Skip to content

[REQ] Feature Request Description #25006

Description

@morrta

Is your feature request related to a problem? Please describe.

JSON Schema if/then/else conditionals nested inside allOf (valid since OpenAPI 3.1 /
JSON Schema 2020-12) are not supported by the generator. This was previously requested in
#13090 ("Add support for if-then-else") but that issue was closed not_planned with no
discussion.
Right now, properties declared only inside then/else aren't
even generated as plain optional fields — they're dropped entirely. This means a model can never
represent that part of the API contract, even loosely.

Example
openapi: 3.1.0
info:
  title: Conditional properties example
  version: 1.0.0
paths: {}
components:
  schemas:
    OrderTO:
      type: object
      required:
        - orderType
        - status
      properties:
        orderType:
          type: string
        status:
          $ref: '#/components/schemas/StatusTO'
      allOf:
        - if:
            properties:
              status:
                properties:
                  value:
                    const: NEEDS_CLARIFICATION
          then:
            required:
              - clarificationNote
            properties:
              clarificationNote:
                type: string
              contactPhone:
                type: string
    StatusTO:
      type: object
      properties:
        value:
          type: string
          enum: [PENDING, NEEDS_CLARIFICATION, COMPLETED]

Generated today with  kotlin-server  (library  jaxrs-spec , openapi-generator-maven-plugin
7.25.0):

data class OrderTO(
    @JsonProperty("orderType") @Valid @NotNull val orderType: String,
    @JsonProperty("status") @Valid @NotNull val status: StatusTO,
)

clarificationNote  and  contactPhone  don't exist anywhere in the output, even though they're a
documented in the schema.

Describe the solution you'd like

expected output:

data class OrderTO(
    @JsonProperty("orderType") @Valid val orderType: String,
    @JsonProperty("status") @Valid val status: StatusTO,
    @JsonProperty("clarificationNote") @Valid val clarificationNote: String?=null,
    @JsonProperty("contactPhone") @Valid val contactPhone: String?=null,
)
  1. Recursively collect  then.properties  and  else.properties  (and nested  allOf  within them)
    and merge them into the parent schema's  properties  map, skipping any already defined at the
    top level.
  2. Do not promote  then.required / else.required  into the parent's unconditional  required 
    list — merged properties should always be generated as optional/nullable, since their
    conditional requiredness can't be statically expressed.

Describe alternatives you've considered

• Manually flattening  if / then / else  into plain  properties  via a spec-preprocessing step
before feeding it to the generator (a normalization pass). This works, but it's extra
build-pipeline complexity that every consumer of a spec with this pattern has to reinvent
themselves.
• Rewriting the external spec to avoid conditionals entirely — not possible when the spec is
owned/maintained by a third party and must be consumed as-is.

Additional context

Related: #13090 (original ask, closed not_planned, no body/discussion recorded).
• We hit this consuming a third-party OpenAPI 3.1 spec we don't control, where several schemas
use  if / then / else  to express "status X requires additional fields Y/Z". Since we can't
modify the external spec, the only current workaround is spec preprocessing before codegen.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions