Skip to content

Commit

Permalink
Issue 61 supporting priority for the included api
Browse files Browse the repository at this point in the history
  • Loading branch information
conorroche committed Mar 23, 2015
1 parent bbf224d commit e9ea943
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@SuppressWarnings("javadoc")
Expand Down Expand Up @@ -114,6 +115,7 @@ public String getDescription() {
* This sets the priority
* @param priority the priority to set
*/
@JsonProperty
public void setPriority(int priority) {
this.priority = priority;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Collection<ApiDeclaration> merge(Collection<ApiDeclaration> declarations)
String apiVersion = getFirstNonNull(this.apiVersion, declaration.getApiVersion());
String swaggerVersion = getFirstNonNull(this.swaggerVersion, declaration.getSwaggerVersion());
String basePath = getFirstNonNull(this.basePath, declaration.getBasePath());
Integer priority = getFirstNonNull(0, declaration.getPriority());
int priority = getFirstNonNullNorVal(Integer.MAX_VALUE, Integer.MAX_VALUE, declaration.getPriority());

ApiDeclaration newApi = new ApiDeclaration(swaggerVersion, apiVersion, basePath, resourcePath, declaration.getApis(), declaration.getModels(),
priority, declaration.getDescription());
Expand All @@ -69,7 +69,7 @@ public Collection<ApiDeclaration> merge(Collection<ApiDeclaration> declarations)
String apiVersion = getFirstNonNull(this.apiVersion, existing.getApiVersion(), declaration.getApiVersion());
String swaggerVersion = getFirstNonNull(this.swaggerVersion, existing.getSwaggerVersion(), declaration.getSwaggerVersion());
String basePath = getFirstNonNull(this.basePath, existing.getBasePath(), declaration.getBasePath());
Integer priority = getFirstNonNull(0, existing.getPriority(), declaration.getPriority());
int priority = getFirstNonNullNorVal(Integer.MAX_VALUE, Integer.MAX_VALUE, existing.getPriority(), declaration.getPriority());
String description = getFirstNonNull(null, existing.getDescription(), declaration.getDescription());

List<Api> apis = existing.getApis();
Expand Down Expand Up @@ -143,4 +143,13 @@ private <T> T getFirstNonNull(T defaultValue, T... vals) {
return defaultValue;
}

private <T> T getFirstNonNullNorVal(T defaultValue, T excludeVal, T... vals) {
for (T val : vals) {
if (val != null && !val.equals(excludeVal)) {
return val;
}
}
return defaultValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public ApiMethodParser(DocletOptions options, String parentPath, MethodDoc metho
* @param parentMethod
* @param methodDoc
* @param classes
* @param typeClasses
* @param classDefaultErrorType
*/
public ApiMethodParser(DocletOptions options, Method parentMethod, MethodDoc methodDoc, Collection<ClassDoc> classes, Collection<ClassDoc> typeClasses,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class IncludeApiDeclarationsTest {
public void setup() throws IOException {
this.recorderMock = mock(Recorder.class);
this.options = new DocletOptions().setRecorder(this.recorderMock).setIncludeSwaggerUi(false);
this.options.setSortResourcesByPriority(true);

final ApiDeclaration api1 = loadFixture("/fixtures/includeapideclarations/includedeclaration1.json", ApiDeclaration.class);
final ApiDeclaration api2 = loadFixture("/fixtures/includeapideclarations/includedeclaration2.json", ApiDeclaration.class);
Expand All @@ -55,6 +56,7 @@ public void testStart() throws IOException {
verify(this.recorderMock).record(any(File.class), eq(expectedDeclaration1));

final ApiDeclaration expectedDeclaration2 = loadFixture("/fixtures/includeapideclarations/foo3.json", ApiDeclaration.class);
expectedDeclaration2.setPriority(5);
verify(this.recorderMock).record(any(File.class), eq(expectedDeclaration2));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"priority" : 5,
"resourcePath": "/foo3",
"apis": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"swaggerVersion": "1.2",
"apis": [
{
"path": "/foo.{format}"
},
{
"path": "/foo3.{format}"
},
{
"path": "/foo.{format}"
}
]
}

0 comments on commit e9ea943

Please sign in to comment.