Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended interface doesn't produce an allOf type #1490

Closed
Mearman opened this issue Oct 4, 2023 · 6 comments
Closed

Extended interface doesn't produce an allOf type #1490

Mearman opened this issue Oct 4, 2023 · 6 comments
Labels

Comments

@Mearman
Copy link

Mearman commented Oct 4, 2023

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
Copy link
Author

Mearman commented Oct 4, 2023

I had a look at #400 and it looks like this is not a case that is tested

@github-actions
Copy link

github-actions bot commented Oct 4, 2023

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
Copy link
Collaborator

WoH commented Oct 4, 2023

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

@WoH
Copy link
Collaborator

WoH commented Oct 4, 2023

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
Copy link
Author

Mearman commented Oct 4, 2023

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

Copy link

github-actions bot commented Nov 4, 2023

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

@github-actions github-actions bot added the Stale label Nov 4, 2023
@github-actions github-actions bot closed this as completed Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants