OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.74k stars 6.56k forks source link

[REQ] Go Server Default values #5511

Open langohr opened 4 years ago

langohr commented 4 years ago

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?

langohr commented 4 years ago

@LoveIsGrief Could you please take a look at that?

ghost commented 4 years ago

@langohr I'm not entirely sure why you pinged me since I'm not a maintainer, but if you have a look at CONTRIBUTING.md it contains guidelines on what to consider when submitting code.

Feel free to open a pull request with the rationale as to why your code works better and whether it'll be better for everybody or just for you. I'm sure the maintainers will have a look and give it a fair chance.