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
  • #14665
Closed
Open
Issue created Feb 10, 2023 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Go] Default string values of enums are not double quoted

Created by: jlsherrill

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

When trying to generate a Go client binding for pulp (https://docs.pulpproject.org/pulp_rpm/_static/api.json), default values that are strings do not seem to be double quoted:

For example, a generated model for the mentioned spec is:

func NewRpmRpmRemote(name string, url string) *RpmRpmRemote {
        this := RpmRpmRemote{}
        this.Name = name
        this.Url = url
        var policy PolicyEnum = immediate
        this.Policy = &policy
        return &this
}

This fails to compile, and the generated tests fail with:

./model_rpm_rpm_remote.go:86:26: undefined: immediate

I would expect immediate to be wrapped in double quotes:

        var policy PolicyEnum = "immediate"

I suspect that this is related to toDefaultValue() here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java#L391-L405

Its either not being called, or is not detecting the string properly. The value mentioned is an enum and from testing with a simplified example, that is the root of the problem

openapi-generator version

6.4.0-SNAPSHOT
2023-02-09T02:46:35Z

OpenAPI declaration file content or url

http://localhost:8080/pulp/api/v3/docs/api.json

i've created a simpler example here: https://gist.github.com/jlsherrill/af376f50ca7692332ab19ce01d88ee11

Generation Details
          docker run --network=host --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
           -i http://localhost:8080/pulp/api/v3/docs/api.json \
           -g go \
          -o /local/packages/pulpGoBinding  --skip-validate-spec \
           --git-user-id=user_id --git-repo-id=repo_id \
           --package-name=pulpGoBinding \
           -p enumClassPrefix=true \
           -p structPrefix=true \
           -p disallowAdditionalPropertiesIfNotPresent=true
Steps to reproduce

Generate go bindings with the above command, and then run the resulting tests:

$  go test ./...
./model_patchedrpm_rpm_remote.go:74:26: undefined: immediate
./model_patchedrpm_rpm_remote.go:84:26: undefined: immediate
./model_patchedrpm_uln_remote.go:74:26: undefined: immediate
./model_patchedrpm_uln_remote.go:84:26: undefined: immediate
./model_rpm_rpm_remote.go:76:26: undefined: immediate
./model_rpm_rpm_remote.go:86:26: undefined: immediate
./model_rpm_rpm_remote_response.go:74:26: undefined: immediate
./model_rpm_rpm_remote_response.go:84:26: undefined: immediate
./model_rpm_uln_remote.go:78:26: undefined: immediate
./model_rpm_uln_remote.go:88:26: undefined: immediate
./model_rpm_uln_remote.go:88:26: too many errors
Related issues/PRs
Suggest a fix

Currently working to get a build going to try to debug further.

Assignee
Assign to
Time tracking