Open creckord opened 1 year ago
I too have hit this issue. Same problem.
It seems that in the generate code, the URI
datatype is using java.net.URI
and not the one defined in my model.
@jimbydamonk that sounds like a slightly different problem. I specifically want to use java.net.URI
here.
My issue is that the class using the URI property wrongly assumes it is a generated class with the expected validation methods the generator adds.
We have a similar issue with those validateJsonObject
methods.
In our case, it is a oneOf
declaration of multiple objects, and it generates in the end a TypeAdapter<Object>
plus the real required TypeAdapter
s.
In theory, the oneOf
(and maybe the allOf
and anyOf
) Sets of objects should not contain classes which the generator has not generated from the API to avoid calling this validateJsonObject
method.
Same issue for attributes representing binaries.
type: string
format: binary
Excerpt from compilation error:
error: cannot find symbol
[ERROR] symbol: method validateJsonObject(JsonObject)
[ERROR] location: class File
Same thing with enums.
up!
java.lang.IllegalArgumentException: The field `operator` in the JSON string is not defined in the `xxx` properties. JSON: {"id":158}
I had the same problem generating by gradle plugin 6.6.0.
Overcame by adding supportingFilesConstrainedTo = ["JSON"]
, don't know why it works.
Doc openapi-generator-gradle-plugin
Hope I can save a bit of your time.
Bug Report Checklist
Description
We frequently specialize base types in order to indicate specific domain meaning and to apply domain constraints centrally. E.g.:
We also frequently "abuse"
allOf
to combine property-specific documentation with schema references:When these two (string subtype plus allOf) come together, it breaks the generated
validateJsonObject
:oneOf
is similarly broken.openapi-generator version
6.2.1
Regression: I upgraded from 5.4.0, where it still worked, to 6.2.1.
The error goes back to 6.0.0 with the new okhttp-gson-nextgen templates
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Callback.java
classSuggest a fix
The generator needs to check if the target type of a field to be validated is actually under its control, or skip the nested validate code.
Also, in our case, the additional validation isn't needed at all (validation happens on the returned values anyway). It would be awesome to have a generator option to skip the whole thing, including the CustomTypeAdapterFactory with its double conversion (JsonObject, bean).