Giter Club home page Giter Club logo

concerto-codegen's Introduction

Concerto CodeGen

Model converters and codegen for Concerto format model files.

Install

npm install @accordproject/concerto-codegen --save

Use

Benchmark Model Generator

This API allows you to generate models of varying sizes (up to 100 MiB) which can be used to test the performance of your Concerto-handling code.

Generate a model up to a specified number of declarations and properties

You can generate a model up to a specified number of declarations and properties using:

const benchmarkModelGenerator = new BenchmarkModelGenerator();
const generated = benchmarkModelGenerator.generateConcertoModels({
    nDeclarations: 5, // Number of declarations in the model
    nProperties: 5, // Number of properties per declaration
});

Generate a model up to a specified size in bytes

You can generate a model up to a specified size in bytes, however you would need to specify how that model should grow.

Grow model by number of declarations

If you'd like to grow it by number of declarations, you will need to specify the number of properties that you wish the model to have (defaults to 1):

const benchmarkModelGenerator = new BenchmarkModelGenerator();
const generated = benchmarkModelGenerator.generateConcertoModels({
    generateUpToSize: 10000, // Target upper limit of growth in bytes
    growBy: 'declarations', // Element type by which the model should grow
    nProperties: 5, // Number of properties per declaration
});
Grow model by number of properties

If you'd like to grow it by number of properties, you will need to specify the number of declarations that you wish the model to have (defaults to 1):

const benchmarkModelGenerator = new BenchmarkModelGenerator();
const generated = benchmarkModelGenerator.generateConcertoModels({
    generateUpToSize: 10000, // Target upper limit of growth in bytes
    growBy: 'properties', // Element type by which the model should grow
    nProperties: 5, // Number of declarations in the model
});

The expected response will include an array of generated models (currently containing only a single model) and a metadata object with information about the generated model e.g:

{
  models: [
    {
      '$class': '[email protected]',
      decorators: [],
      namespace: '[email protected]',
      imports: [],
      declarations: [
        ...
      ]
    }
  ],
  metadata: {
    requestedModelSizeInBytes: 10000,
    humanReadableRequestedModelSize: '9.77 KiB',
    generatedModelSizeInBytes: 9952,
    humanReadableGeneratedModelSize: '9.72 KiB',
    declarationsN: 5,
    propertiesNInSmallestDeclaration: 15,
    propertiesNInLargestDeclaration: 16
  }
}

As you can see from the above example model, the generator will try its best to reach the upper generateUpToSize requested size, but may fall short by a few bytes.

License

Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0), available at http://creativecommons.org/licenses/by/4.0/.

concerto-codegen's People

Contributors

ahmad-kashkoush avatar aniruddha-shriwant avatar apoorvsxna avatar dependabot[bot] avatar dianalease avatar dselman avatar ekarademir avatar github-actions[bot] avatar j4m3sb0mb avatar jeromesimeon avatar jonathan-casey avatar kailash360 avatar kylebastien avatar martinhalford avatar mttrbrts avatar niladri24dutta avatar ragi-dayananda avatar sanketshevkar avatar santanu8961 avatar stefanblaginov avatar subhajit20 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

concerto-codegen's Issues

Vocabulary is auto generated for $identifier

Bug Report ๐Ÿ›

This issue may be considered a follow-up to this issue in the concerto repository.

Vocabulary is auto-generated for $identifier, while it is supposed to be skipped in this case.

Expected Behavior

Should not auto generate vocabulary for $identifier

Current Behavior

For this model,


concept Person identified {
	o String name
}

enum Color {
    o RED
    o BLUE
    o GREEN
}

asset Vehicle identified by vin {
    o String vin
    o Color color
}

asset Truck extends Vehicle {
    o Double weight
}

The following vocab is generated.

#Generated vocabulary for namespace: [email protected]
locale: en
namespace: [email protected]
declarations:
  - Person: Person
    properties:
      - $identifier: Identifier of the Person # should not be auto generated
      - name: Name of the Person
  - Color: Color
    properties:
      - RED: RED of the Color
      - BLUE: BLUE of the Color
      - GREEN: GREEN of the Color
  - Vehicle: Vehicle
    properties:
      - vin: Vin of the Vehicle
      - color: Color of the Vehicle
  - Truck: Truck
    properties:
      - weight: Weight of the Truck

Possible Solution

Fix bug in vocabularyvisitor.js in the concerto-codegen repository.

Steps to Reproduce

  1. Run
concerto compile --target vocabulary

for the above .cto file.

Rollup fails to bundle module

Rollup fails to bundle this module because of the browser entry point incorrect in package.json.

Context

Trying to bundle @accordproject/template-engine, which depends on this module.

Expected Behavior

Should be able to bundle this module.

Actual Behavior

Rollup fails with an error saying that is cannot resolve the @accordproject/concerto-codegen module.

Possible Fix

Update package.json.

Steps to Reproduce

Existing issues

Context

Your Environment

  • Version used:
  • Environment name and version (e.g. Chrome 39, node.js 5.4):
  • Operating System and version (desktop or mobile):
  • Link to your project:

Concerto error when inferring from a JSON Schema without a body

Context

An error gets thrown when converting JSON Schema to Concerto.

Expected Behavior

We expect this Concerto output:

namespace [email protected]

concept DataIOWriteDataByUri {
  o String name
  o String type
  o ActionContractSchema_alias_969551601_132_307_969551601_0_1080360522385_ input
  o ActionContractSchema_alias_893869671_313_536_893869671_0_10591185408304_ output
}

concept ActionContractSchema_alias_969551601_132_307_969551601_0_1080360522385_ {
  o String uri
  @StringifiedJson
  o String data
}

concept ActionContractSchema_alias_893869671_313_536_893869671_0_10591185408304_ {
  o String id
}

Actual Behavior

We get this error:

concerto infer --namespace com.docusign.app --format jsonschema --input packages/data-models/src/schemas/contracts/actions/verify/v1/bank-account.json --output example.cto
10:46:42 AM - ERROR: Cannot read properties of undefined (reading 'enum')
TypeError: Cannot read properties of undefined (reading 'enum')
    at JsonSchemaVisitor.visitDefinition (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:765:36)
    at JsonSchemaVisitor.visit (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:926:25)
    at Definition.accept (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaClasses.js:38:24)
    at JsonSchemaVisitor.visitLocalReference (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:375:19)
    at JsonSchemaVisitor.visit (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:905:25)
    at LocalReference.accept (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaClasses.js:38:24)
    at JsonSchemaVisitor.visitReference (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:401:18)
    at JsonSchemaVisitor.visit (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:908:25)
    at Reference.accept (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaClasses.js:38:24)
    at JsonSchemaVisitor.visitProperty (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-tools/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:518:15) 

Steps to Reproduce

We would like to issue this command

concerto infer --namespace com.docusign.app --format jsonschema --input ./jsonSchemaFromTypescriptShapes.json --output ./example.cto

Where jsonSchemaFromTypescriptShapes.json contains this valid JSON Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/DataIOWriteDataByUri",
  "definitions": {
    "DataIOWriteDataByUri": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "const": "Contracts.Actions.DataIO.Version3.WriteDataByUri"
        },
        "type": {
          "type": "string",
          "const": "action"
        },
        "input": {
          "$ref": "#/definitions/ActionContractSchema%3CActionContractSchema%3Calias-969551601-132-307-969551601-0-1080360522385%3E%3E"
        },
        "output": {
          "$ref": "#/definitions/ActionContractSchema%3CActionContractSchema%3Calias-969551601-307-463-969551601-0-10801928584726%3E%3E"
        }
      },
      "required": [
        "input",
        "name",
        "output",
        "type"
      ],
      "additionalProperties": false,
      "description": "This action contract handles writing data to a specific URI"
    },
    "ActionContractSchema<ActionContractSchema<alias-969551601-132-307-969551601-0-1080360522385>>": {
      "$ref": "#/definitions/ActionContractSchema%3Calias-969551601-132-307-969551601-0-1080360522385%3E",
      "description": "Action Contract Schema"
    },
    "ActionContractSchema<alias-969551601-132-307-969551601-0-1080360522385>": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "uri": {
          "type": "string"
        },
        "data": {
          "type": "object",
          "additionalProperties": {}
        }
      },
      "required": [
        "data",
        "uri"
      ],
      "description": "Action Contract Schema"
    },
    "ActionContractSchema<ActionContractSchema<alias-969551601-307-463-969551601-0-10801928584726>>": {
      "$ref": "#/definitions/ActionContractSchema%3Calias-969551601-307-463-969551601-0-10801928584726%3E",
      "description": "Action Contract Schema"
    },
    "ActionContractSchema<alias-969551601-307-463-969551601-0-10801928584726>": {
      "$ref": "#/definitions/ActionContractSchema%3CActionContractSchema%3Calias-893869671-313-536-893869671-0-10591185408304%3E%3E",
      "description": "Action Contract Schema"
    },
    "ActionContractSchema<ActionContractSchema<alias-893869671-313-536-893869671-0-10591185408304>>": {
      "$ref": "#/definitions/ActionContractSchema%3Calias-893869671-313-536-893869671-0-10591185408304%3E",
      "description": "Action Contract Schema"
    },
    "ActionContractSchema<alias-893869671-313-536-893869671-0-10591185408304>": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        }
      },
      "required": [
        "id"
      ],
      "additionalProperties": false,
      "description": "Action Contract Schema"
    }
  }
} 

