Skip to content

Commit

Permalink
Fix #1258 - Serialize/deserialize security in "security" instead of "…
Browse files Browse the repository at this point in the history
…securityRequierement" to be spec compliant
  • Loading branch information
boillodmanuel committed May 8, 2016
1 parent d98de9c commit a024462
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
Expand Up @@ -51,7 +51,7 @@ private void assertIsRefResponse(Response response, String expectedRef) {
}

@Test
public void testDeserializeSecurityRequirement() throws Exception {
public void testDeserializeSecurity() throws Exception {
final Swagger swagger = TestUtils.deserializeJsonFileFromClasspath("specFiles/securityDefinitions.json", Swagger.class);

final List<SecurityRequirement> security = swagger.getSecurity();
Expand Down
Expand Up @@ -64,6 +64,6 @@ public void testSerializeSecurityRequirement_UsingSpecCompliantMethods() throws
.security(new SecurityRequirement().requirement("api_key").requirement("basic_auth"))
.security(new SecurityRequirement().requirement("oauth2", Arrays.asList("hello", "world")));
json = Json.mapper().writeValueAsString(swagger);
assertEquals(json, "{\"swagger\":\"2.0\",\"securityRequirement\":[{\"basic_auth\":[],\"api_key\":[]},{\"oauth2\":[\"hello\",\"world\"]}]}");
assertEquals(json, "{\"swagger\":\"2.0\",\"security\":[{\"basic_auth\":[],\"api_key\":[]},{\"oauth2\":[\"hello\",\"world\"]}]}");
}
}
@@ -1,6 +1,6 @@
{
"swagger" : "2.0",
"securityRequirement" : [ {
"security" : [ {
"basic_auth" : [ ],
"api_key" : [ ]
}, {
Expand Down
Expand Up @@ -298,27 +298,37 @@ public void addSecurityDefinition(String name, SecuritySchemeDefinition security
this.securityDefinitions.put(name, securityDefinition);
}

/**
* @deprecated Use {@link #getSecurity()}.
*/
@JsonIgnore
@Deprecated
public List<SecurityRequirement> getSecurityRequirement() {
return security;
}

/**
* @deprecated Use {@link #setSecurity(List)}.
*/
@JsonIgnore
@Deprecated
public void setSecurityRequirement(List<SecurityRequirement> securityRequirements) {
this.security = securityRequirements;
}

/**
* @deprecated Use {@link #addSecurity(SecurityRequirement)}.
*/
@JsonIgnore
@Deprecated
public void addSecurityDefinition(SecurityRequirement securityRequirement) {
this.addSecurity(securityRequirement);
}

@JsonIgnore //remove JsonIgnore when getSecurityRequirement() method is deleted in next major version
public List<SecurityRequirement> getSecurity() {
return security;
}

@JsonIgnore //remove JsonIgnore when setSecurityRequirement() method is deleted in next major version
public void setSecurity(List<SecurityRequirement> securityRequirements) {
this.security = securityRequirements;
}
Expand Down
Expand Up @@ -82,7 +82,7 @@ public void testSetSecurityRequirement() {
swagger.setSecurityRequirement(new ArrayList<SecurityRequirement>(Arrays.asList(requirement)));

// then
assertTrue(swagger.getSecurityRequirement().contains(requirement),
assertTrue(swagger.getSecurity().contains(requirement),
"The newly added requiement must be contained in the requiement list");
}

Expand All @@ -92,7 +92,7 @@ public void testAddSecurityDefinition() {
swagger.addSecurityDefinition(requirement);

// then
assertTrue(swagger.getSecurityRequirement().contains(requirement),
assertTrue(swagger.getSecurity().contains(requirement),
"The newly added requiement must be contained in the requiement list");
}

Expand Down

0 comments on commit a024462

Please sign in to comment.