OpenAPITools / OpenAPITools/openapi-generator
List of child objects and kotlin generator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Openapi generator into kotlin-spring generates incorrect kotlin code when I use list (ZOO) of child objects (Cats or Dog) with the common inheritance parent (Pet) in the openapi definition. It creates a data class ZOOAnimalsInner with all fields required, does matter if it is field of Cat, Dog or Pet.
openapi-generator version
6.6.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
version: 1.0.0
title: allOf test
description: based on https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
paths:
/zoo:
patch:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ZOO'
responses:
'200':
description: Updated
components:
schemas:
Pet:
type: object
required:
- pet_type
properties:
pet_type:
type: string
discriminator:
propertyName: pet_type
Dog: # "Dog" is a value for the pet_type property (the discriminator value)
allOf: # Combines the main `Pet` schema with `Dog`-specific properties
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Dog`
required:
- bark
- breed
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
Cat: # "Cat" is a value for the pet_type property (the discriminator value)
allOf: # Combines the main `Pet` schema with `Cat`-specific properties
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Cat`
required:
- hunts
- age
properties:
hunts:
type: boolean
age:
type: integer
ZOO:
type: object
properties:
animals:
type: array
items:
oneOf:
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Cat'
Suggest a fix
Fields of Cat and fields of Dog shlould be optional in the generated class ZOOAnimalsInner.
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
Use the supplied OpenAPI declaration with the Kotlin Spring generator at version 6.6.0 and inspect the generated ZOOAnimalsInner class. Trace how the oneOf array items and inherited required fields are represented, then verify that Cat and Dog fields are optional in the generated class.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100