You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am trying to generate a Go client for an OpenAPI 3.1 document that represents a contract for a JSON:API endpoint.
My understanding is that union types, especially oneOf and anyOf, can be challenging to generate. Our OpenAPI document leverages all three union types (oneOf, anyOf, and allOf).
I'm not sure whether the compilation errors are due to a pathological OpenAPI document, the fact that the OpenAPI document is 3.1, or if it represents a bug in the Go code generator.
openapi-generator version
7.5, latest
Labels from the :latest image tag, repo sha: openapitools/openapi-generator-cli@sha256:7b4b9591a282b9cfe8ff66fc00719069133e263b855bc80e18432dbde3d39fe6:
Labels from the :v7.5.0 image tag, repo sha: openapitools/openapi-generator-cli@sha256:cdf11948948de9c21c6035de47dd5fc73c1651c8ba2ea0a4b86a527608ef52a9`:
Generating Go client code with the Docker image using:
docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:v7.5.0 generate \
-i /local/openapi.yaml \
-g go \
-o /local
Steps to reproduce
Install Go if you don't have it; the latest 1.22.2 is fine. Execute go version to make sure it is on your command path.
Create and cd into a new directory to isolate the test case OpenAPI and the generated code.
Download the problematic spec file from the gist as openapi.yaml.
Run the docker command above to generate the code.
Attempt to build the generated Go code: go build ./..., and you should receive a number of compilation errors
Example output:
$ go build ./...
# github.com/GIT_USER_ID/GIT_REPO_ID
./model_applications_create_applications_request_data.go:100:21: syntax error: unexpected { at end of statement
./model_applications_create_applications_request_data.go:102:2: syntax error: non-declaration statement outside functionbody
./model_applications_create_applications_request_data.go:175:21: syntax error: unexpected { at end of statement
./model_applications_create_applications_request_data.go:177:2: syntax error: non-declaration statement outside functionbody
./model_applications_list_application_200_response.go:123:21: syntax error: unexpected { at end of statement
./model_applications_list_application_200_response.go:125:2: syntax error: non-declaration statement outside functionbody
./model_applications_list_applications_200_response.go:123:21: syntax error: unexpected { at end of statement
./model_applications_list_applications_200_response.go:125:2: syntax error: non-declaration statement outside functionbody
./model_applications_list_applications_200_response_all_of_data.go:24:2: syntax error: unexpected [, expected field name or embedded type
./model_applications_list_applications_200_response_all_of_data.go:25:2: syntax error: unexpected [, expected field name or embedded type
./model_applications_list_applications_200_response_all_of_data.go:25:2: too many errors
I reproduced this with openapitools/openapi-generator-cli:v7.5.0 and openapitools/openapi-generator-cli:latest.
Related issues/PRs
Suggest a fix
The text was updated successfully, but these errors were encountered:
emetsger
changed the title
[BUG] Generated Go code does not compile.
[BUG] Generated Go (golang for the search algorithm) code does not compile.
May 3, 2024
Bug Report Checklist
Description
I am trying to generate a Go client for an OpenAPI 3.1 document that represents a contract for a JSON:API endpoint.
My understanding is that union types, especially
oneOf
andanyOf
, can be challenging to generate. Our OpenAPI document leverages all three union types (oneOf
,anyOf
, andallOf
).I'm not sure whether the compilation errors are due to a pathological OpenAPI document, the fact that the OpenAPI document is 3.1, or if it represents a bug in the Go code generator.
openapi-generator version
7.5, latest
Labels from the
:latest
image tag, repo sha:openapitools/openapi-generator-cli@sha256:7b4b9591a282b9cfe8ff66fc00719069133e263b855bc80e18432dbde3d39fe6
:Labels from the
:v7.5.0
image tag, repo sha: openapitools/openapi-generator-cli@sha256:cdf11948948de9c21c6035de47dd5fc73c1651c8ba2ea0a4b86a527608ef52a9`:OpenAPI declaration file content or url
Gist link
Validates with the online swagger-parser and redocly:
Generation Details
Generating Go client code with the Docker image using:
docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:v7.5.0 generate \ -i /local/openapi.yaml \ -g go \ -o /local
Steps to reproduce
Install Go if you don't have it; the latest 1.22.2 is fine. Execute
go version
to make sure it is on your command path.openapi.yaml
.go build ./...
, and you should receive a number of compilation errorsExample output:
I reproduced this with
openapitools/openapi-generator-cli:v7.5.0
andopenapitools/openapi-generator-cli:latest
.Related issues/PRs
Suggest a fix
The text was updated successfully, but these errors were encountered: