Getting interfaces from openapi-generator-cli

226 views Asked by At

I am trying to generate a typescript-axios client from an OpenApi schema.yml using openapitools/openapi-generator-cli.

Used yaml:

openapi: "3.0.0"
...
components:
  schemas:
    Pet:
      type: object
      required:
      - pet_type
      properties:
        pet_type:
          type: string
    Cat:
      allOf:
      - $ref: '#/components/schemas/Pet'
      - type: object
        properties:
          name:
            type: string

config.json for generator:

{
    "apiPackage": "apis",
    "modelPackage": "models",
    "withSeparateModelsAndApi": true,  
    "paramNaming": "original",
    "withInterfaces": true
}

As you can see I am using inheritance via allOf.

Expected cat.ts: interface for 'Cat'

export interface Cat extends Pet {...}

Actual cat.ts:

//imports
export type Cat = CatAllOf & Pet;

I looked into the configuration options for typescript-axios but did not find any solution.

A workaround/bug which does not work for my case as I need separation between models and api:

  • setting "withSeparateModelsAndApi": false achieves the expected interface extending (after some tweaks at the yaml)

Do you know a viable workaround?

0

There are 0 answers