lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.54k stars 499 forks source link

Extended interface doesn't produce an `allOf` type #1490

Closed Mearman closed 11 months ago

Mearman commented 1 year ago

Hopefully self explanatory. The ExtendedModelInterface path doesn't produce a schema that references the subtypes

export interface Model {
    a: string
}
export interface ExtendedModelInterface extends Model {
    b: string
}
export type ExtendedModelType = Model & ExtendedModelInterface;

@Route("model")
export class ModelController  {
    @Get("model")
    public async getBaseModel(): Promise<Model> {
        return {} as Model;
    }
    @Get("extended_model_interface")
    public async getExtendedModelInterface(): Promise<ExtendedModelInterface> {
        return {} as ExtendedModelInterface;
    }
    @Get("extemded_model_type")
    public async getExtendedModelType(): Promise<ExtendedModelType> {
        return {} as ExtendedModelType;
    }
}
components:
  schemas:
    Model:
      properties:
        a:
          type: string
      required:
        - a
      type: object
      additionalProperties: false
    ExtendedModelInterface:
      properties:
        a:
          type: string
        b:
          type: string
      required:
        - a
        - b
      type: object
      additionalProperties: false
    ExtendedModelType:
      allOf:
        - $ref: '#/components/schemas/Model'
        - $ref: '#/components/schemas/ExtendedModelInterface'

this is what I would expect

components:
  schemas:
    Model:
      properties:
        a:
          type: string
      required:
        - a
      type: object
      additionalProperties: false
    ExtendedModelInterface:
      allOf:
        - $ref: '#/components/schemas/Model'
        - properties:
            b:
              type: string
          required:
            - b
          type: object
          additionalProperties: false
    ExtendedModelType:
      allOf:
        - $ref: '#/components/schemas/Model'
        - $ref: '#/components/schemas/ExtendedModelInterface'
Mearman commented 1 year ago

I had a look at https://github.com/lukeautry/tsoa/pull/400 and it looks like this is not a case that is tested

github-actions[bot] commented 1 year ago

Hello there Mearman 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

WoH commented 1 year ago

OpenAPI 2 does not support this so we came up with out own DIY inheritance.

WoH commented 1 year ago

I would be fine with delaying that from before the metadata generation to the spec generators and have OpenAPI 3 use the "built in" way. Would you like to submit a PR for that?

Mearman commented 1 year ago

Ah do you mean having both behaviours, based on whether targeting OpenAPI V2 or V3?

github-actions[bot] commented 11 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days