openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open rost5000 opened this issue 2 years ago • 1 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
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
  • gradle openapi generator plugin
  • java-micronaut-server
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")

rost5000 avatar May 05 '23 14:05 rost5000

@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

altro3 avatar Aug 27 '24 06:08 altro3