Skip to content

Commit

Permalink
OperationPaths key changed, the @path annotation define that key, sec…
Browse files Browse the repository at this point in the history
…urityTests initiation, improvements
  • Loading branch information
Rafael Lopez committed Jun 19, 2017
1 parent be67960 commit 2e4203f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.jaxrs2;

import com.fasterxml.jackson.databind.util.JSONPObject;
import io.swagger.converter.ModelConverters;
import io.swagger.oas.annotations.media.ExampleObject;
import io.swagger.oas.models.ExternalDocumentation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public OpenAPI read(Class<?> cls, String parentPath) {

Operation operation = parseMethod(method);
PathItem pathItemObject = new PathItem();
pathItemObject.set$ref(operationPath);
if (StringUtils.isNotBlank(operation.getSummary())) {
pathItemObject.setSummary(operation.getSummary());
}
Expand Down Expand Up @@ -195,7 +194,7 @@ public OpenAPI read(Class<?> cls, String parentPath) {
}
operation.setParameters(operationParameters);

paths.addPathItem(pathItemObject.get$ref(), pathItemObject);
paths.addPathItem(operationPath, pathItemObject);
if (openAPI.getPaths() != null) {
this.paths.putAll(openAPI.getPaths());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

public abstract class AbstractAnnotationTest {
public String readIntoYaml(Class<?> cls) {
// TODO: we will scan the ClassWithTitle and write as YAML but for now, stubbing it out to show the
Reader reader = new Reader(new OpenAPI(), null);
OpenAPI openAPI = reader.read(cls);

Expand All @@ -18,12 +17,10 @@ public String readIntoYaml(Class<?> cls) {
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
// parse JSON
JsonNode jsonNodeTree = objectMapper.readTree(objectMapper.writeValueAsString(openAPI));
// save it as YAML
// return it as YAML
return new YAMLMapper().writeValueAsString(jsonNodeTree);
} catch (Exception e) {
e.printStackTrace();
return "";
}

return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static class SimpleGetOperationTest {
}
)
@GET
@Path("/")
@Path("/path")
public void simpleGet() {
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ static class GetOperationWithResponsePayloadAndAlternateCodes {
)
}
)
@Path("/")
@Path("/path")
@GET
public void simpleGet() {
}
Expand Down Expand Up @@ -205,7 +205,7 @@ static class GetOperationWithResponseExamples {
}
)
@GET
@Path("/")
@Path("/path")
public void simpleGet() {
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,76 @@
package io.swagger.jaxrs2.annotations.security;

import io.swagger.jaxrs2.annotations.AbstractAnnotationTest;
import io.swagger.jaxrs2.annotations.info.InfoTest;
import io.swagger.oas.annotations.security.OAuthFlow;
import io.swagger.oas.annotations.security.OAuthFlows;
import io.swagger.oas.annotations.security.Scopes;
import io.swagger.oas.annotations.security.SecurityRequirement;
import io.swagger.oas.annotations.security.SecurityScheme;
import org.testng.annotations.Test;

public class SecurityTests {
import static org.testng.Assert.assertEquals;

public class SecurityTests extends AbstractAnnotationTest {
@Test
public void testSecuritySheme() {
String openApiYAML = readIntoYaml(SecurityTests.OAuth2SchemeOnClass.class);
int start = openApiYAML.indexOf("components:");
String extractedYAML = openApiYAML.substring(start, openApiYAML.length() - 1);
String expectedYAML = "components:\n" +
" securitySchemes:\n" +
" myOauth2Security:\n" +
" name: \"myOauth2Security\"\n" +
" flows:\n" +
" implicit:\n" +
" authorizationUrl: \"http://url.com/auth\"\n" +
" scopes:\n" +
" name: \"write:pets\"\n" +
" description: \"modify pets in your account\"\n" +
" password:\n" +
" scopes:\n" +
" name: \"\"\n" +
" description: \"\"\n" +
" clientCredentials:\n" +
" scopes:\n" +
" name: \"\"\n" +
" description: \"\"\n" +
" authorizationCode:\n" +
" scopes:\n" +
" name: \"\"\n" +
" description: \"\"";
assertEquals(extractedYAML, expectedYAML);

}

@Test(enabled = false)
public void testSecurityRequirement() {
String openApiYAML = readIntoYaml(SecurityTests.SecurityRequirementOnClass.class);
int start = openApiYAML.indexOf("components:");
String extractedYAML = openApiYAML.substring(start, openApiYAML.length() - 1);
String expectedYAML = "components:\n" +
" securitySchemes:\n" +
" myOauth2Security:\n" +
" name: \"myOauth2Security\"\n" +
" flows:\n" +
" implicit:\n" +
" authorizationUrl: \"http://url.com/auth\"\n" +
" scopes:\n" +
" name: \"write:pets\"\n" +
" description: \"modify pets in your account\"\n" +
" password:\n" +
" scopes:\n" +
" name: \"\"\n" +
" description: \"\"\n" +
" clientCredentials:\n" +
" scopes:\n" +
" name: \"\"\n" +
" description: \"\"\n" +
" authorizationCode:\n" +
" scopes:\n" +
" name: \"\"\n" +
" description: \"\"";
assertEquals(openApiYAML, expectedYAML);

}

Expand All @@ -26,7 +87,9 @@ static class ApiKeySchemeOnClass {
@SecurityScheme(name = "myOauth2Security",
type = "oauth2",
in = "header",
flows = @OAuthFlows(implicit = @OAuthFlow(authorizationUrl = "", scopes = @Scopes(name = "write:pets", description = "modify pets in your account"))))
flows = @OAuthFlows(
implicit = @OAuthFlow(authorizationUrl = "http://url.com/auth",
scopes = @Scopes(name = "write:pets", description = "modify pets in your account"))))
static class OAuth2SchemeOnClass {

}
Expand Down

0 comments on commit 2e4203f

Please sign in to comment.