OpenAPITools / OpenAPITools/openapi-generator

[BUG] [scala-http4s-server] Polymorphism not Working

Open
#21,900 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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 Pet class, with generic pet/owner information, like names.
  • A Cat class, which is a trivial implementation of a Pet.
  • A Dog class, 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.

Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.