https://github.com/kokuwaio/micronaut-openapi-codegen
OpenAPI codegen for Micronaut
https://github.com/kokuwaio/micronaut-openapi-codegen
codegen micronaut openapi
Last synced: 3 months ago
JSON representation
OpenAPI codegen for Micronaut
- Host: GitHub
- URL: https://github.com/kokuwaio/micronaut-openapi-codegen
- Owner: kokuwaio
- License: apache-2.0
- Created: 2019-12-12T07:11:50.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-22T06:56:37.000Z (7 months ago)
- Last Synced: 2024-10-23T09:54:54.317Z (7 months ago)
- Topics: codegen, micronaut, openapi
- Language: Java
- Homepage:
- Size: 1.49 MB
- Stars: 39
- Watchers: 6
- Forks: 16
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Micronaut Codegen
OpenAPI code generator for Micronaut 4. Micronaut 3 is supported by version [3.x](https://github.com/kokuwaio/micronaut-logging/tree/3.x)
[](https://github.com/kokuwaio/micronaut-openapi-codegen/blob/main/LICENSE)
[](https://central.sonatype.com/namespace/io.kokuwa.micronaut)
[](https://github.com/kokuwaio/micronaut-openapi-codegen/actions/workflows/build.yaml?query=branch%3Amain)Include in your `pom.xml`:
```xml
org.openapitools
openapi-generator-maven-plugin
${version.org.openapitools.generator}
generate
micronaut
${project.build.directory}
src/resources//openapi/spec.yaml
changeMe
io.kokuwa.micronaut
micronaut-openapi-codegen
${version.io.kokuwa.micronaut.codegen}
```
## Features
* generate api interfaces (see [declarative client](https://docs.micronaut.io/latest/guide/index.html#clientAnnotation))
* generate model objects with fluent and property accessors
* generate interfaces for api tests based on method name and return code
* generate client interfaces with micronaut **clientId**
* add validation annotations
* support for One-Of interfaces
* support for additional properties with composed schemas
* generate example instances of the model-objects
* set a base class for all generated pojos, to allow extension with common functionality### Config options
* clientId: id for generated clients (if no client id is provided no interface will be generated)
* serdeable: add `@io.micronaut.serde.annotation.Serdeable` to models (default `true`)
* dateTimeRelaxed: add type registrar for relaxed time converter (default `true`)
* useBeanValidation: generate validation annotations (default `true`)
* useGenericResponse: return generic container or specific model, e.g. `Model` vs. `HttpResponse` (default `true`)
* useOptional: optional parameters are generated as `java.util.Optional` (default `true`)
* openApiNullable: add container `JsonNullable` to model objects that are nullable (default `true`)
* supportAsync: use reactivex return types, see [Reactive HTTP Request Processing](https://docs.micronaut.io/latest/guide/index.html#reactiveServer)
* pagable: generate provider for pagable (default `false`)
* generateExamples: generate example objects for the model, based on example and default values (default `false`)
* generateConstants: generate constants for model names and api paths (default `false`)
* generateAuthentication: generate Àuthentication into controller interfaces if response code 401 is present (default `false`)
* sealed: generate sealed interfaces (default `true`)
* record: generate records instead of pojos (default `false`)
* modelBaseClass: set a base class that all generated pojos extend (default is unset)For examples see [integration tests](src/it).
### Null handling and default values
Jackson Inclusions:
* `required=true` & `nullable=false`: `JsonInclude.ALWAYS`
* `required=true` & `nullable=true`: `JsonInclude.ALWAYS`
* `required=false` & `nullable=false`: `JsonInclude.NON_ABSENT`
* `required=false` & `nullable=true`: `JsonInclude.NON_NULL`Container (array/map):
* `required=true` & `nullable=false`: empty containers are set as default value
* `required=true` & `nullable=true`: containers have no default value
* `required=false` & `nullable=false`: containers have no default value
* `required=false` & `nullable=true`: containers have no default valueIf `jacksonDatabindNullable=true` is configured always `JsonNullable.undefined()` is set.
Do not forget to add the dependency to `pom.xml`:
```xml
org.openapitools
jackson-databind-nullable
0.2.6```
And register [Jackson Module](https://github.com/OpenAPITools/jackson-databind-nullable):
```java
@Factory
public class ApplicationFactory {@Singleton
JsonNullableModule jsonNullableModule() {
return new JsonNullableModule();
}
}
```### Not supported
* no project (e.g. `pom.xml`) is generated, only interfaces to implement
* no support for java <17