Enhance graph.findConnectedGraph to use type hierarchy

Currently graph.findConnectedGraph does not use the type hierarchy, meaning that types that extend a target type are dropped from a filtered model.

Context

Using the code below we can "tree shake" the model manager, to remove all types that are not connected to a root/target type, and then render the result as a PlantUML diagram. Although the output is correct, it is aggressive in that if we have a model containing derived types that could be used in place of an abstract type the derived types are removed, leaving only the abstract type.

if (process.argv.length > 2) {
    const graphVisitor = new Common.ConcertoGraphVisitor();
    const graph = new Common.DirectedGraph();
    mm.accept(graphVisitor, { graph });
    const connectedGraph = graph.findConnectedGraph(process.argv[2]);

    // now create a new model manager that only includes types
    // that are included in the dependency graph
    const filteredModelManager = mm.filter((declaration) =>
      connectedGraph.hasVertex(declaration.getFullyQualifiedName())
    );

    const visitor = new CodeGen.PlantUMLVisitor();
    const parameters = {
      fileWriter: new FileWriter("."),
      showCompositionRelationships: true,
      hideBaseModel: true,
    };
    filteredModelManager.accept(visitor, parameters);
  }

Expected Behavior

It would be very useful to be able to optionally take into account the type hierarchy in the call to graph.findConnectedGraph allowing the caller to say "find everything connected to this type, and include all derived types that appear in the model".

Actual Behavior

Derived types are removed as they are not directly connected in the graph.

Possible Fix

Steps to Reproduce

  1. Run the REPL https://replit.com/@dselman/AccordProjectConcerto-Type-Dependencies#index.js
  2. Note that the types [email protected] and Cat are not included, although the abstract type Pet which they extend is

Existing issues

Context

Your Environment

  • Version used:
  • Environment name and version (e.g. Chrome 39, node.js 5.4):
  • Operating System and version (desktop or mobile):
  • Link to your project:

TypeScript codegen is broken with a model containing enum or scalar

Bug Report ๐Ÿ›

Invalid TS code is generated from this model. Looks like the logic to generate unions doesn't take into account scalars or enums.

namespace [email protected]

concept Address {
    o String street
    o String city
    o String zip
}

concept Order {
    o String sku
    o Integer amount
}

concept LoyaltyStatus {
    o String level
}

enum Color {
    o RED
    o GREEN
    o BLUE
    o PINK
    o BLACK
    o WHITE
}

concept Preferences {
    o Color[] favoriteColors optional
}

@template
concept TemplateData {
    o String firstName
    o String lastName
    o String[] middleNames
    o Boolean active
    o DateTime lastVisit
    o Address address
    o Order[] orders
    o LoyaltyStatus loyaltyStatus optional
    o Preferences preferences
}

Expected Behavior

Generates code that compiles.

Current Behavior

Code doesn't compile because a union is created containing IColor, even though Color is an enum.

Possible Solution

Steps to Reproduce

Context (Environment)

Desktop

  • OS: [e.g. macOS]
  • Browser: [e.g. Chrome, Safari]
  • Version: [e.g. 0.22.15]

Detailed Description

Possible Implementation

Error when inferring from JSON Schema with alternations in body

Expected Behavior

This Concerto code gets generated:

namespace [email protected]

concept VerifyBankAccount {
  o String name
  o String type
  o ActionContractSchema_alias_246531724_141_346_246531724_0_16261588163527_ input
  o VerifyResponse output
}

concept ActionContractSchema_alias_246531724_141_346_246531724_0_16261588163527_ {
  o Double accountNumber
  o definitions$_ActionContractSchema_alias_246531724_141_346_246531724_0_16261588163527_$_properties$_accountType accountType
  o Double routingNumber
}

enum definitions$_ActionContractSchema_alias_246531724_141_346_246531724_0_16261588163527_$_properties$_accountType {
  o checking
  o savings
  o credit_card
  o loan
}

concept VerifyResponse {
  o Boolean verified
}

Actual Behavior

This error gets thrown:

9:49:43 AM - ERROR: Cannot read properties of undefined (reading 'path')
TypeError: Cannot read properties of undefined (reading 'path')
    at JsonSchemaVisitor.visitProperty (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:551:45)
    at JsonSchemaVisitor.visit (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:948:25)
    at Property.accept (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaClasses.js:38:24)
    at /Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:642:48
    at Array.map (<anonymous>)
    at JsonSchemaVisitor.visitProperties (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:641:14)
    at JsonSchemaVisitor.visit (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:951:25)
    at Properties.accept (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaClasses.js:38:24)
    at JsonSchemaVisitor.visitNonEnumDefinition (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:723:15)
    at JsonSchemaVisitor.visit (/Users/andrew.wilson/.nvm/versions/node/v18.12.0/lib/node_modules/@accordproject/concerto-cli/node_modules/@accordproject/concerto-codegen/lib/codegen/fromJsonSchema/cto/jsonSchemaVisitor.js:954:25)

Steps to Reproduce

Run the following:

concerto infer --namespace com.docusign.app --format jsonschema --input packages/data-models/src/schemas/contracts/actions/verify/v1/bank-account.json --output example.cto

Where bank-account.json contains:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$ref": "#/definitions/VerifyBankAccount",
    "definitions": {
        "VerifyBankAccount": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "const": "Contracts.Actions.Verify.Version1.BankAccount"
                },
                "type": {
                    "type": "string",
                    "const": "action"
                },
                "input": {
                    "$ref": "#/definitions/ActionContractSchema%3CActionContractSchema%3Calias-246531724-141-346-246531724-0-16261588163527%3E%3E"
                },
                "output": {
                    "$ref": "#/definitions/ActionContractSchema%3CActionContractSchema%3Calias-246531724-346-450-246531724-0-1626237990000%3E%3E"
                }
            },
            "required": [
                "input",
                "name",
                "output",
                "type"
            ],
            "additionalProperties": false,
            "description": "Bank Account"
        },
        "ActionContractSchema<ActionContractSchema<alias-246531724-141-346-246531724-0-16261588163527>>": {
            "$ref": "#/definitions/ActionContractSchema%3Calias-246531724-141-346-246531724-0-16261588163527%3E",
            "description": "Action Contract Schema"
        },
        "ActionContractSchema<alias-246531724-141-346-246531724-0-16261588163527>": {
            "type": "object",
            "properties": {
                "accountNumber": {
                    "type": "number"
                },
                "accountType": {
                    "type": "string",
                    "enum": [
                        "checking",
                        "savings",
                        "credit-card",
                        "loan"
                    ]
                },
                "routingNumber": {
                    "type": "number"
                }
            },
            "required": [
                "accountNumber",
                "accountType",
                "routingNumber"
            ],
            "additionalProperties": false,
            "description": "Action Contract Schema"
        },
        "ActionContractSchema<ActionContractSchema<alias-246531724-346-450-246531724-0-1626237990000>>": {
            "$ref": "#/definitions/ActionContractSchema%3Calias-246531724-346-450-246531724-0-1626237990000%3E",
            "description": "Action Contract Schema"
        },
        "ActionContractSchema<alias-246531724-346-450-246531724-0-1626237990000>": {
            "$ref": "#/definitions/VerifyResponse",
            "description": "Action Contract Schema"
        },
        "VerifyResponse": {
            "anyOf": [
                {
                    "type": "object",
                    "properties": {
                        "verified": {
                            "type": "boolean",
                            "const": true
                        }
                    },
                    "required": [
                        "verified"
                    ],
                    "additionalProperties": false
                },
                {
                    "type": "object",
                    "properties": {
                        "verified": {
                            "type": "boolean",
                            "const": false
                        },
                        "verifyFailureReason": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "verified",
                        "verifyFailureReason"
                    ],
                    "additionalProperties": false
                }
            ]
        }
    }
}

TypeScript codegen creates invalid code for models with enums

Context

Models containing enums generate invalid TS code.

Expected Behavior

Code should compile.

Actual Behavior

Enums are included in the Union type, prefixed by an I. Enums are imported, also prefixed by an I.

Possible Fix

Steps to Reproduce

  1. Generate TS code for any model that contains an enum
  2. Compile the generated TS code

Existing issues

Context

Your Environment

  • Version used:
  • Environment name and version (e.g. Chrome 39, node.js 5.4):
  • Operating System and version (desktop or mobile):
  • Link to your project:

Inferring from JSON Schema may produce Concerto with properties starting with $

Context

When inferring from JSON Schema, we may produce Concerto CTO with properties starting with $, which is invalid.

Expected Behavior

When trying to infer:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "Foo": {
      "type": "object",
      "properties": {
        "$bar": {
          "type": "string"
        },
        "ba$z": {
          "type": "string"
        }
      },
      "required": [
        "$bar",
        "ba$z"
      ]
    }
  }
}

we would like to get this Concerto CTO file:

namespace [email protected]

concept Foo {
  o String _$bar
  o String ba$z
}

Actual Behavior

Instead we're getting:

namespace [email protected]

concept Foo {
  o String $bar
  o String ba$z
}

The $bar above is problematic.

Namespace is not defined for type "org.accordproject.contract.*".

While writing Visitor for Rust land, came across this error for a supposedly valid model file.

Context

Run this code in root of concerto-codegen repo.

'use strict';

const { ModelManager } = require('@accordproject/concerto-core');
const { FileWriter } = require('@accordproject/concerto-util');

const Visitor = require('./lib/codegen/fromcto/jsonschema/jsonschemavisitor');

const model = `namespace [email protected]

import org.accordproject.contract.* from https://models.accordproject.org/accordproject/contract.cto
import org.accordproject.runtime.* from https://models.accordproject.org/accordproject/runtime.cto

transaction MyRequest extends Request {
  o String input
}

transaction MyResponse extends Response {
  o String output
}

asset HelloWorldClause extends Clause {
  o String name
}`;

const modelManager = new ModelManager();
modelManager.addCTOModel(model);

const parameters = {
  fileWriter: new FileWriter('./output')
};
const visitor = new Visitor();

modelManager.accept(visitor, parameters);

console.log('Done');

Expected Behavior

As this is a valid model then expected the model to be validated by basemodelmanager.js.

Actual Behavior

The basemodelmanager.js throw an error on line 201 modelFile.validate();.

IllegalModelException: Namespace is not defined for type "org.accordproject.contract.*". 
    at /Users/martin/Dev/accord/concerto-codegen/node_modules/@accordproject/concerto-core/lib/introspect/modelfile.js:233:23
    at Array.forEach (<anonymous>)
    at ModelFile.validate (/Users/martin/Dev/accord/concerto-codegen/node_modules/@accordproject/concerto-core/lib/introspect/modelfile.js:225:27)
    at ModelManager.addModelFile (/Users/martin/Dev/accord/concerto-codegen/node_modules/@accordproject/concerto-core/lib/basemodelmanager.js:201:27)
    at ModelManager.addModel (/Users/martin/Dev/accord/concerto-codegen/node_modules/@accordproject/concerto-core/lib/basemodelmanager.js:234:14)
    at ModelManager.addCTOModel (/Users/martin/Dev/accord/concerto-codegen/node_modules/@accordproject/concerto-core/lib/modelmanager.js:80:21)
    at Object.<anonymous> (/Users/martin/Dev/accord/concerto-codegen/testharness.js:30:14)
    at Module._compile (node:internal/modules/cjs/loader:1246:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
    at Module.load (node:internal/modules/cjs/loader:1103:32) {
  component: '@accordproject/concerto-util',
  fileLocation: undefined,
  shortMessage: 'Namespace is not defined for type "org.accordproject.contract.*".',
  fileName: null
}

CSharp code gen fails for model containing a concept Transaction

Context

Cannot create a namespace containing a concept called Transaction.

Expected Behavior

Should allow this, concept names should use the namespace.

Actual Behavior

Generated code does not compile because the concerto system namespace contains a type called Transaction and the two type names collide.

Possible Fix

Steps to Reproduce

Existing issues

Context

Your Environment

  • Version used:
  • Environment name and version (e.g. Chrome 39, node.js 5.4):
  • Operating System and version (desktop or mobile):
  • Link to your project:

Unable to compile CSharp code with models containing reserved keywords

Context

The generated C# code cannot be compiled when models contain any reserved .NET keywords.
Eg, 'fixed', 'void', 'event', 'virtual' etc.. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/

enum invoice_amount_type {
   o fixed
   o maximum
}

enum issuing_card_type {
   o physical
   o virtual
}

enum invoice_status {
   o deleted
   o draft
   o open
   o paid
   o uncollectible
   o void
}

Expected Behavior

Any generated csharp code should be compilable.

Possible Fix

We can add a trailing underscore char to the reserved keyword.

Steps to Reproduce

Generate cshar code for any of the model provided in the above example. Add the generated models to any csharp project and try t build the project.

Your Environment

  • Version used: 3.11.1
  • Operating System and version (desktop or mobile): windows 11 desktop

[Enhancement] Create codegen featureset/delta documentation table

It would make adoption more manageable for codegen if we can clearly articulate differences in compiled results. At a minimum, we should develop a documentation summary with featuresets (e.g., inheritance, metamodel differences, etc.) that can be easily grasped at a high level.

Today, language deltas are documented separately for each codegen subtarget. By putting it in a single view, we can more readily understand differences, expected results, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.