Skip to content

Commit

Permalink
amending bundle tool to add inherited schema titles to parent (and as…
Browse files Browse the repository at this point in the history
…cendant) schema discriminator; removing x-cg-discriminator as is not needed anymore (relates to #99)
  • Loading branch information
sebastian-iancu committed Nov 24, 2023
1 parent d2cdafc commit b2ac046
Show file tree
Hide file tree
Showing 28 changed files with 28 additions and 190 deletions.
5 changes: 5 additions & 0 deletions development/src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public function writeJsonFile(): void {
*/
public static function getSchemaRef(string $schemaTitle): string {
$schemaName = ucfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($schemaTitle)))));
$schemaName = match ($schemaName) {
'Entry' => 'AbstractEntry',
'Cluster' => 'Clstr',
default => $schemaName
};
return '#/components/schemas/' . $schemaName;
}

Expand Down
26 changes: 22 additions & 4 deletions development/src/Writer/Codegen.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Codegen extends AbstractWriter {
*/
protected function prepareInput(): void {
echo "prepareInput() ...";
$this->input = str_replace(["x-cg-discriminator"], ["discriminator"], $this->input);
$this->input = preg_replace('#\\/schemas\\/U((?:Dv|Party|Version|Object|Uid|Content|Item|DataValue)[a-zA-Z]*)#', '\\/schemas\\/$1', $this->input);
$this->input = preg_replace('#\\/schemas\\/UM(DvDateTime)#', '\\/schemas\\/$1', $this->input);
}
Expand All @@ -34,6 +33,10 @@ protected function cleaning(Schema $schema): void {
}
}
}
$this->populateDiscriminator($schema->title, $schema);
}

protected function populateDiscriminator(string $mappingKey, Schema $schema): void {
if ($schema->allOf) {
/** @var Schema $parentSchema */
$parentSchema = $schema->allOf[0]->resolve();
Expand All @@ -43,15 +46,30 @@ protected function cleaning(Schema $schema): void {
if (!isset($parentSchema->discriminator)) {
$parentSchema->discriminator = new Discriminator(['propertyName' => '_type']);
}
if (!isset($parentSchema->discriminator->mapping[$schema->title])) {
if (!isset($parentSchema->discriminator->mapping[$mappingKey])) {
$mapping = $parentSchema->discriminator->mapping ?? [];
$mapping[$schema->title] = static::getSchemaRef($schema->title);
echo "(added $schema->title mapping in $parentSchema->title) ";
$mapping[$mappingKey] = static::getSchemaRef($mappingKey);
ksort($mapping);
echo "(added $mappingKey mapping in $parentSchema->title) ";
$parentSchema->discriminator->mapping = $mapping;
}
// add it also to all ancestors, not only to first parent
// this is needed to solve some issues with json-parsers and from() factories in generated code
$this->populateDiscriminator($mappingKey, $parentSchema);
}
}

/**
* AuditDetails
* PartyIdentified
* UpdateAudit
* DvUri
* DvText
* DvInterval
* **ObjectRef
**/


/**
* @return void
*/
Expand Down
3 changes: 0 additions & 3 deletions development/src/Writer/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ protected function cleaning(Schema $schema): void {
if (isset($schema->{'x-cg-allOf'})) {
unset($schema->{'x-cg-allOf'});
}
if (isset($schema->{'x-cg-discriminator'})) {
unset($schema->{'x-cg-discriminator'});
}
}

/**
Expand Down
9 changes: 0 additions & 9 deletions specifications/schemas/base_types/ObjectId.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,3 @@ properties:
type: string
value:
type: string
x-cg-discriminator:
propertyName: _type
mapping:
ARCHETYPE_ID: '#/components/schemas/ArchetypeId'
TEMPLATE_ID: '#/components/schemas/TemplateId'
TERMINOLOGY_ID: '#/components/schemas/TerminologyId'
GENERIC_ID: '#/components/schemas/GenericId'
HIER_OBJECT_ID: '#/components/schemas/HierObjectId'
OBJECT_VERSION_ID: '#/components/schemas/ObjectVersionId'
5 changes: 0 additions & 5 deletions specifications/schemas/base_types/UidBasedId.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ properties:
type: string
default: UID_BASED_ID
x-discriminator-value: UID_BASED_ID
x-cg-discriminator:
propertyName: _type
mapping:
HIER_OBJECT_ID: '#/components/schemas/HierObjectId'
OBJECT_VERSION_ID: '#/components/schemas/ObjectVersionId'
5 changes: 0 additions & 5 deletions specifications/schemas/common/AuditDetails.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ properties:
committer:
$ref: ../common/UPartyProxy.yaml
x-discriminator-value: AUDIT_DETAILS
x-cg-discriminator:
propertyName: _type
mapping:
AUDIT_DETAILS: '#/components/schemas/AuditDetails'
ATTESTATION: '#/components/schemas/Attestation'
example:
system_id: 9624982A-9F42-41A5-9318-AE13D5F5031F
committer:
Expand Down
6 changes: 0 additions & 6 deletions specifications/schemas/common/Locatable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,3 @@ properties:
$ref: ../common/Archetyped.yaml
feeder_audit:
$ref: ../common/FeederAudit.yaml
x-cg-discriminator:
propertyName: _type
mapping:
COMPOSITION: '#/components/schemas/Composition'
EHR_STATUS: '#/components/schemas/EhrStatus'
FOLDER: '#/components/schemas/Folder'
5 changes: 0 additions & 5 deletions specifications/schemas/common/PartyIdentified.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ properties:
items:
$ref: ../data_types/DvIdentifier.yaml
x-discriminator-value: PARTY_IDENTIFIED
x-cg-discriminator:
propertyName: _type
mapping:
PARTY_IDENTIFIED: '#/components/schemas/PartyIdentified'
PARTY_RELATED: '#/components/schemas/PartyRelated'
example:
_type: PARTY_IDENTIFIED
external_ref:
Expand Down
5 changes: 0 additions & 5 deletions specifications/schemas/common/PartyProxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@ properties:
default: PARTY_PROXY
external_ref:
$ref: ../base_types/PartyRef.yaml
x-cg-discriminator:
propertyName: _type
mapping:
PARTY_SELF: '#/components/schemas/PartySelf'
PARTY_IDENTIFIED: '#/components/schemas/PartyIdentified'
2 changes: 0 additions & 2 deletions specifications/schemas/common/Pathable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ type: object
properties:
_type:
type: string
x-cg-discriminator:
propertyName: _type
5 changes: 0 additions & 5 deletions specifications/schemas/common/UpdateAudit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ properties:
committer:
$ref: ../common/UPartyProxy.yaml
x-discriminator-value: UPDATE_AUDIT
x-cg-discriminator:
propertyName: _type
mapping:
UPDATE_AUDIT: '#/components/schemas/UpdateAudit'
UPDATE_ATTESTATION: '#/components/schemas/UpdateAttestation'
example:
change_type:
value: creation
Expand Down
5 changes: 0 additions & 5 deletions specifications/schemas/common/Version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ properties:
$ref: ../common/AuditDetails.yaml
data:
$ref: ../common/UVersionable.yaml
x-cg-discriminator:
propertyName: _type
mapping:
ORIGINAL_VERSION: '#/components/schemas/OriginalVersion'
IMPORTED_VERSION: '#/components/schemas/ImportedVersion'
5 changes: 0 additions & 5 deletions specifications/schemas/common/Versionable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ description: A Versionable resource
type: object
allOf:
- $ref: ../common/Locatable.yaml
x-cg-discriminator:
propertyName: _type
mapping:
COMPOSITION: '#/components/schemas/Composition'
EHR_STATUS: '#/components/schemas/EhrStatus'
5 changes: 0 additions & 5 deletions specifications/schemas/common/VersionedObject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@ properties:
$ref: ../base_types/ObjectRef.yaml
time_created:
$ref: ../data_types/DvDateTime.yaml
x-cg-discriminator:
propertyName: _type
mapping:
VERSIONED_COMPOSITION: '#/components/schemas/VersionedComposition'
VERSIONED_EHR_STATUS: '#/components/schemas/VersionedEhrStatus'
6 changes: 1 addition & 5 deletions specifications/schemas/data_structures/Item.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@ properties:
_type:
type: string
x-discriminator-value: ITEM
x-cg-discriminator:
propertyName: _type
mapping:
ELEMENT: '#/components/schemas/Element'
CLUSTER: '#/components/schemas/Clstr'

7 changes: 0 additions & 7 deletions specifications/schemas/data_structures/ItemStructure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,3 @@ properties:
_type:
type: string
x-discriminator-value: ITEM_STRUCTURE
x-cg-discriminator:
propertyName: _type
mapping:
ITEM_SINGLE: '#/components/schemas/ItemSingle'
ITEM_LIST: '#/components/schemas/ItemList'
ITEM_TABLE: '#/components/schemas/ItemTable'
ITEM_TREE: '#/components/schemas/ItemTree'
28 changes: 0 additions & 28 deletions specifications/schemas/data_types/DataValue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,3 @@ type: object
properties:
_type:
type: string
x-cg-discriminator:
propertyName: _type
mapping:
DV_AMOUNT: '#/components/schemas/DvAmount'
DV_BOOLEAN: '#/components/schemas/DvBoolean'
DV_CODED_TEXT: '#/components/schemas/DvCodedText'
DV_COUNT: '#/components/schemas/DvCount'
DV_DATE: '#/components/schemas/DvDate'
DV_DATE_TIME: '#/components/schemas/DvDateTime'
DV_DURATION: '#/components/schemas/DvDuration'
DV_EHR_URI: '#/components/schemas/DvEhrUri'
DV_ENCAPSULATED: '#/components/schemas/DvEncapsulated'
DV_IDENTIFIER: '#/components/schemas/DvIdentifier'
DV_INTERVAL: '#/components/schemas/DvInterval'
DV_INTERVAL_of_DATE_TIME: '#/components/schemas/DvIntervalOfDateTime'
DV_MULTIMEDIA: '#/components/schemas/DvMultimedia'
DV_ORDERED: '#/components/schemas/DvOrdered'
DV_ORDINAL: '#/components/schemas/DvOrdinal'
DV_PARSABLE: '#/components/schemas/DvParsable'
DV_PROPORTION: '#/components/schemas/DvProportion'
DV_QUANTIFIED: '#/components/schemas/DvQuantified'
DV_QUANTITY: '#/components/schemas/DvQuantity'
DV_SCALE: '#/components/schemas/DvScale'
DV_STATE: '#/components/schemas/DvState'
DV_TEMPORAL: '#/components/schemas/DvTemporal'
DV_TEXT: '#/components/schemas/DvText'
DV_TIME: '#/components/schemas/DvTime'
DV_URI: '#/components/schemas/DvUri'
7 changes: 0 additions & 7 deletions specifications/schemas/data_types/DvAmount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,3 @@ properties:
accuracy:
type: number
x-discriminator-value: DV_AMOUNT
x-cg-discriminator:
propertyName: _type
mapping:
DV_COUNT: '#/components/schemas/DvCount'
DV_DURATION: '#/components/schemas/DvDuration'
DV_PROPORTION: '#/components/schemas/DvProportion'
DV_QUANTITY: '#/components/schemas/DvQuantity'
5 changes: 0 additions & 5 deletions specifications/schemas/data_types/DvEncapsulated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@ properties:
$ref: ../data_types/CodePhrase.yaml
language:
$ref: ../data_types/CodePhrase.yaml
x-cg-discriminator:
propertyName: _type
mapping:
DV_MULTIMEDIA: '#/components/schemas/DvMultimedia'
DV_PARSABLE: '#/components/schemas/DvParsable'
5 changes: 0 additions & 5 deletions specifications/schemas/data_types/DvInterval.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,3 @@ properties:
upper_included:
type: boolean
x-discriminator-value: DV_INTERVAL
x-cg-discriminator:
propertyName: _type
mapping:
DV_INTERVAL: '#/components/schemas/DvInterval'
DV_INTERVAL_of_DATE_TIME: '#/components/schemas/DvIntervalOfDateTime'
15 changes: 0 additions & 15 deletions specifications/schemas/data_types/DvOrdered.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,3 @@ properties:
items:
$ref: ../data_types/ReferenceRange.yaml
x-discriminator-value: DV_ORDERED
x-cg-discriminator:
propertyName: _type
mapping:
DV_AMOUNT: '#/components/schemas/DvAmount'
DV_COUNT: '#/components/schemas/DvCount'
DV_DATE: '#/components/schemas/DvDate'
DV_DATE_TIME: '#/components/schemas/DvDateTime'
DV_DURATION: '#/components/schemas/DvDuration'
DV_ORDINAL: '#/components/schemas/DvOrdinal'
DV_PROPORTION: '#/components/schemas/DvProportion'
DV_QUANTIFIED: '#/components/schemas/DvQuantified'
DV_QUANTITY: '#/components/schemas/DvQuantity'
DV_SCALE: '#/components/schemas/DvScale'
DV_TEMPORAL: '#/components/schemas/DvTemporal'
DV_TIME: '#/components/schemas/DvTime'
12 changes: 0 additions & 12 deletions specifications/schemas/data_types/DvQuantified.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,3 @@ properties:
type: string
default: '='
x-discriminator-value: DV_QUANTIFIED
x-cg-discriminator:
propertyName: _type
mapping:
DV_AMOUNT: '#/components/schemas/DvAmount'
DV_COUNT: '#/components/schemas/DvCount'
DV_DATE: '#/components/schemas/DvDate'
DV_DATE_TIME: '#/components/schemas/DvDateTime'
DV_DURATION: '#/components/schemas/DvDuration'
DV_PROPORTION: '#/components/schemas/DvProportion'
DV_QUANTITY: '#/components/schemas/DvQuantity'
DV_TEMPORAL: '#/components/schemas/DvTemporal'
DV_TIME: '#/components/schemas/DvTime'
6 changes: 0 additions & 6 deletions specifications/schemas/data_types/DvTemporal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ properties:
accuracy:
$ref: ../data_types/DvDuration.yaml
x-discriminator-value: DV_TEMPORAL
x-cg-discriminator:
propertyName: _type
mapping:
DV_DATE: '#/components/schemas/DvDate'
DV_DATE_TIME: '#/components/schemas/DvDateTime'
DV_TIME: '#/components/schemas/DvTime'
5 changes: 0 additions & 5 deletions specifications/schemas/data_types/DvText.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,3 @@ properties:
encoding:
$ref: ../data_types/CodePhrase.yaml
x-discriminator-value: DV_TEXT
x-cg-discriminator:
propertyName: _type
mapping:
DV_TEXT: '#/components/schemas/DvText'
DV_CODED_TEXT: '#/components/schemas/DvCodedText'
5 changes: 0 additions & 5 deletions specifications/schemas/data_types/DvUri.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,3 @@ properties:
value:
type: string
x-discriminator-value: DV_URI
x-cg-discriminator:
propertyName: _type
mapping:
DV_URI: '#/components/schemas/DvUri'
DV_EHR_URI: '#/components/schemas/DvEhrUri'
9 changes: 0 additions & 9 deletions specifications/schemas/ehr/AbstractEntry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,3 @@ properties:
$ref: ../common/UPartyProxy.yaml
provider:
$ref: ../common/UPartyProxy.yaml
x-cg-discriminator:
propertyName: _type
mapping:
ADMIN_ENTRY: '#/components/schemas/AdminEntry'
CARE_ENTRY: '#/components/schemas/CareEntry'
OBSERVATION: '#/components/schemas/Observation'
EVALUATION: '#/components/schemas/Evaluation'
INSTRUCTION: '#/components/schemas/Instruction'
ACTION: '#/components/schemas/Action'
7 changes: 0 additions & 7 deletions specifications/schemas/ehr/CareEntry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,3 @@ properties:
$ref: ../data_structures/UItemStructure.yaml
guideline_id:
$ref: ../base_types/ObjectRef.yaml
x-cg-discriminator:
propertyName: _type
mapping:
OBSERVATION: '#/components/schemas/Observation'
EVALUATION: '#/components/schemas/Evaluation'
INSTRUCTION: '#/components/schemas/Instruction'
ACTION: '#/components/schemas/Action'
10 changes: 0 additions & 10 deletions specifications/schemas/ehr/ContentItem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,3 @@ title: CONTENT_ITEM
type: object
allOf:
- $ref: ../common/Locatable.yaml
x-cg-discriminator:
propertyName: _type
mapping:
ENTRY: '#/components/schemas/AbstractEntry'
ADMIN_ENTRY: '#/components/schemas/AdminEntry'
CARE_ENTRY: '#/components/schemas/CareEntry'
OBSERVATION: '#/components/schemas/Observation'
EVALUATION: '#/components/schemas/Evaluation'
INSTRUCTION: '#/components/schemas/Instruction'
ACTION: '#/components/schemas/Action'

0 comments on commit b2ac046

Please sign in to comment.