raml-dotnet-tools icon indicating copy to clipboard operation
raml-dotnet-tools copied to clipboard

Map definition with pattern properties

Open majkimester opened this issue 6 years ago • 4 comments

If I define this type in RAML:

types:
  MyMap:
    type: object
    properties:
      []:
        type: string
        required: false

The following c# code is generated from that:

    public partial class MyMap  : Dictionary<string,String>
    {

    } // end class

That way I can define Map objects. It is fine, but this syntax is not documented in the raml-spec: https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#additional-properties

But the raml-spec defines pattern properties, which should look like:

types:
  MyMap:
    type: object
    properties:
      /[a-zA-Z0-9_]*/:     # it consume any regular expression between the slashes
        type: string
        required: false

This format not converted to proper Dictionary class by this tool, but other tools like oas-raml-converter with swagger-codegen-cli converts it to proper HashMap class in Java.

This tools should support the pattern properties to define proper Map (Dictionary) classes.

The responsible function is here:

https://github.com/mulesoft-labs/raml-dotnet-tools/blob/e027487fbe13bd5df199ed329a805f05bcf7c654/Raml.Tools/RamlTypeParser.cs#L267-L272

majkimester avatar Mar 14 '18 23:03 majkimester

It used to be a valid syntax but it was changed.

woodp avatar Mar 14 '18 23:03 woodp

It was a valid syntax 2 years ago in RAML 1.0 RC 1 but it is not a valid syntax now with the official 1.0.1 release. (It was released more than one and a half years ago.)

Map syntax with [] was removed in RAML 1.0 RC2: https://github.com/raml-org/raml-spec/wiki/RAML-1.0-RC1-vs-RC2

So please support additionalProperties instead.

Changing the square brackets to slashes does the business:

if (ramlType.Object.Properties.Count == 1 && ramlType.Object.Properties.First().Key.StartsWith("/") && ramlType.Object.Properties.First().Key.EndsWith("/")) { return ParseMap(ramlType, key); }

majkimester avatar Mar 15 '18 15:03 majkimester

that code would add any regex pattern as a dictionary, no matter what it contains

woodp avatar May 18 '18 15:05 woodp

The old format can contain also a regexp, so that way it also add any regex pattern as a dictionary, no difference so far:

types:
  MapOfNumbers:
    type: object
    properties:
      [a-zA-Z]:
        type: number

But anyway the main question is will this project actively maintained in the near future or it was abandoned?

I just ask it as I tried to use it for complex interfaces, and found lot of issues. I did not opened ticket for them so far as I see the current ones are also untouched, and I won't open any further ticket if they will never be fixed.

majkimester avatar Jun 11 '18 21:06 majkimester