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

fix(core): export type with required properties in all-of object #1819

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AllieJonsson
Copy link
Contributor

Status

READY

Description

Fixes #1670
This allows spec to contain a required array either in parent object, or a sibling object inside the allOf:

components:
  schemas:
    ContractPartial:
      type: object
      properties:
        uuid:
          type: string
        description:
          type: string
        start_date:
          type: string
          format: date
        end_date:
          type: string
          format: date
    Contract:
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractPartial'
        - type: object
          properties:
            active:
              type: boolean
              description: If this contract is current active.
          required:
            - description
            - end_date
            - start_date
            - uuid

Would yield the same result as

components:
  schemas:
    ContractPartial:
      type: object
      properties:
        uuid:
          type: string
        description:
          type: string
        start_date:
          type: string
          format: date
        end_date:
          type: string
          format: date
    Contract:
      type: object
      required:
        - description
        - end_date
        - start_date
        - uuid
      allOf:
        - $ref: '#/components/schemas/ContractPartial'
        - type: object
          properties:
            active:
              type: boolean
              description: If this contract is current active.

which is:

export interface ContractPartial {
  uuid?: string;
  description?: string;
  start_date?: string;
  end_date?: string;
}

export type ContractAllOf = {
  /** If this contract is current active. */
  active?: boolean;
};

export type Contract = ContractPartial & ContractAllOf & Required<Pick<ContractPartial & ContractAllOf, 'description' | 'end_date' | 'start_date' | 'uuid'>>;

The resulting type is

{
  uuid: string;
  description: string;
  start_date: string;
  end_date: string;
  active?: boolean;
}

image

@melloware melloware added this to the 7.4.2 milestone Jan 13, 2025
@melloware melloware added the bug Something isn't working label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Required properties across allOfs don't work
2 participants