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

Support discriminators #1121

Closed
Tracked by #1115
vitorcamachoo opened this issue Aug 12, 2024 · 5 comments · Fixed by #1251
Closed
Tracked by #1115

Support discriminators #1121

vitorcamachoo opened this issue Aug 12, 2024 · 5 comments · Fixed by #1251
Assignees
Labels
enhancement New feature or request @kubb/plugin-oas v2 v3 Kubb v3
Milestone

Comments

@vitorcamachoo
Copy link

What is the problem this feature would solve?

Our API is using the discriminators feature from the open API and Kubb does not support that making a possible migration to this tool impossible.
Supporting discriminators would be really useful for the community.
https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

External documents/projects?

No response

What is the feature you are proposing to solve the problem?

No response

What alternatives have you considered?

No response

@vitorcamachoo vitorcamachoo added the enhancement New feature or request label Aug 12, 2024
@helt
Copy link
Contributor

helt commented Aug 24, 2024

@vitorcamachoo can you provide details where the current behavior of kubb is not as you expected? Ideally with a minimal schema that replicates the issue(s)?

@vitorcamachoo
Copy link
Author

vitorcamachoo commented Aug 29, 2024

For the following schema:

---
openapi: 3.0.3
components:
  schemas:
    IssueEventParameters:
      type: object
      anyOf:
        - '$ref': '#/components/schemas/IssueEventParametersAcceptAssignment'
        - '$ref': '#/components/schemas/IssueEventParametersAddApprover'
        - '$ref': '#/components/schemas/IssueEventParametersAddTeam'
      discriminator:
        propertyName: eventType
        mapping:
          accept_assignment: '#/components/schemas/IssueEventParametersAcceptAssignment'
          add_approver: '#/components/schemas/IssueEventParametersAddApprover'
          add_team: '#/components/schemas/IssueEventParametersAddTeam'          

With the current Kubb version, it is being generated the following code:

import { IssueEventParametersAcceptAssignmentSchema } from './issueEventParametersAcceptAssignmentSchema';
import { IssueEventParametersAddApproverSchema } from './issueEventParametersAddApproverSchema';
import { IssueEventParametersAddTeamSchema } from './issueEventParametersAddTeamSchema';

export type IssueEventParametersSchema =
  | IssueEventParametersAcceptAssignmentSchema
  | IssueEventParametersAddApproverSchema
  | IssueEventParametersAddTeamSchema;
file: issueEventParametersAcceptAssignmentSchema

export type IssueEventParametersAcceptAssignmentSchema = {
  /**
   * @type object
   */
  parameters: {
    /**
     * @type string | undefined, uuid
     */
    issueAssignmentId?: string;
  };
};

The expectation of this last piece of code should be the following (it is missing the eventType property):

(generated by Orval)
import type { IssueEventParametersAcceptAssignmentSchemaEventType } from './issueEventParametersAcceptAssignmentSchemaEventType';
import type { IssueEventParametersAcceptAssignmentSchemaParameters } from './issueEventParametersAcceptAssignmentSchemaParameters';

export interface IssueEventParametersAcceptAssignmentSchema {
  eventType: IssueEventParametersAcceptAssignmentSchemaEventType;
  parameters: IssueEventParametersAcceptAssignmentSchemaParameters;
}

@stijnvanhulle stijnvanhulle added v3 Kubb v3 v2 labels Sep 20, 2024
@stijnvanhulle stijnvanhulle self-assigned this Sep 22, 2024
@stijnvanhulle
Copy link
Collaborator

@vitorcamachoo Can you provide my your swagger/openAPI(or a stripped down version) because I tried with the following example: https://gist.github.com/vrialland/7031316121cb8e025dfca9dccfc226b1 and that works just fine so not sure what we are missing or need to adapt.

@stijnvanhulle stijnvanhulle added this to the 3.0.0 milestone Sep 22, 2024
@stijnvanhulle stijnvanhulle linked a pull request Sep 23, 2024 that will close this issue
@stijnvanhulle stijnvanhulle mentioned this issue Sep 23, 2024
36 tasks
@stijnvanhulle
Copy link
Collaborator

@helt @vitorcamachoo v2.27.0 has been released with support for discriminators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request @kubb/plugin-oas v2 v3 Kubb v3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants