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][Go] Panic when error is JSON array #15147

Closed
thiagoarrais opened this issue Apr 6, 2023 · 1 comment · Fixed by #15154
Closed

[BUG][Go] Panic when error is JSON array #15147

thiagoarrais opened this issue Apr 6, 2023 · 1 comment · Fixed by #15154

Comments

@thiagoarrais
Copy link
Contributor

Description

It seems like since #13680 openapi-generator's Go template assumes that JSON responses are single objects. But when ran against APIs that returns object arrays, it panics when trying to parse error messages. I've chased this down to the use of formatErrorMessage as demonstraded on Go Playground FQ8Js4GaBuv.

openapi-generator version

6.2.1 onwards. Reproduced against 6.5.0, which is latest stable as of this writing. 6.2.0 presents no problem.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: OpenAPI Library Demo App
  version: 0.0.1
servers: [
  {
    "url": "http://localhost:8000",
    "description": "local development server",
  },
]
paths:
  /books:
    get:
      responses:
        "422":
          description: error
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    message:
                      type: string
Suggest a fix

Maybe ensuring that metaValue' is a struct (by virtue of it's Kind field) before calling FieldByName will do the trick. See the docs for FieldByName.

@gcatanese
Copy link
Contributor

@thiagoarrais Good catch, I have created #15154 to address it. Thank you!

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

Successfully merging a pull request may close this issue.

2 participants