Skip to content

Commit

Permalink
Merge pull request #1769 from eliyahus/master
Browse files Browse the repository at this point in the history
fix for issue 1767 - OpenAPI v2 converter
  • Loading branch information
gracekarina authored Jul 16, 2022
2 parents 065fa61 + 06b60b8 commit 0b2dfac
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ public Operation convert(io.swagger.models.Operation v2Operation) {
operation.setExternalDocs(convert(v2Operation.getExternalDocs()));
}

if (v2Operation.getSecurity() != null && v2Operation.getSecurity().size() > 0) {
if (v2Operation.getSecurity() != null) {
operation.setSecurity(convertSecurityRequirementsMap(v2Operation.getSecurity()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.security.OAuthFlow;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.tags.Tag;
import io.swagger.v3.parser.converter.SwaggerConverter;
Expand Down Expand Up @@ -99,6 +100,8 @@ public class V2ConverterTest {

private static final String ISSUE_1715_YAML = "issue-1715.yaml";

private static final String ISSUE_1767_YAML = "issue-1767.yaml";

private static final String API_BATCH_PATH = "/api/batch/";
private static final String PETS_PATH = "/pets";
private static final String PET_FIND_BY_STATUS_PATH = "/pet/findByStatus";
Expand Down Expand Up @@ -864,6 +867,21 @@ public void testissue1715() throws Exception {
assertEquals("bar", requestBody.getExtensions().get("x-foo"));
}

@Test(description = "OpenAPI v2 converter - security of operation should be set to empty list if that's the case")
public void testIssue1767() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1767_YAML);
assertNotNull(oas);

List<SecurityRequirement> firstOperationSecurityRequirements =
oas.getPaths().get("/api/not-secured").getGet().getSecurity();
assertNotNull(firstOperationSecurityRequirements);
assertEquals(firstOperationSecurityRequirements.size(), 0);

List<SecurityRequirement> secondOperationSecurityRequirements =
oas.getPaths().get("/api/secured/").getGet().getSecurity();
assertNull(secondOperationSecurityRequirements);
}

@Test()
public void testInlineDefinitionProperty() throws Exception {
SwaggerConverter converter = new SwaggerConverter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
swagger: '2.0'
basePath: /
paths:
/api/not-secured:
get:
responses:
'200':
description: Success
summary: Not secured API
operationId: not_secured_api
security: []
tags:
- not-secured
/api/secured/:
get:
responses:
'200':
description: Success
summary: Secured API
operationId: secured_api
tags:
- secured
info:
title: Sample spec
version: 0.1.0
produces:
- application/json
consumes:
- application/json
securityDefinitions:
api_key:
type: apiKey
in: header
name: Authorization
security:
- api_key: []
tags:
- name: not-secured
description: API not secured
- name: secured
description: API secured

0 comments on commit 0b2dfac

Please sign in to comment.