OpenAPITools / OpenAPITools/openapi-generator

[BUG] Code generation completely skips "string64" parameter

Open
#21,014 1 comment 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

Description

SPEC contains (extract of the relevant parts):

components:
  schemas:
    string64:
      maxLength: 64
      type: string

which is then referenced elsewhere with a simple ref:

    hoststate:
      $ref: '#/components/schemas/string64'

The generator completely skips hoststate, leading to errors at buildtime (go-server):

$ java -jar openapi-generator-cli.jar generate -o server/ -g go-server -i openapi-3.1.yaml
$ cd server
$ go build

go/model_host.go:24:12: undefined: Hoststate
...
... too many errors


The generated code also forgets to import "errors" and "io" leading to other build errors that can be easily worked around by manually adding the missing imports (separate issue).

By removing the string64 and directly using "string", the problem goes away, like this:

    hoststate:
      maxLength: 64
      type: string

(leaving only the missing "errors" and "io" imports)

It's painful and less concise though to replace everywhere in the API all references to fixed length types, since they appear many times.

openapi-generator version

using latest stable version, at this time 7.12.0

OpenAPI declaration file content or url
components:
  schemas:
    string64:
      maxLength: 64
      type: string
Generation Details

java -jar openapi-generator-cli.jar generate -o server/ -g go-server -i openapi-3.1.yaml

Steps to reproduce

As per Generation Details and the OpenAPI snippet. Adding any ref to string64 does not work.

Suggest a fix

It should generate the code for all components that reference string64. Currently it silently skips all components that are a $ref to string64.

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 by reproducing the issue with the provided OpenAPI schema and go-server generation command, then inspect the generated go/model_host.go where Hoststate is missing. Trace how the generator handles components referenced through string64; done means the referenced Hoststate model is generated, while the separately reported missing errors and io imports remain out of scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java, openapi
Domain
backend-api-design, build-system, devtools
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.