typescriptliquidnswag

How to generate TypeScript client using NSwag in form of named properties?


We generate TypeScript client from swagger interface using NSwag.

The generated client looks like following:

client.EndPointFoo(arg1, arg2, arg3, ...)

We deal with issues that NSWag change order of arugments in case of some changes in Swagger interface and compiler sometime does not catch the problem in case that those parameters are of same type. This finally leads to runtime issues.

I would like to generate client in form of named properties, for example this way:

client.EndPointFoo(
    property1: arg1,
    property2: arg2,
    property3: arg3,
    ...)

Is this possible? Do I have write my own Liquid template or is there easier solution?


Solution

  • Disclaimer: I am a maintainer of Fern

    Hey @tomas, you can give Fern's TypeScript generator a spin which will generate named properties for the request so that it's easier to get compile breaks when your API changes.

    Here are our docs for importing an existing OpenAPI https://buildwithfern.com/docs/spec/openapi.

    npm install -g fern-api
    fern init --openapi <path to openapi|url>
    fern generate