Skip to content

[BUG] go-gin-server generates empty struct for inappropriate types #18227

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

Open
6 tasks done
coryschwartz opened this issue Mar 25, 2024 · 0 comments
Open
6 tasks done

Comments

@coryschwartz
Copy link

coryschwartz commented Mar 25, 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

Switching from go-server to go-gin-server, I am surprised to see invalid models generated. I'm unable to switch to the gin server without manually editing the code after generation.

openapi-generator version
% ./tools/openapi-generator-cli version
7.4.0
OpenAPI declaration file content or url

bug is demonstrated in gist:
https://gist.github.com/coryschwartz/4b3674d8493e3398be9858993efa57f6

Generation Details

Empty struct is generated regardless of the type of model required in the yaml file. In my case,
I'm trying to generate models with a list of strings and a string map with "additional attributes", and the generated code is unusable since they are just an empty struct.

Steps to reproduce

Start with openapi yaml file with a list of strings defined.
Generate with go-gin-server
Observe that list of strings and string map are generated as empty structs

If you use my demo gist, you can run "make generate"

Related issues/PRs

There are a couple PRs related to improving the go-gin-server template, although not directly to empty struct generation.

#7280
#10429

Suggest a fix

The mustache file in question is this one: https://github.com/OpenAPITools/openapi-generator/blob/v7.4.0/modules/openapi-generator/src/main/resources/go-gin-server/model.mustache

This template lacks features that are found in the go-server template -- particularly the primitive type generation. I suspect a lot of the go-server model could be re-used in the go-gin-server template.

I'd be willing to sponsor the work.

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

1 participant