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

Maintains state of hasMore when security is filtered #4585

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ private List<CodegenSecurity> filterAuthMethods(List<CodegenSecurity> authMethod
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,26 @@ public void testAuthorizationScopeValues_Issue392() {
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");
Expand Down
110 changes: 110 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue4584.yaml
Original file line number Diff line number Diff line change
@@ -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