3
votes

I am developing a small web application with .NET Core backend and React (TS support) frontend.

For API definition/documentation I am using OpenAPI and have problems with code generation for the client. Bellow is a snippet of the yaml definitions (from swagger.json) that I use to generate client interfaces with Swagger Editor

crmObiskiPartnerjevResponse:
      type: object
      properties:
        id:
          type: integer
          format: int32
        PoslovniPartner:
          type: integer
          format: int32
          nullable: true
        DatumObiska:
          type: string
          format: date-time
          nullable: true
        NamenObiskaId:
          type: integer
          format: int32
          nullable: true
        Uporabnik:
          type: integer
          format: int32
          nullable: true
        Opomba:
          type: string
          nullable: true
        NamenObiskaNaziv:
          type: string
          nullable: true
        UporabnikNaziv:
          type: string
          nullable: true
        PoslovniPartnerNaziv:
          type: string
          nullable: true
      nullable: true

The problem is that when generating client code for typescript, Swagger editor messes up naming of properties. In this example it converts first letter to small cap (PoslovniPartner -> poslovniPartner). Any ideas would how to solve this would be much appreciated.

/**
 * ECE_crmWebAPI
 * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
 *
 * OpenAPI spec version: v1
 * 
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */

export interface CrmObiskiPartnerjevResponse { 
    id?: number;
    poslovniPartner?: number;
    datumObiska?: Date;
    namenObiskaId?: number;
    uporabnik?: number;
    opomba?: string;
    namenObiskaNaziv?: string;
    uporabnikNaziv?: string;
    poslovniPartnerNaziv?: string;
}
1

1 Answers

4
votes

Please have a look at the Codegen FAQ: Codegen - FAQ

The JSON response failed to deserialize properly into the object due to change in variable naming (snake_case to camelCase). Is there any way to keep the original naming?

Yes, please use the following option when generating TypeScript clients:

modelPropertyNaming
    Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name (Default: camelCase)

So, please set modelPropertyNaming to original