I've successfully setup openapi generator (through gradle plugin) to generate the java client from a swagger specification. Today the server has been updated and the client now complains about unknown properties. The message is:
The field additionalProperties
in the JSON string is not defined in the Document
properties. JSON: ...
I found the message in the moustache template: okhttp-gson/pojo.mustache, defined in validateJsonElement and surrounded by tag {{^isAdditionalPropertiesTrue}}
However could not understand how to turn off the validation, how to pass isAdditionalPropertiesTrue=false
Here is my gradle build:
group = "swagger_generation"
generatorName = "java"
id = "client-generated"
inputSpec = "$projectDir/swagger_${swagFile}.json".toString()
outputDir = "$rootDir/client-generated-${swagFile}".toString()
apiPackage = "ie.client${swagSpec}"
invokerPackage = "ie.client${swagSpec}"
modelPackage = "ie.client.model${swagSpec}"
configOptions = [
openApiNullable: "false",
]
Edit: Has been proposed to change the tag from gson to Gradle, the reason to have gson is that the generated JSON class uses Gson to parse json content. I need it to skip any unknown properties. This is the default setting but it also generate the validateJsonElement that throw the error.
Resolved, the solution was to turn off the property disallowAdditionalPropertiesIfNotPresent:
configOptions = [
openApiNullable: "false",
disallowAdditionalPropertiesIfNotPresent: "false"
]