OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.15k stars 592 forks source link

Update OpenAPI Generator to support Server Stubs with MicroProfile Annotations #11789

Open turkeylurkey opened 4 years ago

turkeylurkey commented 4 years ago

Is your feature request related to a problem? Please describe. When a developer needs to implement a REST service which is already described by an OpenAPI v3.0 or Swagger v2 document, it takes a long time to write the Java code. This is a mechanical process, at least at the start, and should be automated.

Describe the solution you'd like The OpenAPI Generator can generate client and server stubs when given an OpenAPI v3.0 (or Swagger v2) document that describes a REST interface. To work with OpenLiberty we should use the Java or the JAX-RS generator and it should use JSON-B for the data. It should also generate MicroProfile annotations in the Java code to help the developers who use that specification.

gcharters commented 4 years ago

@turkeylurkey please can you confirm, this is the generator you're referring to? https://github.com/OpenAPITools/openapi-generator

turkeylurkey commented 4 years ago

Yes, that's the one.

bmarwell commented 4 years ago

+1 from me. I just created an issue: https://github.com/OpenAPITools/openapi-generator/issues/6189

Where to implement

I haven't gotten the <library> tag to work, but it should be easy creating a new folder in https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/JavaJaxRS/

how to implement

If OpenLiberty could contribute such a generator to openapi-generator, that would be awesome and super helpful! I do not see another way to consume an OpenAPI document in Liberty.

Workaround:

use jaxrs-spec and overwrite some of the templates yourself. It is a bit of work, but will do. The swagger annotations are quite a bit different, I wasn't able to come up with something useful and did not implement then. If you do not need annotations, it is just a simple change in the pojo.mustache class: Just replace two or three imports and change JsonProperty to JsonbProperty etc. (two occurrences).

That's it, if you only need to generate interfaces!