Skip to content
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 @@ -297,25 +297,28 @@ private SecurityScheme convertOauth2SecurityScheme(SecuritySchemeDefinition defi
OAuthFlow oAuthFlow = new OAuthFlow();

securityScheme.setType(SecurityScheme.Type.OAUTH2);

switch (oAuth2Definition.getFlow()) {
case "implicit":
oAuthFlow.setAuthorizationUrl(oAuth2Definition.getAuthorizationUrl());
oAuthFlows.setImplicit(oAuthFlow);
break;
case "password":
oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
oAuthFlows.setPassword(oAuthFlow);
break;
case "application":
oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
oAuthFlows.setClientCredentials(oAuthFlow);
break;
case "accessCode":
oAuthFlow.setAuthorizationUrl(oAuth2Definition.getAuthorizationUrl());
oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
oAuthFlows.setAuthorizationCode(oAuthFlow);
break;
String flow = oAuth2Definition.getFlow();

if (flow != null) {
switch (flow) {
case "implicit":
oAuthFlow.setAuthorizationUrl(oAuth2Definition.getAuthorizationUrl());
oAuthFlows.setImplicit(oAuthFlow);
break;
case "password":
oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
oAuthFlows.setPassword(oAuthFlow);
break;
case "application":
oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
oAuthFlows.setClientCredentials(oAuthFlow);
break;
case "accessCode":
oAuthFlow.setAuthorizationUrl(oAuth2Definition.getAuthorizationUrl());
oAuthFlow.setTokenUrl(oAuth2Definition.getTokenUrl());
oAuthFlows.setAuthorizationCode(oAuthFlow);
break;
}
}

Scopes scopes = new Scopes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class V2ConverterTest {
private static final String ISSUE_758_JSON = "issue-758.json";
private static final String ISSUE_762_JSON = "issue-762.json";
private static final String ISSUE_765_YAML = "issue-765.yaml";
private static final String ISSUE_768_JSON = "issue-786.json";

private static final String API_BATCH_PATH = "/api/batch/";
private static final String PETS_PATH = "/pets";
Expand Down Expand Up @@ -692,6 +693,12 @@ public void testSwaggerParseResultHasMessage() throws Exception {
assertNotNull(result.getMessages());
}

@Test(description = "OpenAPI v2 converter - Migrate minLength, maxLength and pattern of String property")
public void testIssue786() throws Exception {
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_768_JSON);
assertNotNull(oas);
}

private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException {
SwaggerConverter converter = new SwaggerConverter();
String swaggerAsString = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(file).toURI())));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"swagger": "2.0",
"host" : "localhost",
"info": {
"version": "1.0.9-abcd",
"title": "Swagger Sample API Security Example",
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "Swagger API Team",
"url": "http://swagger.io"
},
"license": {
"name": "Creative Commons 4.0 International",
"url": "http://creativecommons.org/licenses/by/4.0/"
}
},
"basePath": "/v1",
"schemes": [
"http",
"https"
],
"securityDefinitions": {
"petstoreImplicit": {
"type": "oauth2",
"scopes": {
"user": "Grants read/write access to profile info only. Note that this scope includes user:email and user:follow."
},
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog"
}
}
}