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

Scope is not added properly in generated code #852

Merged
merged 1 commit into from
Jan 28, 2021

Conversation

reta
Copy link
Contributor

@reta reta commented Jan 21, 2021

The CodegenSecurity model exposes scopes as a map which is not aligned within its usage in code generation templates. As the result, the scopes are not generated properly. The suggested fix is to update all templates to deal with scopes map in a proper way.

Verified against OAS2 / OAS3 generators, the following specification fragment

  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          scopes:
            read: read scope
            write: ""

On the generation side, the following code is being generated for OAS2 and OAS3 respectively.

@ApiOperation(                                                             
  value = "",                                                              
  notes = "Search all people",                                             
  response = Person.class,                                                 
  responseContainer = "List",                                              
  authorizations = {                                                       
    @Authorization(                                                        
      value = "oauth2",                                                    
      scopes = {                                                           
        @AuthorizationScope(scope = "read", description = "read scope"),   
        @AuthorizationScope(scope = "write", description = "")             
      }                                                                    
    )                                                                      
  },                                                                       
  tags = {"people"}                                                        
)                                                                          
@Operation(                                     
  summary = "",                                 
  description = "Search all people",            
  security = {                                  
    @SecurityRequirement(                       
      name = "oauth2",                          
      scopes = {"read", "write"}                
    )                                           
  },                                            
  tags = {"people"}                             
)                                               
    if ("oauth2".equals(authName)) {                                   
      auth = new OAuth(OAuthFlow.accessCode, "", "", "read, write");   
    }                                                           

Fixes swagger-api/swagger-codegen#10225.

@reta
Copy link
Contributor Author

reta commented Jan 21, 2021

@HugoMario please whenever you have time, I think this is the right way, using the same map-style iteration over scopes, tested on mostly all generators.

@reta
Copy link
Contributor Author

reta commented Jan 28, 2021

@HugoMario sorry, mind taking a look please? Thanks!

@HugoMario
Copy link
Contributor

LGTM, thanks a lot !

@HugoMario HugoMario merged commit 152df38 into swagger-api:master Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[jaxrs-cxf-cdi] Scope is not added properly in generating code from
2 participants