Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5074
Closed
Open
Issue created Jan 22, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Go-experimental] Syntax error in generated petstore openapi3 samples

Created by: sebastien-rosset

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

The generated go-experimental code has multiple issues that cause syntax errors:

  1. Use but does not define the "NullableMap" type
  2. Refer to the "NullableTime.Time" type, but the type is actually "NullableTime"
  3. Import but does not use the "time" package
  4. Refer to the Nullable[]map[string]interface{}, which is not a valid golang type.
  5. Some "const" values are defined twice with the same identifier, once for the enum value, and once for the default value.

Other issues found:

  1. Missing pom.xml files in the go and go-experimental directories.

This can be easily reproduced in the openapi3 petstore sample. Specifically, the petstore sample petstore-with-fake-endpoints-models-for-testing.yaml is used to generate go-experimental code, but that code does not compile.

As an example, the go-experimental generator generates the following code:

/ NullableClass struct for NullableClass
type NullableClass struct {
  ....
  ArrayNullableProp *Nullable[]map[string]interface{} `json:"array_nullable_prop,omitempty"`
  ...
}

"*Nullable[]map[string]interface{}" is not a valid go type.

This code is committed in git at https://github.com/OpenAPITools/openapi-generator/blob/master/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go#L26

A secondary problem is that the CircleCI build does not catch the go compilation error (because of missing shell script in bin/utils/ensure-up-to-date).

openapi-generator version

master January 21 2020

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml

Command line used for generation
mvn package
./bin/openapi3/go-experimental-petstore.sh
Steps to reproduce

In the commands below, I used go 1.12.9, but the same problem would occur with any version.

./bin/openapi3/go-experimental-petstore.sh
cp -R samples/openapi3/client/petstore/go-experimental/* ~/tmp/
cd /tmp
go test -v ./...

The go compiler raises the following errors:

go-petstore/model_nullable_class.go:26:29: syntax error: unexpected [, expecting semicolon or newline or }
go-petstore/model_nullable_class.go:233:56: syntax error: unexpected [ after top level declaration
...
go-petstore/model_nullable_class.go:276:58: too many errors

Expected output: The go code should compile without error.

Also:

go-petstore/model_outer_enum_default_value.go:22:2: PLACED redeclared in this block
	previous declaration at go-petstore/model_outer_enum.go:22:21
Related issues/PRs
Suggest a fix

The problem is because of an issue in the following postProcessModels() method:

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java#L90

Assignee
Assign to
Time tracking