skyleague / therefore

Therefore, the JSON Schema toolkit for TypeScript.
https://skyleague.io
MIT License
5 stars 1 forks source link

OpenAPI schema generation produces non-compliant types #167

Open eugenpodaru opened 1 month ago

eugenpodaru commented 1 month ago

Description

Given the following interface:

export interface CreateSubSessionBody {
    type: 'ADVICE_AGREEMENT_SIGNED'
    firstName?: string | null | undefined
    lastName?: string | null | undefined
    lastNameInsertion?: string | null | undefined
    initials?: string | null | undefined
    dateOfBirth?: string | null | undefined
    email?: string | null | undefined
    phone?: string | null | undefined
    registeredAddress?: RegisteredAddress | null | undefined
    gender?: Gender | null | undefined
    nationality?: Nationality | null | undefined
    randomSeed?: number | undefined
}

This is the OpenAPI component that is being generated:

    CreateSubSessionBody:
      title: CreateSubSessionBody
      type: object
      properties:
        type:
          const: ADVICE_AGREEMENT_SIGNED
        firstName:
          type: string
          nullable: true
        lastName:
          type: string
          nullable: true
        lastNameInsertion:
          type: string
          nullable: true
        initials:
          type: string
          nullable: true
        dateOfBirth:
          type: string
          nullable: true
        email:
          type: string
          nullable: true
        phone:
          type: string
          nullable: true
        registeredAddress:
          anyOf:
            - $ref: '#/components/schemas/RegisteredAddress'
            - type: 'null'
        gender:
          anyOf:
            - $ref: '#/components/schemas/Gender'
            - type: 'null'
        nationality:
          anyOf:
            - $ref: '#/components/schemas/Nationality'
            - type: 'null'
        randomSeed:
          type: integer
      additionalProperties: true

Which produces validation errors when rendered:

Structural error at components.schemas.CreateSubSessionBody.properties.type
should NOT have additional properties
additionalProperty: const

Structural error at components.schemas.CreateSubSessionBody.properties.registeredAddress.anyOf.1.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string

Structural error at components.schemas.CreateSubSessionBody.properties.gender.anyOf.1.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string

Structural error at components.schemas.CreateSubSessionBody.properties.nationality.anyOf.1.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string

Expectation

The schema should not produce validation errors