zijianhuang / openapiclientgen

Generate strongly typed C# and TypeScript client codes from Open API / Swagger definitions supporting jQuery, Angular, AXIOS, Fetch API, Aurelia and Angular Strictly Typed Forms
MIT License
64 stars 13 forks source link

dot in property name for TypeScript #49

Closed zijianhuang closed 5 months ago

zijianhuang commented 5 months ago

some Swagger / OpenAPI definitions have property names containing dot, such as openapi-directory\APIs\azure.com\batch-BatchService\2019-08-01.10.0

  AccountListSupportedImagesResult:
    properties:
      odata.nextLink:
        title: The URL to get the next set of results.
        type: string
      value:
        items:
          $ref: '#/definitions/ImageInformation'
        title: The list of supported Virtual Machine Images.
        type: array

Current for C#, I replace dot with underscore. And with DataContract, the generated codes:

    [System.Runtime.Serialization.DataContract(Namespace="http://fonlow.com/TestOpenApi/2024/01")]
    public class AccountListSupportedImagesResult
    {

        [System.Runtime.Serialization.DataMember(Name="odata.nextLink")]
        public string Odata_nextLink { get; set; }

        [System.Runtime.Serialization.DataMember(Name="value")]
        public ImageInformation[] Value { get; set; }
    }

And Swagger Editor with its code generators will remove dot for C# and TypeScript, and this will cause problem during serialization and deserialization.

The correct approach is:

  1. For TS, use quote to define the property name. for exampe:
    export interface AccountListSupportedImagesResult {
        'odata.nextLink'?: string | null;
        value?: Array<ImageInformation>;
    }
zijianhuang commented 5 months ago

other bugs:

zijianhuang commented 5 months ago

openapi-directory\APIs\azure.com\mariadb\2018-06-01 swagger definition error: LogFile inherited from ProxyResource declares name again.

zijianhuang commented 5 months ago

v2.8.1