Skip to content

Commit df7c847

Browse files
author
Ole Lensmar
committed
fixed so SwaggerDefinitions are scanned before resources to get tags defined in correct order
1 parent 42056f2 commit df7c847

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.fasterxml.jackson.databind.JavaType;
2020
import com.fasterxml.jackson.databind.type.TypeFactory;
2121
import com.google.common.collect.Collections2;
22-
2322
import io.swagger.annotations.Api;
2423
import io.swagger.annotations.ApiImplicitParam;
2524
import io.swagger.annotations.ApiImplicitParams;
@@ -62,7 +61,6 @@
6261
import io.swagger.models.properties.MapProperty;
6362
import io.swagger.models.properties.Property;
6463
import io.swagger.models.properties.RefProperty;
65-
6664
import org.apache.commons.lang3.StringUtils;
6765
import org.slf4j.Logger;
6866
import org.slf4j.LoggerFactory;
@@ -73,7 +71,6 @@
7371
import javax.ws.rs.PathParam;
7472
import javax.ws.rs.Produces;
7573
import javax.ws.rs.QueryParam;
76-
7774
import java.lang.annotation.Annotation;
7875
import java.lang.reflect.Constructor;
7976
import java.lang.reflect.Field;
@@ -144,6 +141,14 @@ public Swagger read(Set<Class<?>> classes) {
144141
}
145142
}
146143

144+
// process SwaggerDefinitions first - so we get tags in desired order
145+
for (Class<?> cls : classes) {
146+
SwaggerDefinition swaggerDefinition = cls.getAnnotation(SwaggerDefinition.class);
147+
if (swaggerDefinition != null) {
148+
readSwaggerConfig(cls, swaggerDefinition);
149+
}
150+
}
151+
147152
for (Class<?> cls : classes) {
148153
read(cls);
149154
}
@@ -172,11 +177,6 @@ public Swagger read(Class<?> cls) {
172177
}
173178

174179
protected Swagger read(Class<?> cls, String parentPath, String parentMethod, boolean readHidden, String[] parentConsumes, String[] parentProduces, Map<String, Tag> parentTags, List<Parameter> parentParameters) {
175-
SwaggerDefinition swaggerDefinition = cls.getAnnotation(SwaggerDefinition.class);
176-
if (swaggerDefinition != null) {
177-
readSwaggerConfig(cls, swaggerDefinition);
178-
}
179-
180180
Api api = (Api) cls.getAnnotation(Api.class);
181181
Map<String, SecurityScope> globalScopes = new HashMap<String, SecurityScope>();
182182

modules/swagger-jaxrs/src/test/scala/ConfigAndExtensionScannerTest.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ConfigAndExtensionScannerTest extends FlatSpec with Matchers {
4444
swagger.getSchemes().contains(Scheme.HTTP);
4545
swagger.getSchemes().contains(Scheme.HTTPS);
4646

47-
swagger.getTags().size() should be(6)
47+
swagger.getTags().size() should be(7)
4848
swagger.getTags().get(0).getName() should be("Tag-added-before-read")
4949

5050
swagger.getTags().get(1).getName() should be("mytag")
@@ -62,7 +62,8 @@ class ConfigAndExtensionScannerTest extends FlatSpec with Matchers {
6262
extensions.get("x-test") should be("value")
6363

6464
swagger.getTags().get(4).getName() should be("externalinfo")
65-
swagger.getTags().get(5).getName() should be("Tag-added-after-read")
65+
swagger.getTags().get(5).getName() should be("testingtag")
66+
swagger.getTags().get(6).getName() should be("Tag-added-after-read")
6667

6768
extensions = swagger.getInfo().getVendorExtensions()
6869
extensions.size() should be(3)

modules/swagger-jaxrs/src/test/scala/resources/ResourceWithConfigAndExtensions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
@Api(value = "/external/info/")
5353
@Path("who/cares")
5454
public class ResourceWithConfigAndExtensions implements ReaderListener {
55-
@ApiOperation(value = "test.", extensions = {
55+
@ApiOperation(value = "test.", tags = {"tagwithextensions", "mytag", "testingtag"}, extensions = {
5656
@Extension(properties = @ExtensionProperty(name = "test", value = "value"))
5757
})
5858
@GET

0 commit comments

Comments
 (0)