Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additionalProperties=true is getting mis-categorized as UntypedProperty #7586

Open
EtonDoze opened this issue Feb 6, 2018 · 0 comments
Open

Comments

@EtonDoze
Copy link
Contributor

EtonDoze commented Feb 6, 2018

Description

As per the definition of Free-Form Objects described in Swagger documentation here, additionalProperties: true needs to be treated as dictionary values can be of any type.

I assume any is interpreted as Object.class in the world of Java.
During the parsing or codegen modeling (not sure), such an object is treated as UntypedProperty causing following errors during codegen

[ERROR] No Type defined for Property io.swagger.models.properties.UntypedProperty@0
[ERROR] String to be sanitized is null. Default to ERROR_UNKNOWN

Actual: additionalProperties=true is treated as UntypedProperty. Generated class does not extend HashMap
Expected: additionalProperties=true needs to be treated as ObjectProperty. Generated class should extend HashMap

Sample notation:
pet.json << this one fails with above error

{
  "type": "object",
  "title": "pet",
  "additionalProperties": true,
  "properties": {
    "color": {
      "type": "string",
    }
  }
}

pet.json << this one works without any error

{
  "type": "object",
  "title": "pet",
  "additionalProperties": {
    "type": "object"
  },
  "properties": {
    "color": {
      "type": "string",
    }
  }
}
Swagger-codegen version

v2.3.1

Swagger declaration file content or url

swagger.json

{
  "swagger": "2.0",
  "paths": {
    "/pet": {
      "get": {
        "operationId": "petstoreGet",
        "responses": {
          "200": {
            "schema": {
              "$ref": "./pet.json"
            }
          }
        }
      }
    }
  }
}
Command line used for generation

Used maven plugin

<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
Steps to reproduce

Place above swagger.json and pet.json in same folder and run the maven plugin to generate java code.

Related issues/PRs
Suggest a fix/enhancement

Treat
"additionalProperties": true, exactly same as

"additionalProperties": {
  "type": "object"
}
@EtonDoze EtonDoze changed the title additionalProperties Free-Form Object is getting mis-categorized as UntypedProperty additionalProperties Free-Form Object is getting mis-categorized as UntypedProperty Feb 6, 2018
@EtonDoze EtonDoze changed the title additionalProperties Free-Form Object is getting mis-categorized as UntypedProperty additionalProperties Free-Form Object is getting mis-categorized as UntypedProperty Feb 6, 2018
@EtonDoze EtonDoze changed the title additionalProperties Free-Form Object is getting mis-categorized as UntypedProperty additionalProperties=true is getting mis-categorized as UntypedProperty Feb 6, 2018
@3ygun 3ygun mentioned this issue Feb 13, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant