-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Open
Labels
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?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using kotlinx.serialization as serialization library and having an object without any properties other than discriminator itself, the outputted class is invalid - generator outputs an empty data class and makes Kotlin compilation fail.
openapi-generator version
v7.17.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Test Empty Model
version: 1.0.0
paths: {}
components:
schemas:
Response:
type: "object"
properties:
result_or_error:
nullable: true
discriminator:
propertyName: "_type"
mapping:
result: "#/components/schemas/EmptyModel"
error: "#/components/schemas/Error"
oneOf:
- $ref: "#/components/schemas/EmptyModel"
- $ref: "#/components/schemas/Error"
EmptyModel:
type: object
properties:
_type:
required:
- "_type"
type: string
default: "result"
additionalProperties: false
Error:
type: object
required:
- "code"
properties:
code:
type: integer
_type:
required:
- "_type"
type: string
default: "error"
additionalProperties: falseGeneration Details
kotlinx.serialization should be used.
Steps to reproduce
- Use the schema provided as an example
- Set serialization library to
kotlinx.serialization - Generate the Kotlin client
- Try to compile the client
Related issues/PRs
Suggest a fix
Going to open a PR in a bit.