swagger-api / swagger-api/swagger-codegen-generators

[SPRING] OAuth2 scopes missing

Open
#272 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

  • when setting security scopes in api definition they should be in the generated code too
 @ApiOperation(value = "Get Data", nickname = "getData", notes = "", response = Data.class, authorizations = {
        @Authorization(value = "oAuth", scopes = {
<the scopes list should be inserted here>
            })
    }, tags={ "data", })
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "data", response = Data.class),
        @ApiResponse(code = 200, message = "unexpected error", response = Error.class) })
    @RequestMapping(value = "/data",
        produces = { "application/json" },
        method = RequestMethod.GET)
    ResponseEntity<Data> getData();

my api definition looks like:

/data:
    get:
      summary: Get Data
      operationId: getData
      tags:
        - data
      responses:
        '200':
          description: data
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Data"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
      security:
        - oAuth: ["data:read"]

components:
  securitySchemes:
    oAuth:            
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://example.com/oauth/authorize
          tokenUrl: https://example.com/oauth/token
          scopes:
            - data:read

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the provided OpenAPI security block and generated Spring @ApiOperation example as the reproduction, then locate the Spring generator template responsible for rendering authorization scopes. Done means the generated Java annotation includes the data:read scope for the shown endpoint and preserves the existing OAuth2 authorization structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.