Bug 53190 - openapi.json leads to unknown base type error when generating Java clients
openapi.json leads to unknown base type error when generating Java clients
Status: ASSIGNED
Product: UCS@school
Classification: Unclassified
Component: HTTP-API (Kelvin)
UCS@school 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: UCS@school maintainers
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-04-28 17:38 CEST by Oliver Friedrich
Modified: 2021-04-30 17:20 CEST (History)
1 user (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 1: Cosmetic issue or missing function but workaround exists
Who will be affected by this bug?: 1: Will affect a very few installed domains
How will those affected feel about the bug?: 2: A Pain – users won’t like this once they notice it
User Pain: 0.011
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional): Workaround is available
Max CVSS v3 score:


Attachments
maven mwe - complete (83.67 KB, application/zip)
2021-04-30 17:10 CEST, Oliver Friedrich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Friedrich univentionstaff 2021-04-28 17:38:25 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
Comment 1 Daniel Tröder univentionstaff 2021-04-29 09:40:12 CEST
(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.
Comment 2 Oliver Friedrich univentionstaff 2021-04-30 17:06:49 CEST
Created attachment 10713 [details]
maven mwe -incomplete
Comment 3 Oliver Friedrich univentionstaff 2021-04-30 17:10:58 CEST
Created attachment 10714 [details]
maven mwe - complete
Comment 4 Oliver Friedrich univentionstaff 2021-04-30 17:20:22 CEST
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.