swagger-api / swagger-api/swagger-codegen

codegen doesn't take into account the default values

Open
#1,892 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Server: Nodejs
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi,

Here is my swagger description:

  inline_response_200:
    properties:
      surname:
        type: "integer"
        default: 1
        format: "int32"
      name:
        type: "string"
        default: "lazy"
        enum:
        - clueless
        - lazy
        - adventurous
        - aggressive

And that's what we receive in the generated nodejs app:

exports.newCustomer = function(request) {

  var examples = {};

  examples['application/json'] = {
  "name" : "aeiou",
  "surname" : 123
};

Is that ok, that default values are not taken into consideration? string is the same each time, the numer also the same. Is that possible to make it work?
As we don't want to use hardcoded examples.

Regards,

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 Swagger description and the generated Node.js app shown in the report, then locate the code-generation entry point that produces the hardcoded application/json examples. Check how the surname and name defaults are represented during generation, and consider the issue done when generated examples use those defaults instead of fixed values such as 123 and "aeiou".

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, openapi
Domain
tooling
Issue type
Bug
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.