1

I am using npm nswag to generate a TypeScript file from a Swagger .json file with the swaggerToTypeScriptClient code generator.

There is a problem when it comes across OData properties contained in the JSON. When it generates the interface, the TypeScript throws an error because it does not recognise the '@' in the OData property value.

This is an example of the original Swagger .json:

"Swashbuckle.OData.ODataResponse[System.Collections.Generic.List[Shadow.DataLayer.ReleaseBatchs]]": {
  "type": "object",
  "properties": {
    "@odata.context": {
      "type": "string"
    },
    "value": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Shadow.DataLayer.ReleaseBatchs"
      }
    }
  }
}

This is the corresponding TypeScript generated by the nswag swaggerToTypeScriptClient:

export interface ReleaseBatchs {
    @odata.context?: string | undefined;
    value?: ReleaseBatchs2[] | undefined;
}

This throws an error because it does not like the '@' in the property.

It would work if the generated code wrapped the property in quotes, like this:

export interface ReleaseBatchs {
    "@odata.context"?: string | undefined;
    value?: ReleaseBatchs2[] | undefined;
}

Is there a way to get the swaggerToTypeScriptClient to wrap these properties in quotes? Or to make it compatible with OData values?

iehrlich
  • 3,572
  • 4
  • 34
  • 43
Paul
  • 11
  • 2
  • We have to fix this here: https://github.com/RSuter/NJsonSchema/blob/master/src/NJsonSchema.CodeGeneration.TypeScript/Models/PropertyModel.cs#L38 ill look into this soon... – Rico Suter Jun 28 '17 at 21:31
  • OK. Thanks for this. I have created a pull request. – Paul Jun 29 '17 at 12:49

1 Answers1

0

This has been fixed in NSwag v11.3

Rico Suter
  • 11,548
  • 6
  • 67
  • 93