Univention Bugzilla – Bug 53190
openapi.json leads to unknown base type error when generating Java clients
Last modified: 2021-04-30 17:20:22 CEST
Tested against Kelvin-API v1.4.0 and OpenJRE 11 During the creation of a Java client using the OpenAPI Generator (1), the compilation fails due to UNKNOWN_BASE_TYPE. This error has been caused by a bug in OpenAPI (2) and can be easily fixed by removing the allOf-Attribute (3) from the "UserCreateModel" (line 826) in the generated openapi.json, so: "requestBody": { "content": { "application/json": { "schema": { "title": "user", "allOf": [ { "$ref": "#/components/schemas/UserCreateModel" } ] } } }, becomes "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserCreateModel" } } }, "required": true }, As there is only one schema object included, I guess there is no need for allOf here. With this, the client builds fine with swagger-codegen and openapi-generator. It should be considered whether the attribute allOf can be removed as it causes compilation errors. [1] https://github.com/OpenAPITools/openapi-generator [2] https://github.com/OpenAPITools/openapi-generator/issues/2892#issuecomment-549344604 [3] https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/#allof
(In reply to Oliver Friedrich from comment #0) > This error has been caused by a bug in OpenAPI (2) and can be easily fixed > by removing the allOf-Attribute (3) from the "UserCreateModel" (line 826) in > the generated openapi.json, so: 1. The error is in the OpenAPITools/openapi-generator, not in OpenAPI. 2. I can successfully build the Java client using https://editor.swagger.io/ and the openapi.json from Kelvin 1.4.0. Please supply instructions how to reproduce the problem.
Created attachment 10713 [details] maven mwe -incomplete
Created attachment 10714 [details] maven mwe - complete
I added a minimal working example. Instructions for reproduction of success: - <unzip the folder> - in first level, execute "./mvnw clean compile" -> Builds with success Reproduction of failure: - Replace <first level>/school-sh-connector-api-parent/school-sh-connector-kelvin-client/src/main/resources/kelvin-api-1.4.0.json with a newly generated openapi.json from kelvin api - in first level, execute "./mvnw clean compile" -> builds with errors This example uses the openapi-generator-maven-plugin in v4.3.1. If you upgrade it to the actual version (5.1.0) you get "java time" errors, but this seems like another problem.