OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.29k stars 6.44k forks source link

[BUG][java-micronaut-server] Illegal codegeneration for security schemes #15428

Open rost5000 opened 1 year ago

rost5000 commented 1 year ago

Bug Report Checklist

Description

I try to create RBAC authentication based on micronaut controller. The micronaut controller was generated from openapi spec. The generator ignores the scope of the securitySchemes. I expected the security scopes in @Secured annotation. The generated file contains: @Secured({SecurityRule.IS_AUTHENTICATED}), but expected annotations like: @Secured({"write", "read"})

openapi-generator version
OpenAPI declaration file content or url

Here is a link: https://github.com/rost5000/micronaut-server-openapi/blob/master/src/main/resources/openapi.yaml

Generation Details
Steps to reproduce
  1. clone the project: https://github.com/rost5000/micronaut-server-openapi.git
  2. assemble the project: ./gradlew clean build
  3. The generated code is in build/generate-resources/main/src/main/java/com/example/api/AbstractDefaultController.java
Related issues/PRs
Suggest a fix

I suggest that openapi generator load scopes information from /security or /components/securitySchemes I expect to see in generated controllers the scopes of the security, like @Secured("write", "admin")

altro3 commented 2 weeks ago

@rost5000 Fixed it here: https://github.com/micronaut-projects/micronaut-openapi/pull/1733

Just use official micronaut generator for java and kotlin by micronaut-opeanpi gradle or maven plugin from this repo: https://github.com/micronaut-projects/micronaut-openapi

Look to this guide: https://guides.micronaut.io/latest/micronaut-openapi-generator-server.html

Also, please describe problems and suggestions here: https://github.com/micronaut-projects/micronaut-openapi/issues