diff --git a/modules/swagger-core/src/main/java/io/swagger/v3/core/converter/ModelConverters.java b/modules/swagger-core/src/main/java/io/swagger/v3/core/converter/ModelConverters.java index 5f6008648a..0bb9c21f02 100644 --- a/modules/swagger-core/src/main/java/io/swagger/v3/core/converter/ModelConverters.java +++ b/modules/swagger-core/src/main/java/io/swagger/v3/core/converter/ModelConverters.java @@ -42,6 +42,10 @@ public ModelConverters(boolean openapi31) { } } + public Set getSkippedPackages() { + return skippedPackages; + } + public static ModelConverters getInstance(boolean openapi31) { if (openapi31) { if (SINGLETON31 == null) { @@ -58,7 +62,8 @@ public static ModelConverters getInstance(boolean openapi31) { } private static void init(ModelConverters converter) { - converter.skippedPackages.add("java.lang"); + converter.addPackageToSkip("java.lang"); + converter.addPackageToSkip("groovy.lang"); ServiceLoader loader = ServiceLoader.load(ModelConverter.class); Iterator itr = loader.iterator(); diff --git a/modules/swagger-core/src/test/java/io/swagger/v3/core/converting/ModelConverterTest.java b/modules/swagger-core/src/test/java/io/swagger/v3/core/converting/ModelConverterTest.java index aa6f886519..13a0fa1220 100644 --- a/modules/swagger-core/src/test/java/io/swagger/v3/core/converting/ModelConverterTest.java +++ b/modules/swagger-core/src/test/java/io/swagger/v3/core/converting/ModelConverterTest.java @@ -383,6 +383,23 @@ public void indirectPropertiesRecognized() { assertEquals(model.getProperties().size(), 1); } + @Test + public void checkDefaultSkippedPackages(){ + ModelConverters modelConverters = ModelConverters.getInstance(); + + assertTrue(modelConverters.getSkippedPackages().contains("java.lang")); + assertTrue(modelConverters.getSkippedPackages().contains("groovy.lang")); + } + + @Test(description = "It should not process skipped package") + public void ignoreSkippedPackage() throws ClassNotFoundException { + ModelConverters modelConverters = ModelConverters.getInstance(); + final Type type = Class.forName("java.lang.String"); + assertNull(modelConverters.readAllAsResolvedSchema(type)); + + + } + @JsonSerialize(as = AnnotatedImplementationClass.class) abstract class BaseClass { public abstract String field(); @@ -406,6 +423,7 @@ public void directPropertiesRecognized() { assertEquals(model.getProperties().size(), 1); } + abstract class AnnotatedBaseClass { @JsonProperty public abstract String field();