openapi-tools / swagger-maven-plugin

Maven plugin to activate the Swagger Core library to generate OpenAPI documentation.
MIT License
72 stars 46 forks source link

Add possibility to use ModelConverters #55

Closed hiddewie closed 4 years ago

hiddewie commented 4 years ago

This enables the use of ModelConverters from the plugin.

Use case: a complex model which is represented as a simple type when used as a request parameter.

hiddewie commented 4 years ago

Pull request has been updated for the new master commits

langecode commented 4 years ago

Swagger is actually using the Java ServiceLoader mechanism to discover different things, e.g., ModelConverter implementations. The missing support for this in the kongchen plugin was actually the primary reason for starting this plugin.

This implies that if you place a file in META-INF/services with the name io.swagger.v3.core.converter.ModelConverter which contains the fully qualified name of your model converter, then Swagger should pick this up and activate the model converter.

This also means that you can actually package model converter implementations inside separate jar files and re-use these across projects.

You can see the code for discovery in ModelConverters

hiddewie commented 4 years ago

@langecode Thanks for noticing that. I have been looking through the source code of Swagger Core, but did not find that ServiceLoader call. That seems to solve my issue. I will close this PR.