Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate generator from openapi-generator #1037

Closed
melix opened this issue Jun 1, 2023 · 5 comments
Closed

Migrate generator from openapi-generator #1037

melix opened this issue Jun 1, 2023 · 5 comments
Assignees

Comments

@melix
Copy link
Contributor

melix commented Jun 1, 2023

Issue description

Currently, our OpenAPI generation strategy lives in the OpenAPI Generator project. This causes a number of issues:

  • the generator is quite outdated. It generates code for Micronaut 3.4. The code is not compatible with Micronaut 4.
  • it cannot be easily tested with newer releases of Micronaut
  • it reproduces logic which exists in Micronaut Launch (code generation), without the flexibility of Micronaut Launch
  • It's "one shot" only, meaning that it is not possible to incrementally add new APIs
  • it is not integrated with our build plugins
  • the guide is not consistent with the experience of other guides

Therefore, we should migrate the logic from the OpenAPI Generator project to this project, as a submodule. It is perfectly acceptable to reuse the same code as in the original project, by having a dependency on OpenAPI generator. The difference is that we handle the releases of the Micronaut support, and we can create consistent experience.

This should let us:

  • implement code generation directly in Micronaut Launch or
  • add support for OpenAPI code generation in our build plugins

(build plugins support is currently our main focus).

@melix melix self-assigned this Jun 1, 2023
melix added a commit to micronaut-projects/micronaut-gradle-plugin that referenced this issue Jun 5, 2023
This commit demonstrates an integration of the Micronaut OpenAPI generator
directly into the Gradle plugin. Because that project is still work in
progress, it uses a source dependency.

This feature allows the generation of an OpenAPI client or server directly
in the build pipeline.

For now, we only support generation of apis and models. Tests are not
supported, but it is arguable if we should handle this at the plugin
level or via something like Micronaut launch instead.

When the `io.micronaut.openapi` plugin is applied, then a new
`openapi` extension is added to the `micronaut` configuration block,
letting the user declare a definition to use. For example:

```
micronaut {
   ...
   openapi {
       client(file("src/openapi/petstore.json")) {
           apiPackageName = "com.mycompany.petstore.api"
           modelPackageName = "com.mycompany.petstore.model"
       }
   }
}
```

Then the APIs and models are generated (in 2 distinct tasks) as
part of the build process. We're using generated output directories
(e.g `build/generated/openapi/client/...`) so it means that the tasks
are executed on every invocation, but they are cacheable.

Relates to micronaut-projects/micronaut-openapi#1037
@sdelamo
Copy link
Contributor

sdelamo commented Jun 14, 2023

@melix we merged #1040 but it needs documentation. Docs are currently out of date:

If you wish to generate Micronaut projects from OpenAPI definition files, utilize the OpenAPI Generator's Micronaut support. Refer to the "Micronaut server generation with OpenAPI" guide or the "Micronaut Client generation with OpenAPI" guide for details.

@melix
Copy link
Contributor Author

melix commented Jun 14, 2023

The merged PR only adds support for the generator in Micronaut OpenAPI. It is not effectively usable without build plugins, or invoking directly the API. I think we need to add support for this first, then we can update the docs and guides.

melix added a commit to micronaut-projects/micronaut-gradle-plugin that referenced this issue Jun 16, 2023
* Initial implementation of Micronaut OpenAPI plugin

This commit demonstrates an integration of the Micronaut OpenAPI generator
directly into the Gradle plugin. Because that project is still work in
progress, it uses a source dependency.

This feature allows the generation of an OpenAPI client or server directly
in the build pipeline.

For now, we only support generation of apis and models. Tests are not
supported, but it is arguable if we should handle this at the plugin
level or via something like Micronaut launch instead.

When the `io.micronaut.openapi` plugin is applied, then a new
`openapi` extension is added to the `micronaut` configuration block,
letting the user declare a definition to use. For example:

```
micronaut {
   ...
   openapi {
       client(file("src/openapi/petstore.json")) {
           apiPackageName = "com.mycompany.petstore.api"
           modelPackageName = "com.mycompany.petstore.model"
       }
   }
}
```

Then the APIs and models are generated (in 2 distinct tasks) as
part of the build process. We're using generated output directories
(e.g `build/generated/openapi/client/...`) so it means that the tasks
are executed on every invocation, but they are cacheable.

Relates to micronaut-projects/micronaut-openapi#1037

* Manual sync of graalvm workflows

* Update dependency com.google.devtools.ksp:symbol-processing-gradle-plugin to v1.8.22-1.0.11 (#739)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update for latest OpenAPI snapshot

* Upgrade to Micronaut OpenAPI 5.0.0-M10

* Add documentation about OpenAPI plugin

* Do not use OpenAPI generator specific types as input of tasks/extensions

This will help properly isolate the execution code from the API.

* Use the worker API

While it makes the code more complex, it allows the flexibility of overriding
the default version of the generator that the plugin uses, and also makes it
possible for a user to implement their own code generators and leveraging the
plugin to perform code generation.

* Clarify documentation and fix sonar warnings

---------

Co-authored-by: Milenko Supic <supic82@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@altro3
Copy link
Collaborator

altro3 commented Jul 2, 2023

@melix as I understand, this issue already completed. Can I close it?

@melix
Copy link
Contributor Author

melix commented Jul 2, 2023

I'm using it to track documentation too, I'm looking at the guides now.

@melix
Copy link
Contributor Author

melix commented Jul 6, 2023

First guide PR: micronaut-projects/micronaut-guides#1297

melix added a commit to micronaut-projects/micronaut-guides that referenced this issue Jul 7, 2023
This is now using the build plugins instead of the external
OpenAPI generator project.

Closes micronaut-projects/micronaut-openapi#1037
sdelamo added a commit to micronaut-projects/micronaut-guides that referenced this issue Jul 11, 2023
* Re-introduce OpenAPI Client guide

This commit introduces a new guide for generation of OpenAPI clients.
Compared to the previous version, this guide is much simplified:

- it doesn't make use of the Twitter API anymore, but uses OpenMeteo
instead
- it doesn't require authentication, which was making the guide more
complicated than it should
- it doesn't explain how to use the client in a controller, since
this is generic Micronaut code and that we show how to use the
client in tests

* Reintroduce OpenAPI server generation guide

This is now using the build plugins instead of the external
OpenAPI generator project.

Closes micronaut-projects/micronaut-openapi#1037

* No spaces in :exclude-for-build: macro

* Use `@NotBlank` instead of `@NotNull`

* Fix review feedback

* artifactId is postgresql

* Add create-app-features.adoc[]

* remove non existing invokerPackage

* constructor: use open curly brace instead of semicolon

* move swagger-annotations and openapi-generator-server to invisible features

* remove micronaut.server.port=8080

* remove context-path=/ in configuration

* use micronaut.application.name=micronautguide

* Add @ExecuteOn in addBook method

* remove unused imports

* remove #jackson configuration

* add configuration

* use @notblank for String

---------

Co-authored-by: Tim Yates <tim.yates@gmail.com>
Co-authored-by: Sergio del Amo <sergio.delamo@softamo.com>
@sdelamo sdelamo closed this as completed Jul 13, 2023
sdelamo added a commit to micronaut-projects/micronaut-guides that referenced this issue Jul 14, 2023
* Migrate `oracle-email-delivery` guide source and docs to Jakarta Mail for Micronaut 4 [skip ci]

closes #1119

* Update Guides to Micronaut 4

* use platform bom

* bump up asciidoc to 2.5.7

* add src/docs/asciidoc folder

delete asciidoc files

* remove mention 11 to graalvm

* Add warning about YAML dependency before yaml conf

* Add YAML feature for Application which use yaml

* use create-app-features

* add http-client feature to add HTTP Client dependency

* yaml config

* add note about HTTP Client dependencies

* use jakarta.validation not javax.validation

* use correct Micronaut validation coordinates

* use feature validation not micronaut-validation

* remove unused resources

* use create-app-features

* update to geb to 7.0

* add yaml dependency callout

* use jakarta.persistence

replace javax.persistence wtih jakarta.persistence

* add yaml feature

add yaml feature

yaml feature

add yaml

yaml feature

* remove jansi

ansi

* websocket feature

* add validation feature

* use Java 17 in Github Actions

* use JDK 17 not 11

* isse with validation and optional

* use auto_increment for h2

* support more

* update to Gradle 8.1.1

* update shadow jar to 8.1.1

* upgrade Micronaut Gradle plugin to 4.0.0-M6

* source and target compatibility to 17

* upgrade asciidoctor gradle plugin to 4.0.0-alpha.1

* remove asciidoc docExtensions

* Update spring guides

* delete GORM guides

* add jackson-databind dependency

* remove open api generator guides

* Remove jakarta-persistence-api feature

* pin guides to M5

* Fix micronaut-security-api-key

* Fix micronaut-security-basicauth

* Fix micronaut-security-jwt-cookie

* Fix micronaut-security-jwt

* Fix build for micronaut-security-keys-jwks

* Fix micronaut-security-session

* Fix micronaut-spring-boot -- ass yaml and Serdeable annotation

* Fix micronaut-token-propagation -- http-client addition, moved classes and generic types

* Fix micronaut-turbo-native -- Add generic types for auth

* Fix hotwire-turbo-micronaut-chat -- add validation feature

* Fix micronaut-cloud-secrets-azure : still fails for kotlin KSP/Serde issue

* Fix graphql -- Add yaml, doesn't work with Serde

* Fix graphql-todo -- jakarta Transactional, add validation, use jackson not serde

* hibernate-reactive: fix query type, add validation STILL FAILS, Validation doesn't seem to work...

* fix java-records: add validation

* jaxrs-jdbc: switch to jakarta, add validation and yaml. STILL FAILS KSP/Gradle/Serde again

* jpa-hibernate: add yaml and validation. Doesn't work

* liquibase: LiquibaseEndpoint now returns a list (per configuration), binned KSP for Kapt to get Kotlin to work

* micronaut-microstream-persistence: switch to Kapt, add Body annotation for Kotlin. Maven Build Failure for Groovy... Not sure why

* fix micronaut-oauth2-auth0: yaml

* fix oauth2-client-credentials-auth0: switch to kapt, add http-client and yaml

* fix oauth2-client-credentials-cognito: switch to kapt, add http-client, retry and yaml

* Fix oauth2-cognito: add yaml

* Fix oauth2-github: add yaml and http-client

* Fix oauth2-linkedin: add yaml and http-client

* Fix oauth2-keycloak: add yaml

* Fix oauth2-oidc-google: add yaml

* Fix oauth2-okta: add yaml

* Fix object-storage-gcp: add yaml

* object-storage-oracle-cloud: add yaml still fails locally.. might be M1 issue

* oracle-autonomous-db: add yaml, use jakarta Transactional. Fails with FlywayException: Unsupported Database: Oracle 18.0

* oracle-email-delivery: yaml, validation and require kapt or Gradle/Kotlin fails

* oracle-function-http: Switch to Serdeable from Introspected

* rabbit-rpc: added validation, open class for Kotlin and don't override deprecated/removed methods

* rabbit: Use Jakarta PostConstruct and MockBean doesn't seem to work with KSP 🤔

* jakarta.transaction.Transactional instead of javax

* add validation feature

* add kapt feature

* cloud-secrets-azure: use Kapt

* micronaut-configuration: use kapt for now

* creating-first-graal-app: use kapt

* email-sendgrid: add validation feature

* rewrite guide to return JSON

see: micronaut-projects/micronaut-core#9535

* micronaut-file-download-excel: add validation and open kotlin class

* Fix cache guide with kapt for now

* Flyway: Add Validation and Switch to jackson-databind as the endpoint isn't serdeable

* Use Name qualifier

micronaut-projects/micronaut-core#9534

* qualify tokenvalidator

* use kapt feature

* remove unnecessary yaml file

* add yaml feature to mongo guides

* add kapt feature to jaxrs

* Fix mongo-async guide with kapt.  Maven still fails

* remove jakarta-javax-persistence feature

* use record not pojo

* don't use optional geters

* Fix microservices-services-discover-consul with kapt, yaml, http-client and retry features

* Fix microservices-services-discover-eureka with kapt, yaml, http-client and retry features

* Fix metrics guide: Serdeable instead of Introspected, add yaml, validation, kapt and http-client

* fix hibernate-reactive: Switch to record class and add kapt

* Update graalvm instructions

* Update Micronaut Htp client guide

* only apply awaitility to java and kotlin

* use jakarta.annotation.PostConstruct

* kapt as kotlinFeatures

* fix distributed tracing Jaeger

* fix zipkin guide

* update jaeger opentelemetry to MN4

* update zipkin open telemetry guide

* add http-client to micronaut-cloud-traci-oci

* add http-client to google cloud trace guide

* kotlin-extension-fns: add http-client and kapt

* fix micronaut-kotlin-extensions-fns guide

* remove minimumJavaVersion

* add serialization-jackson feature to mongodb-sync guide

* add serialization-jackson and kapt for mongodb-sync

* skip maven tests

* Exclude Groovy from MicroStream for now

* run aws-secrets-manager-rotation tests

* run tests for google cloud screts guide

* use records

* Run XRay Guide tests

* Fix k8s guides: Added validation, kapt and open classes for kotlin, jakarta imports, etc

* mqtt: package rename, add yaml, awaitility in spock is futile

* Add yaml to Object Storage AWS

* Use correct endpoint-override config path for object-storage-aws test

* Skip Oracle Autonomous Database tests until we get Flyway fixed to include flyway-database-oracle

* Disable Gradle tests until micronaut-projects/micronaut-starter#1944

* Use normal Oracle DB and exclude tests until Flyway fix is out

* security-basicauth fix bad code in test

* Update version.txt

* Remove temporary kapt usage for Gradle

* Re-enable tests

* Switch oracle cloud streaming to Serdeable and fix

* Switch back to KAPT for the configuration guide

* Switch back to KAPT for the Data access MyBatis guide

* Disable tests for data-mongo-async -- Disabled since #1115

* Open k8s controllers, but roll back to Kapt for the API project

* Fix Kotlin for Data Access Mybatis

* Fix liquibase kotlin test by switching from internal classes

* Remove previous test data from db before each test

* Switch back to kapt for rabbitmq guide micronaut-projects/micronaut-core#9550

* Open things for extension in test

* Ideomatic kotlin for the Rabbit books guide

* Re-introduce OpenAPI Client guide (#1297)

* Re-introduce OpenAPI Client guide

This commit introduces a new guide for generation of OpenAPI clients.
Compared to the previous version, this guide is much simplified:

- it doesn't make use of the Twitter API anymore, but uses OpenMeteo
instead
- it doesn't require authentication, which was making the guide more
complicated than it should
- it doesn't explain how to use the client in a controller, since
this is generic Micronaut code and that we show how to use the
client in tests

* remove microaut.server.port=8080

* change micronaut.application.name to micronautguide

* add configuration

* copy adjustments

---------

Co-authored-by: Sergio del Amo <sergio.delamo@softamo.com>

* Reintroduce OpenAPI server generation guide (#1298)

* Re-introduce OpenAPI Client guide

This commit introduces a new guide for generation of OpenAPI clients.
Compared to the previous version, this guide is much simplified:

- it doesn't make use of the Twitter API anymore, but uses OpenMeteo
instead
- it doesn't require authentication, which was making the guide more
complicated than it should
- it doesn't explain how to use the client in a controller, since
this is generic Micronaut code and that we show how to use the
client in tests

* Reintroduce OpenAPI server generation guide

This is now using the build plugins instead of the external
OpenAPI generator project.

Closes micronaut-projects/micronaut-openapi#1037

* No spaces in :exclude-for-build: macro

* Use `@NotBlank` instead of `@NotNull`

* Fix review feedback

* artifactId is postgresql

* Add create-app-features.adoc[]

* remove non existing invokerPackage

* constructor: use open curly brace instead of semicolon

* move swagger-annotations and openapi-generator-server to invisible features

* remove micronaut.server.port=8080

* remove context-path=/ in configuration

* use micronaut.application.name=micronautguide

* Add @ExecuteOn in addBook method

* remove unused imports

* remove #jackson configuration

* add configuration

* use @notblank for String

---------

Co-authored-by: Tim Yates <tim.yates@gmail.com>
Co-authored-by: Sergio del Amo <sergio.delamo@softamo.com>

* remove zipkin replacement

* port guide to Micronaut Data JDBC

* Micronaut Framework 4.0.0

---------

Co-authored-by: Dean Wette <wetted@objectcomputing.com>
Co-authored-by: Tim Yates <tim.yates@gmail.com>
Co-authored-by: Cédric Champeau <cedric.champeau@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants