swagger-api / swagger-api/swagger-codegen

Vars that should be required according to the swagger - are generated as not required.

Open
#4,451 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java Issue: Bug Issue: Workaround available
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Vars that should be required according to the swagger - are generated as not required.
I see that it happens only to vars that are type "object".

Swagger-codegen version

2.2.2-SNAPSHOT

Swagger declaration file content or url
"create_ref": {
  "allOf": [
    {
      "$ref": "#/definitions/json_api_version"
    },
    {
      "type": "object",
      "required": [
        "data"
      ],
      "properties": {
        "data": {
          "type": "object",
          "required": [
            "type",
            "id",
            "meta"
          ],
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "folders",
                "items",
                "versions"
              ]
            },
            "id": {
              "type": "string"
            },
            "meta": {
              "type": "object",
              "required": [
                "extension"
              ],
              "properties": {
                "extension": {
                  "$ref": "#/definitions/base_attributes_extension_object"
                }
              }
            }
          }
        }
      }
    }
  ]
}
Command line used for generation

using java

Steps to reproduce

generate java sdk

Suggest a Fix

You can see in the json that under data there is array of requited vars:
"required": [
"type",
"id",
"meta"
]

but since "meta" is defined as object (I think that is the issue) it is not return in the "getRequired()" method in ModelImpl class.

(The same happens with it's parent "data")

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 ModelImpl.getRequired() and reproduce the Java SDK generation using the supplied Swagger declaration and command. Trace how required arrays are handled for the object-valued data and meta properties; done means required object variables are included in the generated model metadata as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.