From 6de249b9c7ab09c00b9d91f9d2a1f0642d742d43 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Wed, 11 Oct 2023 16:05:40 +0100 Subject: [PATCH 01/12] feat(map): add map codegen to golangvisitor Signed-off-by: Jonathan Casey --- lib/codegen/fromcto/golang/golangvisitor.js | 16 ++++++++++++++++ .../codegen/fromcto/golang/golangvisitor.d.ts | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/lib/codegen/fromcto/golang/golangvisitor.js b/lib/codegen/fromcto/golang/golangvisitor.js index ac06e23a..cbbe9a22 100644 --- a/lib/codegen/fromcto/golang/golangvisitor.js +++ b/lib/codegen/fromcto/golang/golangvisitor.js @@ -169,6 +169,12 @@ class GoLangVisitor { array = '[]'; } + if(this.isMap(field)) { + const decl = field.getModelFile().getAllDeclarations().find(d => d.name === field.ast.type.name); + parameters.fileWriter.writeLine(1, `${field.getName()} := make(map[${this.toGoType(decl.getKey().getType())}]${this.toGoType(decl.getValue().getType())})`); + return null; + } + // we export all fields by capitalizing them // we strip $ as it is not legal in Go const name = field.getName().startsWith('$') ? field.getName().substring(1) : field.getName(); @@ -283,6 +289,16 @@ class GoLangVisitor { toGoPackageName(namespace) { return namespace.replace(/@/g, '_').replace(/\./g, '_'); } + + /** + * Check if field is a Map Declaration + * @param {Field} field - the field being visited + * @return {boolean} true if field is a Map Declaration + * @private + */ + isMap(field) { + return (Object.keys(field).length > 0 && ModelUtil.isMap?.(field)); + } } module.exports = GoLangVisitor; diff --git a/types/lib/codegen/fromcto/golang/golangvisitor.d.ts b/types/lib/codegen/fromcto/golang/golangvisitor.d.ts index f8588223..5f350707 100644 --- a/types/lib/codegen/fromcto/golang/golangvisitor.d.ts +++ b/types/lib/codegen/fromcto/golang/golangvisitor.d.ts @@ -99,4 +99,11 @@ declare class GoLangVisitor { * @private */ private toGoPackageName; + /** + * Check if field is a Map Declaration + * @param {Field} field - the field being visited + * @return {boolean} true if field is a Map Declaration + * @private + */ + private isMap; } From 53c85f9de3463c12947e758ac4acd8e118162d36 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Wed, 11 Oct 2023 16:06:07 +0100 Subject: [PATCH 02/12] feat(map): add test coverage Signed-off-by: Jonathan Casey --- test/codegen/fromcto/golang/golangvisitor.js | 47 ++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/codegen/fromcto/golang/golangvisitor.js b/test/codegen/fromcto/golang/golangvisitor.js index 43e7a70b..74210ef9 100644 --- a/test/codegen/fromcto/golang/golangvisitor.js +++ b/test/codegen/fromcto/golang/golangvisitor.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-vars */ /* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +25,14 @@ const GoLangVisitor = require('../../../../lib/codegen/fromcto/golang/golangvisi const AssetDeclaration = require('@accordproject/concerto-core').AssetDeclaration; const ClassDeclaration = require('@accordproject/concerto-core').ClassDeclaration; const EnumDeclaration = require('@accordproject/concerto-core').EnumDeclaration; +const MapDeclaration = require('@accordproject/concerto-core').MapDeclaration; +const ModelUtil = require('@accordproject/concerto-core').ModelUtil; const EnumValueDeclaration = require('@accordproject/concerto-core').EnumValueDeclaration; const Field = require('@accordproject/concerto-core').Field; const ModelFile = require('@accordproject/concerto-core').ModelFile; const ModelManager = require('@accordproject/concerto-core').ModelManager; const FileWriter = require('@accordproject/concerto-util').FileWriter; +let sandbox = sinon.createSandbox(); describe('GoLangVisitor', function () { let goVisit; @@ -43,6 +47,10 @@ describe('GoLangVisitor', function () { mockFileWriter = sinon.createStubInstance(FileWriter); }); + afterEach(function() { + sandbox.restore(); + }); + describe('visit', () => { let param; beforeEach(() => { @@ -334,6 +342,45 @@ describe('GoLangVisitor', function () { param.fileWriter.writeLine.withArgs(1, 'Bob []string `json:"bob"`').calledOnce.should.be.ok; }); + + it('should write a line defining a map field ', () => { + let param = { + fileWriter: mockFileWriter, + }; + + sandbox.stub(ModelUtil, 'isMap').callsFake(() => { + return true; + }); + + const mockField = sinon.createStubInstance(Field); + const getAllDeclarations = sinon.stub(); + + mockField.dummy = 'Dummy Value'; + mockField.getModelFile.returns({ getAllDeclarations: getAllDeclarations }); + + const mockMapDeclaration = sinon.createStubInstance(MapDeclaration); + const findStub = sinon.stub(); + const getKeyType = sinon.stub(); + const getValueType = sinon.stub(); + + mockField.getName.returns('Bob'); + mockField.getType.returns('SpecialType'); + + getAllDeclarations.returns({ find: findStub }); + findStub.returns(mockMapDeclaration); + getKeyType.returns('String'); + getValueType.returns('String'); + mockField.getName.returns('dictionary'); + mockMapDeclaration.getName.returns('dictionary'); + mockMapDeclaration.isMapDeclaration.returns(true); + mockMapDeclaration.getKey.returns({ getType: getKeyType }); + mockMapDeclaration.getValue.returns({ getType: getValueType }); + + goVisit.visitField(mockField,param); + + param.fileWriter.writeLine.withArgs(1, 'dictionary := make(map[string]string)').calledOnce.should.be.ok; + }); + }); describe('visitEnumValueDeclaration', () => { From 1eeda24d84e43a88aeab63af04ba6ec369bfa004 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Wed, 11 Oct 2023 16:06:18 +0100 Subject: [PATCH 03/12] feat(map): add snapshot Signed-off-by: Jonathan Casey --- analysis.adoc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 analysis.adoc diff --git a/analysis.adoc b/analysis.adoc new file mode 100644 index 00000000..16dc9aea --- /dev/null +++ b/analysis.adoc @@ -0,0 +1,39 @@ +Targets to Support + +- Avro + - In Apache Avro, the key type for a map is always a string. + - The values can be of any Avro data type, such as strings, integers, doubles, records, or even nested maps. + +- sample: + { + "type": "map", + "values": "string" + } +- GoLang + - time.Time for date + - string for string + + + +- GraphQL +- JsonSchema +- Markdown +- Mermaid +- OData +- OpenApi +- PlantUML +- ProtoBuf + +- Vocabulary +- XMLScehma + + +=== +- Loopback // drop support for loopback in 4.0 +- Java + :: HashMap. +- C# +- Typescript +- Rust + :: let mut book_reviews:HashMap = HashMap::new(); + From a3f99e15cdf646845d8462eb7659592cf381ba83 Mon Sep 17 00:00:00 2001 From: Jonathan-Casey <109082377+Jonathan-Casey@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:10:49 +0100 Subject: [PATCH 04/12] Delete analysis.adoc Signed-off-by: Jonathan-Casey <109082377+Jonathan-Casey@users.noreply.github.com> --- analysis.adoc | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 analysis.adoc diff --git a/analysis.adoc b/analysis.adoc deleted file mode 100644 index 16dc9aea..00000000 --- a/analysis.adoc +++ /dev/null @@ -1,39 +0,0 @@ -Targets to Support - -- Avro - - In Apache Avro, the key type for a map is always a string. - - The values can be of any Avro data type, such as strings, integers, doubles, records, or even nested maps. - -- sample: - { - "type": "map", - "values": "string" - } -- GoLang - - time.Time for date - - string for string - - - -- GraphQL -- JsonSchema -- Markdown -- Mermaid -- OData -- OpenApi -- PlantUML -- ProtoBuf - -- Vocabulary -- XMLScehma - - -=== -- Loopback // drop support for loopback in 4.0 -- Java - :: HashMap. -- C# -- Typescript -- Rust - :: let mut book_reviews:HashMap = HashMap::new(); - From 76eec126e7ce76c65e66a09833db7650fb3aa563 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Wed, 11 Oct 2023 16:12:06 +0100 Subject: [PATCH 05/12] feat(map): add actual snapshot Signed-off-by: Jonathan Casey --- test/codegen/__snapshots__/codegen.js.snap | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/codegen/__snapshots__/codegen.js.snap b/test/codegen/__snapshots__/codegen.js.snap index b031ca12..ae0407be 100644 --- a/test/codegen/__snapshots__/codegen.js.snap +++ b/test/codegen/__snapshots__/codegen.js.snap @@ -524,12 +524,12 @@ type Address struct { State State \`json:"state"\` ZipCode string \`json:"zipCode"\` Country string \`json:"country"\` - Dictionary1 Map1 \`json:"dictionary1"\` - Dictionary2 Map2 \`json:"dictionary2"\` - Dictionary3 Map3 \`json:"dictionary3"\` - Dictionary4 Map4 \`json:"dictionary4"\` - Dictionary5 Map5 \`json:"dictionary5"\` - Dictionary6 Map6 \`json:"dictionary6"\` + dictionary1 := make(map[string]string) + dictionary2 := make(map[string]time.Time) + dictionary3 := make(map[string]SSN) + dictionary4 := make(map[string]Concept) + dictionary5 := make(map[SSN]string) + dictionary6 := make(map[SSN]Employee) } type Company struct { concerto_1_0_0.Concept @@ -5650,12 +5650,12 @@ type Address struct { State State \`json:"state"\` ZipCode string \`json:"zipCode"\` Country string \`json:"country"\` - Dictionary1 Map1 \`json:"dictionary1"\` - Dictionary2 Map2 \`json:"dictionary2"\` - Dictionary3 Map3 \`json:"dictionary3"\` - Dictionary4 Map4 \`json:"dictionary4"\` - Dictionary5 Map5 \`json:"dictionary5"\` - Dictionary6 Map6 \`json:"dictionary6"\` + dictionary1 := make(map[string]string) + dictionary2 := make(map[string]time.Time) + dictionary3 := make(map[string]SSN) + dictionary4 := make(map[string]Concept) + dictionary5 := make(map[SSN]string) + dictionary6 := make(map[SSN]Employee) } type Company struct { concerto_1_0_0.Concept From d68fd4bae5b0924bd8549fa26434a699fdc360b9 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Sat, 21 Oct 2023 22:50:28 +0100 Subject: [PATCH 06/12] feat(map): gets type from ModelFile Signed-off-by: Jonathan Casey --- lib/codegen/fromcto/golang/golangvisitor.js | 2 +- test/codegen/fromcto/golang/golangvisitor.js | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/codegen/fromcto/golang/golangvisitor.js b/lib/codegen/fromcto/golang/golangvisitor.js index cbbe9a22..a7c9d72b 100644 --- a/lib/codegen/fromcto/golang/golangvisitor.js +++ b/lib/codegen/fromcto/golang/golangvisitor.js @@ -170,7 +170,7 @@ class GoLangVisitor { } if(this.isMap(field)) { - const decl = field.getModelFile().getAllDeclarations().find(d => d.name === field.ast.type.name); + const decl = field.getModelFile().getType(field.getType()); parameters.fileWriter.writeLine(1, `${field.getName()} := make(map[${this.toGoType(decl.getKey().getType())}]${this.toGoType(decl.getValue().getType())})`); return null; } diff --git a/test/codegen/fromcto/golang/golangvisitor.js b/test/codegen/fromcto/golang/golangvisitor.js index 74210ef9..1a2f2488 100644 --- a/test/codegen/fromcto/golang/golangvisitor.js +++ b/test/codegen/fromcto/golang/golangvisitor.js @@ -353,21 +353,18 @@ describe('GoLangVisitor', function () { }); const mockField = sinon.createStubInstance(Field); - const getAllDeclarations = sinon.stub(); + const getType = sinon.stub(); mockField.dummy = 'Dummy Value'; - mockField.getModelFile.returns({ getAllDeclarations: getAllDeclarations }); + mockField.getModelFile.returns({ getType: getType }); const mockMapDeclaration = sinon.createStubInstance(MapDeclaration); - const findStub = sinon.stub(); const getKeyType = sinon.stub(); const getValueType = sinon.stub(); - mockField.getName.returns('Bob'); - mockField.getType.returns('SpecialType'); + mockField.getType.returns('Map1'); - getAllDeclarations.returns({ find: findStub }); - findStub.returns(mockMapDeclaration); + getType.returns(mockMapDeclaration); getKeyType.returns('String'); getValueType.returns('String'); mockField.getName.returns('dictionary'); From 92f32bda74c0bd28536ade3bed21afcb06c8c644 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Tue, 7 Nov 2023 16:20:42 +0000 Subject: [PATCH 07/12] feat(*): use util fun Signed-off-by: Jonathan Casey --- lib/codegen/fromcto/golang/golangvisitor.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/codegen/fromcto/golang/golangvisitor.js b/lib/codegen/fromcto/golang/golangvisitor.js index a7c9d72b..99defab7 100644 --- a/lib/codegen/fromcto/golang/golangvisitor.js +++ b/lib/codegen/fromcto/golang/golangvisitor.js @@ -169,7 +169,7 @@ class GoLangVisitor { array = '[]'; } - if(this.isMap(field)) { + if(ModelUtil.isMap(field)) { const decl = field.getModelFile().getType(field.getType()); parameters.fileWriter.writeLine(1, `${field.getName()} := make(map[${this.toGoType(decl.getKey().getType())}]${this.toGoType(decl.getValue().getType())})`); return null; @@ -289,16 +289,6 @@ class GoLangVisitor { toGoPackageName(namespace) { return namespace.replace(/@/g, '_').replace(/\./g, '_'); } - - /** - * Check if field is a Map Declaration - * @param {Field} field - the field being visited - * @return {boolean} true if field is a Map Declaration - * @private - */ - isMap(field) { - return (Object.keys(field).length > 0 && ModelUtil.isMap?.(field)); - } } module.exports = GoLangVisitor; From f71bcbd5b922da3634688b3f7468c8cefe9d1257 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Tue, 7 Nov 2023 16:21:03 +0000 Subject: [PATCH 08/12] test(map): fix test regressions Signed-off-by: Jonathan Casey --- test/codegen/fromcto/golang/golangvisitor.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/codegen/fromcto/golang/golangvisitor.js b/test/codegen/fromcto/golang/golangvisitor.js index 1a2f2488..72f3da30 100644 --- a/test/codegen/fromcto/golang/golangvisitor.js +++ b/test/codegen/fromcto/golang/golangvisitor.js @@ -315,6 +315,11 @@ describe('GoLangVisitor', function () { param = { fileWriter: mockFileWriter }; + + sandbox.stub(ModelUtil, 'isMap').callsFake(() => { + return false; + }); + }); it('should write a line defining a field', () => { @@ -348,6 +353,7 @@ describe('GoLangVisitor', function () { fileWriter: mockFileWriter, }; + sandbox.restore(); sandbox.stub(ModelUtil, 'isMap').callsFake(() => { return true; }); From 639ea6747bd095fc82a83b2cb98f0267be9231bc Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Tue, 7 Nov 2023 16:48:59 +0000 Subject: [PATCH 09/12] test(*): snapshot update Signed-off-by: Jonathan Casey --- test/codegen/__snapshots__/codegen.js.snap | 510 ++++++++++----------- 1 file changed, 252 insertions(+), 258 deletions(-) diff --git a/test/codegen/__snapshots__/codegen.js.snap b/test/codegen/__snapshots__/codegen.js.snap index f298c431..26d45a87 100644 --- a/test/codegen/__snapshots__/codegen.js.snap +++ b/test/codegen/__snapshots__/codegen.js.snap @@ -6,7 +6,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "value": "@namespace("concerto@1.0.0") protocol MyProtocol { - + record Concept { } @@ -39,7 +39,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "value": "@namespace("concerto") protocol MyProtocol { - + record Concept { } @@ -69,7 +69,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers protocol MyProtocol { import idl "concerto@1.0.0.avdl"; - + enum State { MA, NY, @@ -106,7 +106,7 @@ protocol MyProtocol { import idl "org.acme.hr.base.avdl"; import idl "concerto@1.0.0.avdl"; - + record Company { string name; Address headquarters; @@ -494,7 +494,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "value": "// Package concerto_1_0_0 contains domain objects and was generated from Concerto namespace concerto@1.0.0. package concerto_1_0_0 import "time" - + type Concept struct { } type Asset struct { @@ -522,7 +522,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "key": "concerto.go", "value": "// Package concerto contains domain objects and was generated from Concerto namespace concerto. package concerto - + type Concept struct { } type Asset struct { @@ -549,7 +549,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "value": "// Package org_acme_hr_base contains domain objects and was generated from Concerto namespace org.acme.hr.base. package org_acme_hr_base import "concerto_1_0_0"; - + type State int const ( MA State = 1 + iota @@ -572,12 +572,6 @@ type Address struct { State State \`json:"state"\` ZipCode string \`json:"zipCode"\` Country string \`json:"country"\` - dictionary1 := make(map[string]string) - dictionary2 := make(map[string]time.Time) - dictionary3 := make(map[string]SSN) - dictionary4 := make(map[string]Concept) - dictionary5 := make(map[SSN]string) - dictionary6 := make(map[SSN]Employee) } ", } @@ -591,16 +585,16 @@ package org_acme_hr import "time" import "org_acme_hr_base"; import "concerto_1_0_0"; - + type Company struct { concerto_1_0_0.Concept Name string \`json:"name"\` Headquarters Address \`json:"headquarters"\` - CompanyProperties CompanyProperties \`json:"companyProperties"\` - EmployeeDirectory EmployeeDirectory \`json:"employeeDirectory"\` - EmployeeTShirtSizes EmployeeTShirtSizes \`json:"employeeTShirtSizes"\` - EmployeeProfiles EmployeeProfiles \`json:"employeeProfiles"\` - EmployeeSocialSecurityNumbers EmployeeSocialSecurityNumbers \`json:"employeeSocialSecurityNumbers"\` + companyProperties := make(map[string]string) + employeeDirectory := make(map[SSN]Employee) + employeeTShirtSizes := make(map[SSN]TShirtSizeType) + employeeProfiles := make(map[string]Concept) + employeeSocialSecurityNumbers := make(map[string]SSN) } type Department int const ( @@ -634,7 +628,7 @@ type Person struct { Ssn string \`json:"ssn"\` Height float64 \`json:"height"\` Dob time.Time \`json:"dob"\` - NextOfKin NextOfKin \`json:"nextOfKin"\` + nextOfKin := make(map[KinName]KinTelephone) } type Employee struct { Person @@ -876,7 +870,7 @@ public abstract class Asset extends Concept { public void set$id(String i) { $id = i; } - + // the accessor for the identifying field public String getID() { return this.get$identifier(); @@ -915,7 +909,7 @@ public abstract class Participant extends Concept { public void set$id(String i) { $id = i; } - + // the accessor for the identifying field public String getID() { return this.get$identifier(); @@ -1172,7 +1166,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "serialNumber") public abstract class Equipment extends Asset { - + // the accessor for the identifying field public String getID() { return this.getSerialNumber(); @@ -1227,7 +1221,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "serialNumber") public class Laptop extends Equipment { - + // the accessor for the identifying field public String getID() { return this.getSerialNumber(); @@ -1268,7 +1262,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "email") public abstract class Person extends Participant { - + // the accessor for the identifying field public String getID() { return this.getEmail(); @@ -1363,7 +1357,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "email") public class Employee extends Person { - + // the accessor for the identifying field public String getID() { return this.getEmail(); @@ -1451,7 +1445,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "email") public class Contractor extends Person { - + // the accessor for the identifying field public String getID() { return this.getEmail(); @@ -1497,7 +1491,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "email") public class Manager extends Employee { - + // the accessor for the identifying field public String getID() { return this.getEmail(); @@ -3836,7 +3830,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "key": "utils.rs", "value": "use chrono::{ DateTime, TimeZone, Utc }; use serde::{ Deserialize, Serialize, Deserializer, Serializer }; - + pub fn serialize_datetime_option(datetime: &Option>, serializer: S) -> Result where S: Serializer, @@ -3866,7 +3860,7 @@ where let datetime_str = String::deserialize(deserializer)?; Utc.datetime_from_str(&datetime_str, "%Y-%m-%dT%H:%M:%S%.3f%Z").map_err(serde::de::Error::custom) } - + pub fn serialize_datetime(datetime: &chrono::DateTime, serializer: S) -> Result where S: Serializer, @@ -3883,9 +3877,9 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "key": "concerto_1_0_0.rs", "value": "use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, TimeZone, Utc }; - + use crate::utils::*; - + #[derive(Debug, Serialize, Deserialize)] pub struct Concept { #[serde( @@ -3900,7 +3894,7 @@ pub struct Asset { rename = "$class", )] pub _class: String, - + #[serde( rename = "$identifier", )] @@ -3913,7 +3907,7 @@ pub struct Participant { rename = "$class", )] pub _class: String, - + #[serde( rename = "$identifier", )] @@ -3926,7 +3920,7 @@ pub struct Transaction { rename = "$class", )] pub _class: String, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -3941,7 +3935,7 @@ pub struct Event { rename = "$class", )] pub _class: String, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -3959,9 +3953,9 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "key": "concerto.rs", "value": "use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, TimeZone, Utc }; - + use crate::utils::*; - + #[derive(Debug, Serialize, Deserialize)] pub struct Concept { #[serde( @@ -3976,7 +3970,7 @@ pub struct Asset { rename = "$class", )] pub _class: String, - + #[serde( rename = "$identifier", )] @@ -3989,7 +3983,7 @@ pub struct Participant { rename = "$class", )] pub _class: String, - + #[serde( rename = "$identifier", )] @@ -4021,10 +4015,10 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "key": "org_acme_hr_base.rs", "value": "use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, TimeZone, Utc }; - + use crate::concerto_1_0_0::*; use crate::utils::*; - + #[derive(Debug, Serialize, Deserialize)] pub enum State { #[allow(non_camel_case_types)] @@ -4057,28 +4051,28 @@ pub struct Address { rename = "$class", )] pub _class: String, - + #[serde( rename = "street", )] pub street: String, - + #[serde( rename = "city", )] pub city: String, - + #[serde( rename = "state", skip_serializing_if = "Option::is_none", )] pub state: Option, - + #[serde( rename = "zipCode", )] pub zip_code: String, - + #[serde( rename = "country", )] @@ -4094,52 +4088,52 @@ exports[`codegen #formats check we can convert all formats from namespace unvers "key": "org_acme_hr.rs", "value": "use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, TimeZone, Utc }; - + use crate::org_acme_hr_base::*; use crate::concerto_1_0_0::*; use crate::utils::*; - + #[derive(Debug, Serialize, Deserialize)] pub struct Company { #[serde( rename = "$class", )] pub _class: String, - + #[serde( rename = "name", )] pub name: String, - + #[serde( rename = "headquarters", )] pub headquarters: Address, - + #[serde( rename = "companyProperties", skip_serializing_if = "Option::is_none", )] pub company_properties: Option, - + #[serde( rename = "employeeDirectory", skip_serializing_if = "Option::is_none", )] pub employee_directory: Option, - + #[serde( rename = "employeeTShirtSizes", skip_serializing_if = "Option::is_none", )] pub employee_t_shirt_sizes: Option, - + #[serde( rename = "employeeProfiles", skip_serializing_if = "Option::is_none", )] pub employee_profiles: Option, - + #[serde( rename = "employeeSocialSecurityNumbers", skip_serializing_if = "Option::is_none", @@ -4169,12 +4163,12 @@ pub struct Equipment { rename = "$class", )] pub _class: String, - + #[serde( rename = "serialNumber", )] pub serial_number: String, - + #[serde( rename = "$identifier", )] @@ -4195,17 +4189,17 @@ pub struct Laptop { rename = "$class", )] pub _class: String, - + #[serde( rename = "make", )] pub make: LaptopMake, - + #[serde( rename = "serialNumber", )] pub serial_number: String, - + #[serde( rename = "$identifier", )] @@ -4218,55 +4212,55 @@ pub struct Person { rename = "$class", )] pub _class: String, - + #[serde( rename = "email", )] pub email: String, - + #[serde( rename = "firstName", )] pub first_name: String, - + #[serde( rename = "lastName", )] pub last_name: String, - + #[serde( rename = "middleNames", skip_serializing_if = "Option::is_none", )] pub middle_names: Option, - + #[serde( rename = "homeAddress", )] pub home_address: Address, - + #[serde( rename = "ssn", )] pub ssn: String, - + #[serde( rename = "height", )] pub height: f64, - + #[serde( rename = "dob", serialize_with = "serialize_datetime", deserialize_with = "deserialize_datetime", )] pub dob: DateTime, - + #[serde( rename = "nextOfKin", )] pub next_of_kin: NextOfKin, - + #[serde( rename = "$identifier", )] @@ -4279,93 +4273,93 @@ pub struct Employee { rename = "$class", )] pub _class: String, - + #[serde( rename = "employeeId", )] pub employee_id: String, - + #[serde( rename = "salary", )] pub salary: u64, - + #[serde( rename = "numDependents", )] pub num_dependents: Integer, - + #[serde( rename = "retired", )] pub retired: bool, - + #[serde( rename = "department", )] pub department: Department, - + #[serde( rename = "officeAddress", )] pub office_address: Address, - + #[serde( rename = "companyAssets", )] pub company_assets: Vec, - + #[serde(rename = "manager")] pub manager: Option, - + #[serde( rename = "email", )] pub email: String, - + #[serde( rename = "firstName", )] pub first_name: String, - + #[serde( rename = "lastName", )] pub last_name: String, - + #[serde( rename = "middleNames", skip_serializing_if = "Option::is_none", )] pub middle_names: Option, - + #[serde( rename = "homeAddress", )] pub home_address: Address, - + #[serde( rename = "ssn", )] pub ssn: String, - + #[serde( rename = "height", )] pub height: f64, - + #[serde( rename = "dob", serialize_with = "serialize_datetime", deserialize_with = "deserialize_datetime", )] pub dob: DateTime, - + #[serde( rename = "nextOfKin", )] pub next_of_kin: NextOfKin, - + #[serde( rename = "$identifier", )] @@ -4378,63 +4372,63 @@ pub struct Contractor { rename = "$class", )] pub _class: String, - + #[serde( rename = "company", )] pub company: Company, - + #[serde(rename = "manager")] pub manager: Option, - + #[serde( rename = "email", )] pub email: String, - + #[serde( rename = "firstName", )] pub first_name: String, - + #[serde( rename = "lastName", )] pub last_name: String, - + #[serde( rename = "middleNames", skip_serializing_if = "Option::is_none", )] pub middle_names: Option, - + #[serde( rename = "homeAddress", )] pub home_address: Address, - + #[serde( rename = "ssn", )] pub ssn: String, - + #[serde( rename = "height", )] pub height: f64, - + #[serde( rename = "dob", serialize_with = "serialize_datetime", deserialize_with = "deserialize_datetime", )] pub dob: DateTime, - + #[serde( rename = "nextOfKin", )] pub next_of_kin: NextOfKin, - + #[serde( rename = "$identifier", )] @@ -4447,96 +4441,96 @@ pub struct Manager { rename = "$class", )] pub _class: String, - + #[serde(rename = "reports")] pub reports: Option>, - + #[serde( rename = "employeeId", )] pub employee_id: String, - + #[serde( rename = "salary", )] pub salary: u64, - + #[serde( rename = "numDependents", )] pub num_dependents: Integer, - + #[serde( rename = "retired", )] pub retired: bool, - + #[serde( rename = "department", )] pub department: Department, - + #[serde( rename = "officeAddress", )] pub office_address: Address, - + #[serde( rename = "companyAssets", )] pub company_assets: Vec, - + #[serde(rename = "manager")] pub manager: Option, - + #[serde( rename = "email", )] pub email: String, - + #[serde( rename = "firstName", )] pub first_name: String, - + #[serde( rename = "lastName", )] pub last_name: String, - + #[serde( rename = "middleNames", skip_serializing_if = "Option::is_none", )] pub middle_names: Option, - + #[serde( rename = "homeAddress", )] pub home_address: Address, - + #[serde( rename = "ssn", )] pub ssn: String, - + #[serde( rename = "height", )] pub height: f64, - + #[serde( rename = "dob", serialize_with = "serialize_datetime", deserialize_with = "deserialize_datetime", )] pub dob: DateTime, - + #[serde( rename = "nextOfKin", )] pub next_of_kin: NextOfKin, - + #[serde( rename = "$identifier", )] @@ -4549,7 +4543,7 @@ pub struct CompanyEvent { rename = "$class", )] pub _class: String, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -4564,10 +4558,10 @@ pub struct Onboarded { rename = "$class", )] pub _class: String, - + #[serde(rename = "employee")] pub employee: Employee, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -4582,15 +4576,15 @@ pub struct ChangeOfAddress { rename = "$class", )] pub _class: String, - + #[serde(rename = "Person")] pub person: Person, - + #[serde( rename = "newAddress", )] pub new_address: Address, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -4648,7 +4642,7 @@ export interface IConcept { $class: string; } -export type ConceptUnion = IAddress | +export type ConceptUnion = IAddress | ICompany; export interface IAsset extends IConcept { @@ -4826,7 +4820,7 @@ export interface IPerson extends IParticipant { nextOfKin: NextOfKin; } -export type PersonUnion = IEmployee | +export type PersonUnion = IEmployee | IContractor; export interface IEmployee extends IPerson { @@ -4982,7 +4976,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers { "key": "concerto@1.0.0.xsd", "value": " - @@ -5038,7 +5032,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers { "key": "concerto.xsd", "value": " - @@ -5092,7 +5086,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers { "key": "org.acme.hr.base.xsd", "value": " - @@ -5138,7 +5132,7 @@ exports[`codegen #formats check we can convert all formats from namespace unvers { "key": "org.acme.hr.xsd", "value": " - @@ -5564,7 +5558,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio "value": "@namespace("concerto@1.0.0") protocol MyProtocol { - + record Concept { } @@ -5597,7 +5591,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio "value": "@namespace("concerto") protocol MyProtocol { - + record Concept { } @@ -5627,7 +5621,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio protocol MyProtocol { import idl "concerto@1.0.0.avdl"; - + enum State { MA, NY, @@ -5664,7 +5658,7 @@ protocol MyProtocol { import idl "org.acme.hr.base@1.0.0.avdl"; import idl "concerto@1.0.0.avdl"; - + record Company { string name; Address headquarters; @@ -6052,7 +6046,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio "value": "// Package concerto_1_0_0 contains domain objects and was generated from Concerto namespace concerto@1.0.0. package concerto_1_0_0 import "time" - + type Concept struct { } type Asset struct { @@ -6080,7 +6074,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio "key": "concerto.go", "value": "// Package concerto contains domain objects and was generated from Concerto namespace concerto. package concerto - + type Concept struct { } type Asset struct { @@ -6107,7 +6101,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio "value": "// Package org_acme_hr_base_1_0_0 contains domain objects and was generated from Concerto namespace org.acme.hr.base@1.0.0. package org_acme_hr_base_1_0_0 import "concerto_1_0_0"; - + type State int const ( MA State = 1 + iota @@ -6143,16 +6137,16 @@ package org_acme_hr_1_0_0 import "time" import "org_acme_hr_base_1_0_0"; import "concerto_1_0_0"; - + type Company struct { concerto_1_0_0.Concept Name string \`json:"name"\` Headquarters Address \`json:"headquarters"\` - CompanyProperties CompanyProperties \`json:"companyProperties"\` - EmployeeDirectory EmployeeDirectory \`json:"employeeDirectory"\` - EmployeeTShirtSizes EmployeeTShirtSizes \`json:"employeeTShirtSizes"\` - EmployeeProfiles EmployeeProfiles \`json:"employeeProfiles"\` - EmployeeSocialSecurityNumbers EmployeeSocialSecurityNumbers \`json:"employeeSocialSecurityNumbers"\` + companyProperties := make(map[string]string) + employeeDirectory := make(map[SSN]Employee) + employeeTShirtSizes := make(map[SSN]TShirtSizeType) + employeeProfiles := make(map[string]Concept) + employeeSocialSecurityNumbers := make(map[string]SSN) } type Department int const ( @@ -6186,7 +6180,7 @@ type Person struct { Ssn string \`json:"ssn"\` Height float64 \`json:"height"\` Dob time.Time \`json:"dob"\` - NextOfKin NextOfKin \`json:"nextOfKin"\` + nextOfKin := make(map[KinName]KinTelephone) } type Employee struct { Person @@ -6428,7 +6422,7 @@ public abstract class Asset extends Concept { public void set$id(String i) { $id = i; } - + // the accessor for the identifying field public String getID() { return this.get$identifier(); @@ -6467,7 +6461,7 @@ public abstract class Participant extends Concept { public void set$id(String i) { $id = i; } - + // the accessor for the identifying field public String getID() { return this.get$identifier(); @@ -6724,7 +6718,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "serialNumber") public abstract class Equipment extends Asset { - + // the accessor for the identifying field public String getID() { return this.getSerialNumber(); @@ -6779,7 +6773,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "serialNumber") public class Laptop extends Equipment { - + // the accessor for the identifying field public String getID() { return this.getSerialNumber(); @@ -6820,7 +6814,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "email") public abstract class Person extends Participant { - + // the accessor for the identifying field public String getID() { return this.getEmail(); @@ -6915,7 +6909,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "email") public class Employee extends Person { - + // the accessor for the identifying field public String getID() { return this.getEmail(); @@ -7003,7 +6997,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "email") public class Contractor extends Person { - + // the accessor for the identifying field public String getID() { return this.getEmail(); @@ -7049,7 +7043,7 @@ import com.fasterxml.jackson.annotation.*; @JsonIgnoreProperties({"id"}) @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "email") public class Manager extends Employee { - + // the accessor for the identifying field public String getID() { return this.getEmail(); @@ -9420,7 +9414,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio "key": "utils.rs", "value": "use chrono::{ DateTime, TimeZone, Utc }; use serde::{ Deserialize, Serialize, Deserializer, Serializer }; - + pub fn serialize_datetime_option(datetime: &Option>, serializer: S) -> Result where S: Serializer, @@ -9450,7 +9444,7 @@ where let datetime_str = String::deserialize(deserializer)?; Utc.datetime_from_str(&datetime_str, "%Y-%m-%dT%H:%M:%S%.3f%Z").map_err(serde::de::Error::custom) } - + pub fn serialize_datetime(datetime: &chrono::DateTime, serializer: S) -> Result where S: Serializer, @@ -9467,9 +9461,9 @@ exports[`codegen #formats check we can convert all formats from namespace versio "key": "concerto_1_0_0.rs", "value": "use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, TimeZone, Utc }; - + use crate::utils::*; - + #[derive(Debug, Serialize, Deserialize)] pub struct Concept { #[serde( @@ -9484,7 +9478,7 @@ pub struct Asset { rename = "$class", )] pub _class: String, - + #[serde( rename = "$identifier", )] @@ -9497,7 +9491,7 @@ pub struct Participant { rename = "$class", )] pub _class: String, - + #[serde( rename = "$identifier", )] @@ -9510,7 +9504,7 @@ pub struct Transaction { rename = "$class", )] pub _class: String, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -9525,7 +9519,7 @@ pub struct Event { rename = "$class", )] pub _class: String, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -9543,9 +9537,9 @@ exports[`codegen #formats check we can convert all formats from namespace versio "key": "concerto.rs", "value": "use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, TimeZone, Utc }; - + use crate::utils::*; - + #[derive(Debug, Serialize, Deserialize)] pub struct Concept { #[serde( @@ -9560,7 +9554,7 @@ pub struct Asset { rename = "$class", )] pub _class: String, - + #[serde( rename = "$identifier", )] @@ -9573,7 +9567,7 @@ pub struct Participant { rename = "$class", )] pub _class: String, - + #[serde( rename = "$identifier", )] @@ -9605,10 +9599,10 @@ exports[`codegen #formats check we can convert all formats from namespace versio "key": "org_acme_hr_base_1_0_0.rs", "value": "use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, TimeZone, Utc }; - + use crate::concerto_1_0_0::*; use crate::utils::*; - + #[derive(Debug, Serialize, Deserialize)] pub enum State { #[allow(non_camel_case_types)] @@ -9641,28 +9635,28 @@ pub struct Address { rename = "$class", )] pub _class: String, - + #[serde( rename = "street", )] pub street: String, - + #[serde( rename = "city", )] pub city: String, - + #[serde( rename = "state", skip_serializing_if = "Option::is_none", )] pub state: Option, - + #[serde( rename = "zipCode", )] pub zip_code: String, - + #[serde( rename = "country", )] @@ -9678,52 +9672,52 @@ exports[`codegen #formats check we can convert all formats from namespace versio "key": "org_acme_hr_1_0_0.rs", "value": "use serde::{ Deserialize, Serialize }; use chrono::{ DateTime, TimeZone, Utc }; - + use crate::org_acme_hr_base_1_0_0::*; use crate::concerto_1_0_0::*; use crate::utils::*; - + #[derive(Debug, Serialize, Deserialize)] pub struct Company { #[serde( rename = "$class", )] pub _class: String, - + #[serde( rename = "name", )] pub name: String, - + #[serde( rename = "headquarters", )] pub headquarters: Address, - + #[serde( rename = "companyProperties", skip_serializing_if = "Option::is_none", )] pub company_properties: Option, - + #[serde( rename = "employeeDirectory", skip_serializing_if = "Option::is_none", )] pub employee_directory: Option, - + #[serde( rename = "employeeTShirtSizes", skip_serializing_if = "Option::is_none", )] pub employee_t_shirt_sizes: Option, - + #[serde( rename = "employeeProfiles", skip_serializing_if = "Option::is_none", )] pub employee_profiles: Option, - + #[serde( rename = "employeeSocialSecurityNumbers", skip_serializing_if = "Option::is_none", @@ -9753,12 +9747,12 @@ pub struct Equipment { rename = "$class", )] pub _class: String, - + #[serde( rename = "serialNumber", )] pub serial_number: String, - + #[serde( rename = "$identifier", )] @@ -9779,17 +9773,17 @@ pub struct Laptop { rename = "$class", )] pub _class: String, - + #[serde( rename = "make", )] pub make: LaptopMake, - + #[serde( rename = "serialNumber", )] pub serial_number: String, - + #[serde( rename = "$identifier", )] @@ -9802,55 +9796,55 @@ pub struct Person { rename = "$class", )] pub _class: String, - + #[serde( rename = "email", )] pub email: String, - + #[serde( rename = "firstName", )] pub first_name: String, - + #[serde( rename = "lastName", )] pub last_name: String, - + #[serde( rename = "middleNames", skip_serializing_if = "Option::is_none", )] pub middle_names: Option, - + #[serde( rename = "homeAddress", )] pub home_address: Address, - + #[serde( rename = "ssn", )] pub ssn: String, - + #[serde( rename = "height", )] pub height: f64, - + #[serde( rename = "dob", serialize_with = "serialize_datetime", deserialize_with = "deserialize_datetime", )] pub dob: DateTime, - + #[serde( rename = "nextOfKin", )] pub next_of_kin: NextOfKin, - + #[serde( rename = "$identifier", )] @@ -9863,93 +9857,93 @@ pub struct Employee { rename = "$class", )] pub _class: String, - + #[serde( rename = "employeeId", )] pub employee_id: String, - + #[serde( rename = "salary", )] pub salary: u64, - + #[serde( rename = "numDependents", )] pub num_dependents: Integer, - + #[serde( rename = "retired", )] pub retired: bool, - + #[serde( rename = "department", )] pub department: Department, - + #[serde( rename = "officeAddress", )] pub office_address: Address, - + #[serde( rename = "companyAssets", )] pub company_assets: Vec, - + #[serde(rename = "manager")] pub manager: Option, - + #[serde( rename = "email", )] pub email: String, - + #[serde( rename = "firstName", )] pub first_name: String, - + #[serde( rename = "lastName", )] pub last_name: String, - + #[serde( rename = "middleNames", skip_serializing_if = "Option::is_none", )] pub middle_names: Option, - + #[serde( rename = "homeAddress", )] pub home_address: Address, - + #[serde( rename = "ssn", )] pub ssn: String, - + #[serde( rename = "height", )] pub height: f64, - + #[serde( rename = "dob", serialize_with = "serialize_datetime", deserialize_with = "deserialize_datetime", )] pub dob: DateTime, - + #[serde( rename = "nextOfKin", )] pub next_of_kin: NextOfKin, - + #[serde( rename = "$identifier", )] @@ -9962,63 +9956,63 @@ pub struct Contractor { rename = "$class", )] pub _class: String, - + #[serde( rename = "company", )] pub company: Company, - + #[serde(rename = "manager")] pub manager: Option, - + #[serde( rename = "email", )] pub email: String, - + #[serde( rename = "firstName", )] pub first_name: String, - + #[serde( rename = "lastName", )] pub last_name: String, - + #[serde( rename = "middleNames", skip_serializing_if = "Option::is_none", )] pub middle_names: Option, - + #[serde( rename = "homeAddress", )] pub home_address: Address, - + #[serde( rename = "ssn", )] pub ssn: String, - + #[serde( rename = "height", )] pub height: f64, - + #[serde( rename = "dob", serialize_with = "serialize_datetime", deserialize_with = "deserialize_datetime", )] pub dob: DateTime, - + #[serde( rename = "nextOfKin", )] pub next_of_kin: NextOfKin, - + #[serde( rename = "$identifier", )] @@ -10031,96 +10025,96 @@ pub struct Manager { rename = "$class", )] pub _class: String, - + #[serde(rename = "reports")] pub reports: Option>, - + #[serde( rename = "employeeId", )] pub employee_id: String, - + #[serde( rename = "salary", )] pub salary: u64, - + #[serde( rename = "numDependents", )] pub num_dependents: Integer, - + #[serde( rename = "retired", )] pub retired: bool, - + #[serde( rename = "department", )] pub department: Department, - + #[serde( rename = "officeAddress", )] pub office_address: Address, - + #[serde( rename = "companyAssets", )] pub company_assets: Vec, - + #[serde(rename = "manager")] pub manager: Option, - + #[serde( rename = "email", )] pub email: String, - + #[serde( rename = "firstName", )] pub first_name: String, - + #[serde( rename = "lastName", )] pub last_name: String, - + #[serde( rename = "middleNames", skip_serializing_if = "Option::is_none", )] pub middle_names: Option, - + #[serde( rename = "homeAddress", )] pub home_address: Address, - + #[serde( rename = "ssn", )] pub ssn: String, - + #[serde( rename = "height", )] pub height: f64, - + #[serde( rename = "dob", serialize_with = "serialize_datetime", deserialize_with = "deserialize_datetime", )] pub dob: DateTime, - + #[serde( rename = "nextOfKin", )] pub next_of_kin: NextOfKin, - + #[serde( rename = "$identifier", )] @@ -10133,7 +10127,7 @@ pub struct CompanyEvent { rename = "$class", )] pub _class: String, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -10148,10 +10142,10 @@ pub struct Onboarded { rename = "$class", )] pub _class: String, - + #[serde(rename = "employee")] pub employee: Employee, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -10166,15 +10160,15 @@ pub struct ChangeOfAddress { rename = "$class", )] pub _class: String, - + #[serde(rename = "Person")] pub person: Person, - + #[serde( rename = "newAddress", )] pub new_address: Address, - + #[serde( rename = "$timestamp", serialize_with = "serialize_datetime", @@ -10232,7 +10226,7 @@ export interface IConcept { $class: string; } -export type ConceptUnion = IAddress | +export type ConceptUnion = IAddress | ICompany; export interface IAsset extends IConcept { @@ -10410,7 +10404,7 @@ export interface IPerson extends IParticipant { nextOfKin: NextOfKin; } -export type PersonUnion = IEmployee | +export type PersonUnion = IEmployee | IContractor; export interface IEmployee extends IPerson { @@ -10566,7 +10560,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio { "key": "concerto@1.0.0.xsd", "value": " - @@ -10622,7 +10616,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio { "key": "concerto.xsd", "value": " - @@ -10676,7 +10670,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio { "key": "org.acme.hr.base@1.0.0.xsd", "value": " - @@ -10722,7 +10716,7 @@ exports[`codegen #formats check we can convert all formats from namespace versio { "key": "org.acme.hr@1.0.0.xsd", "value": " - From af98a5622225830e6fcb1b59162336f09495968f Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Wed, 8 Nov 2023 16:27:19 +0000 Subject: [PATCH 10/12] feat(*): handle scalar case Signed-off-by: Jonathan Casey --- lib/codegen/fromcto/golang/golangvisitor.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/codegen/fromcto/golang/golangvisitor.js b/lib/codegen/fromcto/golang/golangvisitor.js index 99defab7..0af24616 100644 --- a/lib/codegen/fromcto/golang/golangvisitor.js +++ b/lib/codegen/fromcto/golang/golangvisitor.js @@ -170,8 +170,23 @@ class GoLangVisitor { } if(ModelUtil.isMap(field)) { - const decl = field.getModelFile().getType(field.getType()); - parameters.fileWriter.writeLine(1, `${field.getName()} := make(map[${this.toGoType(decl.getKey().getType())}]${this.toGoType(decl.getValue().getType())})`); + const mapDeclaration = field.getModelFile().getType(field.getType()); + let mapKeyType = mapDeclaration.getKey().getType(); + let mapValueType = mapDeclaration.getValue().getType(); + + if (mapDeclaration.getModelFile().getType(mapKeyType).isScalarDeclaration?.()) { + mapKeyType = mapDeclaration.getModelFile().getType(mapKeyType).getType(); + } + + const goKeyType = this.toGoType(mapKeyType); + + if (mapDeclaration.getModelFile().getType(mapValueType).isScalarDeclaration?.()) { + mapValueType = mapDeclaration.getModelFile().getType(mapValueType).getType(); + } + + const goValueType = this.toGoType(mapValueType); + + parameters.fileWriter.writeLine(1, `${field.getName()} := make(map[${goKeyType}]${goValueType})` + ' `json:"' + field.getName() + '"`'); return null; } From c1c3763839d6178bb9cb1646ddb5dc09ae56892a Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Wed, 8 Nov 2023 16:27:55 +0000 Subject: [PATCH 11/12] test(*): update snapshot Signed-off-by: Jonathan Casey --- test/codegen/__snapshots__/codegen.js.snap | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/codegen/__snapshots__/codegen.js.snap b/test/codegen/__snapshots__/codegen.js.snap index 26d45a87..8b9b2375 100644 --- a/test/codegen/__snapshots__/codegen.js.snap +++ b/test/codegen/__snapshots__/codegen.js.snap @@ -590,11 +590,11 @@ type Company struct { concerto_1_0_0.Concept Name string \`json:"name"\` Headquarters Address \`json:"headquarters"\` - companyProperties := make(map[string]string) - employeeDirectory := make(map[SSN]Employee) - employeeTShirtSizes := make(map[SSN]TShirtSizeType) - employeeProfiles := make(map[string]Concept) - employeeSocialSecurityNumbers := make(map[string]SSN) + companyProperties := make(map[string]string) \`json:"companyProperties"\` + employeeDirectory := make(map[string]Employee) \`json:"employeeDirectory"\` + employeeTShirtSizes := make(map[string]TShirtSizeType) \`json:"employeeTShirtSizes"\` + employeeProfiles := make(map[string]Concept) \`json:"employeeProfiles"\` + employeeSocialSecurityNumbers := make(map[string]string) \`json:"employeeSocialSecurityNumbers"\` } type Department int const ( @@ -628,7 +628,7 @@ type Person struct { Ssn string \`json:"ssn"\` Height float64 \`json:"height"\` Dob time.Time \`json:"dob"\` - nextOfKin := make(map[KinName]KinTelephone) + nextOfKin := make(map[string]time.Time) \`json:"nextOfKin"\` } type Employee struct { Person @@ -6142,11 +6142,11 @@ type Company struct { concerto_1_0_0.Concept Name string \`json:"name"\` Headquarters Address \`json:"headquarters"\` - companyProperties := make(map[string]string) - employeeDirectory := make(map[SSN]Employee) - employeeTShirtSizes := make(map[SSN]TShirtSizeType) - employeeProfiles := make(map[string]Concept) - employeeSocialSecurityNumbers := make(map[string]SSN) + companyProperties := make(map[string]string) \`json:"companyProperties"\` + employeeDirectory := make(map[string]Employee) \`json:"employeeDirectory"\` + employeeTShirtSizes := make(map[string]TShirtSizeType) \`json:"employeeTShirtSizes"\` + employeeProfiles := make(map[string]Concept) \`json:"employeeProfiles"\` + employeeSocialSecurityNumbers := make(map[string]string) \`json:"employeeSocialSecurityNumbers"\` } type Department int const ( @@ -6180,7 +6180,7 @@ type Person struct { Ssn string \`json:"ssn"\` Height float64 \`json:"height"\` Dob time.Time \`json:"dob"\` - nextOfKin := make(map[KinName]KinTelephone) + nextOfKin := make(map[string]time.Time) \`json:"nextOfKin"\` } type Employee struct { Person From cb72d752820d9f5a8a1fdddcae9f6dd3b907f485 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Wed, 8 Nov 2023 16:28:11 +0000 Subject: [PATCH 12/12] test(*): fix test regression Signed-off-by: Jonathan Casey --- test/codegen/fromcto/golang/golangvisitor.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/codegen/fromcto/golang/golangvisitor.js b/test/codegen/fromcto/golang/golangvisitor.js index 72f3da30..e37aa9fd 100644 --- a/test/codegen/fromcto/golang/golangvisitor.js +++ b/test/codegen/fromcto/golang/golangvisitor.js @@ -358,7 +358,7 @@ describe('GoLangVisitor', function () { return true; }); - const mockField = sinon.createStubInstance(Field); + const mockField = sinon.createStubInstance(Field); const getType = sinon.stub(); mockField.dummy = 'Dummy Value'; @@ -378,10 +378,11 @@ describe('GoLangVisitor', function () { mockMapDeclaration.isMapDeclaration.returns(true); mockMapDeclaration.getKey.returns({ getType: getKeyType }); mockMapDeclaration.getValue.returns({ getType: getValueType }); + mockMapDeclaration.getModelFile.returns({ getType: getType }); goVisit.visitField(mockField,param); - param.fileWriter.writeLine.withArgs(1, 'dictionary := make(map[string]string)').calledOnce.should.be.ok; + param.fileWriter.writeLine.withArgs(1, 'dictionary := make(map[string]string) `json:"dictionary"`').calledOnce.should.be.ok; }); });