Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 3.1.0 Missing type for array when multiple arrays with same ref #18290

Closed
5 of 6 tasks
am-on opened this issue Apr 4, 2024 · 3 comments
Closed
5 of 6 tasks

[BUG] 3.1.0 Missing type for array when multiple arrays with same ref #18290

am-on opened this issue Apr 4, 2024 · 3 comments

Comments

@am-on
Copy link

am-on commented Apr 4, 2024

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 a Schema has multiple array properties with same $ref, only the first array property gets correct type. The example file works correctly using openapi: 3.0.0

Relevant part from Schema:

properties:
  arrayFooOne:
    type: array
    items:
      $ref: '#/components/schemas/Foo'
  arrayFooTwo:
    type: array
    items:
      $ref: '#/components/schemas/Foo'
  arrayFooThree:
    type: array
    items:
      $ref: '#/components/schemas/Foo'

Elm

type alias BarAndFoos =
    { arrayFooOne : List Foo
    , arrayFooTwo : Maybe AnyType -- Should be `Maybe (List Foo)`
    , arrayFooThree : Maybe AnyType -- Should be `List Foo`
    }

Golang

type BarAndFoos struct {
	ArrayFooOne []Foo `json:"arrayFooOne"`
	ArrayFooTwo interface{} `json:"arrayFooTwo,omitempty"` // Should be ArrayFooTwo []Foo
	ArrayFooThree interface{} `json:"arrayFooThree"` // Should be ArrayFooThree []Foo 
}

Java

  public List<Foo> getArrayFooOne() {
    return arrayFooOne;
  }

  public Object getArrayFooTwo() { // Should be public List<Foo>
    return arrayFooTwo;
  }

  public Object getArrayFooThree() { // Should be public List<Foo>
    return arrayFooThree;
  }
openapi-generator version

openapi-generator-cli 7.5.0-SNAPSHOT
commit : f357be4

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: ""
  version: ""

paths:
  /user/getInfo:
    get:
      operationId: getUserInfo
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BarAndFoos'
          description: |
            OK
      security:
        - Session: []
      x-accepts: application/json

components:
  schemas:
    Foo:
      type: object
      required:
        - fooData
      properties:
        fooData:
          type: string

    BarAndFoos:
      type: object
      required:
        - arrayFooOne
        - arrayFooThree
      properties:
        arrayFooOne:
          type: array
          items:
            $ref: '#/components/schemas/Foo'
        arrayFooTwo:
          type: array
          items:
            $ref: '#/components/schemas/Foo'
        arrayFooThree:
          type: array
          items:
            $ref: '#/components/schemas/Foo'
Generation Details

Elm:

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \ 
      --input-spec openapi.yaml \
      --generator-name elm \
      --output "foo"

Golang:

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \ 
      --input-spec openapi.yaml \
      --generator-name go \
      --output "foo"

Java:

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \ 
      --input-spec openapi.yaml \
      --generator-name java \
      --output "foo"
Steps to reproduce

Use the provided OpenAPI declaration file and generate code.

Related issues/PRs
Suggest a fix
@wing328
Copy link
Member

wing328 commented Apr 5, 2024

thanks for reporting the issue. i've filed #18297 to fix it

@wing328
Copy link
Member

wing328 commented Apr 5, 2024

PR merged. please pull the latest master to give it a try to use the snapshot version mentioned in the project's readme

@wing328 wing328 closed this as completed Apr 5, 2024
@am-on
Copy link
Author

am-on commented Apr 5, 2024

Thank you so much for the speedy bug fix! Greatly appreciated!

I've tested the latest master on the example from this issue and our code where I noticed the bug, and in both cases, the bug is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants