OpenAPITools / OpenAPITools/openapi-generator

[REQ] Go Server Default values

Open
#5,511 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

go-server codegen defaultValue is null

We have extended the go-server templates to generate our own specific code.
Here we also use the "{{defaultValue}}" in our templates. We found an issue in the file

org/openapitools/codegen/languages/AbstractGoCodegen.java
in the method toDefaultValue

Change toDefaultValue method

By comparing then Codegen class with other Codegen classes this code works better for us:
org/openapitools/codegen/languages/AbstractGoCodegen.java LINE 727

    @Override
    public String toDefaultValue(Schema schema) {
        if (schema.getDefault() != null) {
            return schema.getDefault().toString();
        } else {
            schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
            if (schema.getDefault() != null) {
                return schema.getDefault().toString();
            }
            return null;
        }
    }

Is it possible to change that code?

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 in org/openapitools/codegen/languages/AbstractGoCodegen.java, at the toDefaultValue method around line 727. Compare its handling of referenced schemas with the other Codegen classes mentioned in the issue. Done means Go server templates receive the expected defaultValue when the default is defined on a referenced schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.