OpenAPITools / OpenAPITools/openapi-generator

[BUG][GO] Missing attribute when using composed schema

Open
#15,897 0 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 (example)?
  • 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 combining a composed schema (aPlusB) with a schema with more properties (d), attributes from combined schema (d) are ignored.

openapi-generator version

Discovered on 6.6.0
Also present in 7.0.0-20230622.013523-127 SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: Test
  version: v1
paths:
  /test:
    get:
      operationId: get
      responses:
        "200":
          description: Get
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/e"

components:
  schemas:
    a:
      type: object
      properties:
        attA:
          type: string
    b:
      type: object
      properties:
        attB:
          type: integer
    aPlusB:
      type: object
      allOf:
        - $ref: "#/components/schemas/a"
        - $ref: "#/components/schemas/b"
    d:
      type: object
      allOf:
        - $ref: "#/components/schemas/aPlusB"
      properties:
        attD:
          type: string
    e:
      type: object
      allOf:
        - $ref: "#/components/schemas/d"
      properties:
        attE:
          type: integer

Generation Details
java -cp ${repo}/go-oapi-codegen.jar:${repo}/openapi-generator-cli.jar org.openapitools.codegen.OpenAPIGenerator generate \
    -i ./test-open-api.yml \
    -g go \
    -o ./output/ \
    --additional-properties=packageVersion=1.0.0,useOneOfDiscriminatorLookup=true,isGoSubmodule=true \
    --global-property apiTests=false
Steps to reproduce
  1. Save the open api yaml as test-open-api.yml
  2. Run the command to generate the code
  3. Open file ./output/model_e.go
Expected struct
type E struct {
    AttE *int32 `json:"attE,omitempty"`
    AttD *int32 `json:"attE,omitempty"`
    AttA *string `json:"attA,omitempty"`
    AttB *int32 `json:"attB,omitempty"`
}
Actual struct
type E struct {
    AttE *int32 `json:"attE,omitempty"`
    AttA *string `json:"attA,omitempty"`
    AttB *int32 `json:"attB,omitempty"`
}
Related issues/PRs
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

Use the supplied test-open-api.yml with the OpenAPIGenerator generate command and the Go generator, then inspect output/model_e.go. Compare the generated E struct with the expected attributes, especially AttD, and consider the issue resolved when regeneration includes properties inherited through the composed schemas.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.