OpenAPITools / OpenAPITools/openapi-generator
[BUG][kotlin] `allOf: [{if, then}]` next to `properties` drops properties, emits empty `data class`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists? (Reproduced on 7.14.0 and 7.21.0)
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
When an object schema declares properties AND a top-level allOf whose only members are if/then/else conditional-validation branches (JSON Schema 2019-09+, valid in OpenAPI 3.1), the Kotlin generator silently drops the properties and emits an empty data class Foo(). Kotlin then fails to compile with Data class must have at least one primary constructor parameter.
if/then/else is not in the supported-feature matrix (closure of #13090 asked for a new issue). This report is about the silent drop + uncompilable output, not the lack of validation. Acceptable fixes: (a) ignore unsupported allOf: [if/then] as a no-op and keep properties, or (b) fail the generate step with a clear error instead of producing broken code.
openapi-generator version
Reproduced on 7.14.0 and 7.21.0.
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: Repro
version: 1.0.0
paths: {}
components:
schemas:
OpeningHours:
type: object
required: [accessMode]
properties:
accessMode:
type: string
enum: [ALWAYS, SCHEDULED]
weeklySchedule:
type: array
items: { type: string }
allOf:
- if:
required: [accessMode]
properties:
accessMode: { const: SCHEDULED }
then:
required: [weeklySchedule]
- if:
required: [accessMode]
properties:
accessMode: { const: ALWAYS }
then:
not:
required: [weeklySchedule]
Generation Details
kotlin client generator, jvm-ktor library (default options).
Steps to reproduce
- Run codegen against the spec above.
- Inspect the generated model.
Actual output
data class OpeningHours (
) {
}
e: OpeningHours.kt: Data class must have at least one primary constructor parameter
If you remove the allOf: [{if, then}] block, the same properties round-trip into a correct data class with accessMode and weeklySchedule fields. So properties are valid — they are being ignored specifically because of the unsupported conditional validation.
Expected output
A data class OpeningHours(val accessMode: ..., val weeklySchedule: ...) identical to the one produced when allOf is omitted. Conditional validation can be dropped silently (with a warning) or tracked separately — but the generated code must compile.
Suggest a fix
In the composition-resolution path, detect allOf branches that are purely if/then/else (no $ref, no type, no properties) and skip them rather than treating the schema as a composition of empty branches — which currently clears the properties map.
Alternatively, refuse to generate and report "if/then/else is unsupported" so users aren't left with silently broken output.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Kotlin jvm-ktor generator's composition-resolution path and reproduce the issue using the OpenAPI YAML in this report. Compare generation with and without the conditional allOf branches; done means properties are retained in the generated OpeningHours data class, or generation stops with a clear unsupported-feature error, and the output no longer fails Kotlin compilation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100