Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions lib/codegen/fromcto/xmlschema/xmlschemavisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,20 @@ class XmlSchemaVisitor {
*/
visitMapDeclaration(mapDeclaration, parameters) {

const key = this.toXsType(mapDeclaration.getKey().getType(), mapDeclaration.getKey(), mapDeclaration);
const value = this.toXsType(mapDeclaration.getValue().getType(), mapDeclaration.getValue(), mapDeclaration);
const key = this.toXsType(mapDeclaration.getKey().getType(), mapDeclaration);
const value = this.toXsType(mapDeclaration.getValue().getType(), mapDeclaration);

// write the element representing the MapDeclaration
parameters.fileWriter.writeLine(0, `<xs:element name="${mapDeclaration.getName()}">` );
parameters.fileWriter.writeLine(0, '<xs:complexType>' );
const { name: namespace } = ModelUtil.parseNamespace(mapDeclaration.getNamespace());

// write the type representing the MapDeclaration, so that fields can refer to it
parameters.fileWriter.writeLine(0, `<xs:complexType name="${mapDeclaration.getName()}">` );
parameters.fileWriter.writeLine(1, '<xs:sequence>');
parameters.fileWriter.writeLine(2, `<xs:element name="entry" type="${mapDeclaration.getName()}EntryType" minOccurs="0" maxOccurs="unbounded"/>`);
parameters.fileWriter.writeLine(2, `<xs:element name="entry" type="${namespace}:${mapDeclaration.getName()}EntryType" minOccurs="0" maxOccurs="unbounded"/>`);
parameters.fileWriter.writeLine(1, '</xs:sequence>');
parameters.fileWriter.writeLine(0, '</xs:complexType>');
parameters.fileWriter.writeLine(0, '</xs:element>');

// declare the element
parameters.fileWriter.writeLine(0, `<xs:element name="${mapDeclaration.getName()}" type="${namespace}:${mapDeclaration.getName()}"/>` );

// write the Entry type reprenting the schema of the MapDeclaration
parameters.fileWriter.writeLine(0, `<xs:complexType name="${mapDeclaration.getName()}EntryType">` );
Expand Down Expand Up @@ -246,11 +249,11 @@ class XmlSchemaVisitor {
if (sizeValidator.getMaxSize() !== null) {
maxOccurs = String(sizeValidator.getMaxSize());
}
const mapName = field.getType();
const mapType = this.toXsType(field.getFullyQualifiedTypeName());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit · hygiene

PR #307 changes the map branch of visitField on the adjacent line (the <xs:element name=...> line that follows the mapType line here), and also edits the same visitField tests in test/codegen/fromcto/xmlschema/xmlschemavisitor.js. Whichever PR merges second will probably need a rebase. It would help to agree an order with #307 and rebase the other one afterwards.

parameters.fileWriter.writeLine(2, `<xs:element name="${this.toXsName(field.getName())}"${this.toOccurs(field, isOptional)}>`);
parameters.fileWriter.writeLine(3, '<xs:complexType>');
parameters.fileWriter.writeLine(4, '<xs:sequence>');
parameters.fileWriter.writeLine(5, `<xs:element name="entry" type="${mapName}EntryType" minOccurs="${minOccurs}" maxOccurs="${maxOccurs}"/>`);
parameters.fileWriter.writeLine(5, `<xs:element name="entry" type="${mapType}EntryType" minOccurs="${minOccurs}" maxOccurs="${maxOccurs}"/>`);
parameters.fileWriter.writeLine(4, '</xs:sequence>');
parameters.fileWriter.writeLine(3, '</xs:complexType>');
parameters.fileWriter.writeLine(2, '</xs:element>');
Expand Down Expand Up @@ -327,12 +330,11 @@ class XmlSchemaVisitor {
* Converts a Concerto type to a XML Schema type. Primitive types are converted
* everything else is passed through unchanged.
* @param {string} type - the fully qualified concerto type name
* @param {Object} mapElement - the mapElement representing either the Key or Value of a MapDeclaration
* @param {MapDeclaration} mapDeclaration - the object representing a MapDeclaration
* @param {MapDeclaration} [mapDeclaration] - the MapDeclaration used to resolve a type that is not fully qualified
* @return {string} the corresponding type in XML Schema
* @private
*/
toXsType(type, mapElement, mapDeclaration) {
toXsType(type, mapDeclaration) {
switch(type) {
case 'DateTime':
return 'xs:dateTime';
Expand All @@ -349,10 +351,9 @@ class XmlSchemaVisitor {
default:
if(!ModelUtil.getNamespace(type)) {
const typeDeclaration = mapDeclaration.getModelFile().getType(type);
if (typeDeclaration?.isClassDeclaration?.() && ['Concept', 'Asset', 'Transaction', 'Participant', 'Event'].includes(type)) {
return `concerto:${mapElement.getType()}`;
} else if (typeDeclaration?.isClassDeclaration?.() ) {
return `${ModelUtil.parseNamespace(mapDeclaration.getModelFile().getNamespace()).name}:${mapElement.getType()}`;
if (typeDeclaration?.isClassDeclaration?.()) {
// the type may be imported, so use the namespace that declares it
return this.toXsType(typeDeclaration.getFullyQualifiedName());
} else if (typeDeclaration?.isScalarDeclaration?.()) {
return this.toXsType(typeDeclaration.getType());
}
Expand Down
49 changes: 21 additions & 28 deletions test/codegen/__snapshots__/codegen.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7283,13 +7283,12 @@ xmlns:concerto="concerto"
</xs:restriction>
</xs:simpleType>
<xs:element name="TShirtSizeType" type="org.acme.hr.base:TShirtSizeType"/>
<xs:element name="EmployeeTShirtSizes">
<xs:complexType>
<xs:complexType name="EmployeeTShirtSizes">
<xs:sequence>
<xs:element name="entry" type="EmployeeTShirtSizesEntryType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entry" type="org.acme.hr.base:EmployeeTShirtSizesEntryType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="EmployeeTShirtSizes" type="org.acme.hr.base:EmployeeTShirtSizes"/>
<xs:complexType name="EmployeeTShirtSizesEntryType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
Expand Down Expand Up @@ -7353,78 +7352,72 @@ xmlns:concerto="concerto"
</xs:complexContent>
</xs:complexType>
<xs:element name="Info" type="org.acme.hr:Info"/>
<xs:element name="CompanyProperties">
<xs:complexType>
<xs:complexType name="CompanyProperties">
<xs:sequence>
<xs:element name="entry" type="CompanyPropertiesEntryType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entry" type="org.acme.hr:CompanyPropertiesEntryType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CompanyProperties" type="org.acme.hr:CompanyProperties"/>
<xs:complexType name="CompanyPropertiesEntryType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="EmployeeLoginTimes">
<xs:complexType>
<xs:complexType name="EmployeeLoginTimes">
<xs:sequence>
<xs:element name="entry" type="EmployeeLoginTimesEntryType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entry" type="org.acme.hr:EmployeeLoginTimesEntryType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="EmployeeLoginTimes" type="org.acme.hr:EmployeeLoginTimes"/>
<xs:complexType name="EmployeeLoginTimesEntryType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="value" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
<xs:element name="EmployeeSocialSecurityNumbers">
<xs:complexType>
<xs:complexType name="EmployeeSocialSecurityNumbers">
<xs:sequence>
<xs:element name="entry" type="EmployeeSocialSecurityNumbersEntryType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entry" type="org.acme.hr:EmployeeSocialSecurityNumbersEntryType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="EmployeeSocialSecurityNumbers" type="org.acme.hr:EmployeeSocialSecurityNumbers"/>
<xs:complexType name="EmployeeSocialSecurityNumbersEntryType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="NextOfKin">
<xs:complexType>
<xs:complexType name="NextOfKin">
<xs:sequence>
<xs:element name="entry" type="NextOfKinEntryType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entry" type="org.acme.hr:NextOfKinEntryType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NextOfKin" type="org.acme.hr:NextOfKin"/>
<xs:complexType name="NextOfKinEntryType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="EmployeeProfiles">
<xs:complexType>
<xs:complexType name="EmployeeProfiles">
<xs:sequence>
<xs:element name="entry" type="EmployeeProfilesEntryType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entry" type="org.acme.hr:EmployeeProfilesEntryType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="EmployeeProfiles" type="org.acme.hr:EmployeeProfiles"/>
<xs:complexType name="EmployeeProfilesEntryType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="value" type="concerto:Concept"/>
</xs:sequence>
</xs:complexType>
<xs:element name="EmployeeDirectory">
<xs:complexType>
<xs:complexType name="EmployeeDirectory">
<xs:sequence>
<xs:element name="entry" type="EmployeeDirectoryEntryType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="entry" type="org.acme.hr:EmployeeDirectoryEntryType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="EmployeeDirectory" type="org.acme.hr:EmployeeDirectory"/>
<xs:complexType name="EmployeeDirectoryEntryType">
<xs:sequence>
<xs:element name="key" type="xs:string"/>
Expand Down
Loading
Loading