-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
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"
}