OpenAPITools / OpenAPITools/openapi-generator

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

Open
#18,227 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

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.

https://github.com/OpenAPITools/openapi-generator/issues/7280
https://github.com/OpenAPITools/openapi-generator/issues/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.

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 with modules/openapi-generator/src/main/resources/go-gin-server/model.mustache and reproduce the issue using the linked gist with make generate. Compare the go-gin-server template with the go-server template, especially primitive type generation. Done means list-of-string and string-map models generate usable Go fields instead of empty structs.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.