OpenAPITools / OpenAPITools/openapi-generator
[BUG] [scala-http4s-server] Polymorphism not Working
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?
- 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
I am attempting to generate a simple inheritance feature. As a demonstration, I can recreate the problem using a very simple petstore example
In this example, I have:
- A
Petclass, with generic pet/owner information, like names. - A
Catclass, which is a trivial implementation of aPet. - A
Dogclass, which additionally has information about what breed it is.
I expect when I generate the following schema, I will have Cat and Dog classes that share a common base class Pet.
Instead, the generated code outputs an empty Cat class and a Dog class with only a single property, breed. Neither class has the properties they should have inherited from the Pet class.
openapi-generator version: 7.13.0, 7.16.0-SNAPSHOT
openapi: 3.1.0
info:
title: Example
description: Example
version: 1.0.0
components:
schemas:
Pet:
type: object
properties:
name:
type: string
ownerName:
type: string
discriminator:
propertyName: petType
required: [ petType, name, ownerName ]
Cat:
allOf:
- $ref: "#/components/schemas/Pet"
Dog:
allOf:
- $ref: "#/components/schemas/Pet"
- type: object
properties:
breed:
type: string
required: [ breed ]
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-g scala-http4s-server \
-I var/tmp/petstore/petstore.yml \
-o /var/tmp/petstore \
--openapi-normalizer REF_AS_PARENT_IN_ALLOF=true
Steps to reproduce
Generate the provided specification and analyze the resulting output.
Related issues/PRs
I've noticed this issue also appears when using the dart or dart-dio generators.
- Related: https://github.com/OpenAPITools/openapi-generator/issues/18167
- This issue is using the workaround where the
Petclass does not contain aone-ofdefinition.
- This issue is using the workaround where the
- Maybe related: https://github.com/OpenAPITools/openapi-generator/issues/19891
Suggest a fix
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 by running the provided petstore OpenAPI 3.1 specification with the scala-http4s-server command and inspect the generated Cat and Dog classes. Compare them with the Pet properties and confirm that the generated models preserve the inherited name and ownerName fields while retaining Dog's breed field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, scala
- Domain
- backend-api-design, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100