swagger-api / swagger-api/swagger-codegen

Set a default value for "defaultValue"?

Open
#8,274 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I'm trying to make a swagger client generator for C and I have noticed that when using the key "defaultValue" in my .mustache files and there is no defaultValue it gets set no "null". Is it possible to change that? I want it to be "NULL" and not "null".

Swagger-codegen version

2.4.0

Swagger declaration file content or url

My .mustache file:

{{#models}}{{#model}}
struct {{classname}} {
    {{#vars}}
    m_{{name}} = {{{defaultValue}}};
    {{/vars}}
}
{{/model}}{{/models}}
Command line used for generation

mvn package
java -DdebugModels -cp ../../modules/swagger-codegen-cli/target/swagger-codegen-cli.jar:target/C-swagger-codegen-1.0.0.jar io.swagger.codegen.Codegen -l C -i /home/nwerner/Projekte/datav2/framework/webapi/timeseries-rest-api-def.yaml -o ./test > test.txt

Steps to reproduce

Create a new swagger module and try to generate a client with at least one model, without defaultValue set, using your custom .mustache and the value will be "null". Can this be changed to be "NULL" instead?

char* m_{{name}} = {{{defaultValue}}}; -> char* m_{{name}} = null;

Suggest a fix/enhancement

I already searched in the repo and in the CodegenConfig class, but I couldn't locate how I could change it from "null" to "NULL".

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 with the custom .mustache template and trace how the defaultValue field is populated, including the CodegenConfig class mentioned in the issue. Use the provided mvn package and generation command to verify that an absent default renders as NULL for the C client without changing explicitly supplied values.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.