Maintains state of hasMore when security is filtered (#4585)

This commit is contained in:
Jason Culverhouse
2019-11-25 00:08:18 -08:00
committed by William Cheng
parent 40799937fb
commit d0e838ee02
3 changed files with 131 additions and 0 deletions

View File

@@ -1295,6 +1295,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
// We have to create a new auth method instance because the original object must
// not be modified.
CodegenSecurity opSecurity = security.filterByScopeNames(opScopes);
opSecurity.hasMore = security.hasMore;
result.add(opSecurity);
filtered = true;
break;

View File

@@ -491,6 +491,26 @@ public class JavaClientCodegenTest {
assertEquals(postScopes.size(), 2, "POST scopes don't match. actual:" + postScopes);
}
@Test
public void testAuthorizationsHasMoreWhenFiltered() {
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue4584.yaml");
final DefaultGenerator defaultGenerator = new DefaultGenerator();
final ClientOptInput clientOptInput = new ClientOptInput();
clientOptInput.setOpenAPI(openAPI);
clientOptInput.setConfig(new JavaClientCodegen());
defaultGenerator.opts(clientOptInput);
final List<CodegenOperation> codegenOperations = defaultGenerator.processPaths(openAPI.getPaths()).get("Pet");
final CodegenOperation getCodegenOperation = codegenOperations.stream().filter(it -> it.httpMethod.equals("GET")).collect(Collectors.toList()).get(0);
assertTrue(getCodegenOperation.hasAuthMethods);
assertEquals(getCodegenOperation.authMethods.size(), 2);
assertTrue(getCodegenOperation.authMethods.get(0).hasMore);
Assert.assertFalse(getCodegenOperation.authMethods.get(1).hasMore);
}
@Test
public void testFreeFormObjects() {
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue796.yaml");

View File

@@ -0,0 +1,110 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
info:
description: Used for verification of AuthorizationScope resolution issue
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
- petstore_beta_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
'/pet/{petId}':
get:
tags:
- pet
summary: Find pet by ID
description: Returns a single pet
operationId: getPetById
parameters:
- name: petId
in: path
description: ID of pet to return
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
security:
- petstore_auth:
- 'read:pets'
- petstore_beta_auth:
- 'read:pets'
components:
securitySchemes:
petstore_auth:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://petstore.swagger.io/oauth2/auth
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
tokenUrl: https://petstore.swagger.io/oauth2/token
petstore_beta_auth:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://petstore.beta.swagger.io/oauth2/auth
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
tokenUrl: https://petstore.beta.swagger.io/oauth2/token
schemas:
Pet:
title: a Pet
description: A pet for sale in the pet store
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
name:
type: string
example: doggie
photoUrls:
type: array
items:
type: string
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold