Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,10 @@ public static Optional<? extends Schema> getSchema(io.swagger.v3.oas.annotations
schemaMap.forEach((key, schema) -> {
components.addSchemas(key, schema);
});
if (resolvedSchema.schema != null) {
if (resolvedSchema.schema != null && StringUtils.isNotBlank(resolvedSchema.schema.getName())) {
schemaObject.set$ref(COMPONENTS_REF + resolvedSchema.schema.getName());
} else if (resolvedSchema.schema != null){
schemaObject = resolvedSchema.schema;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ public Schema createProperty() {
*/
private static final Map<String, PrimitiveType> EXTERNAL_CLASSES;

/**
* Allows to exclude specific classes from KEY_CLASSES mappings to primitive
* Joda lib.
*/
private static Set<String> customExcludedClasses = new ConcurrentHashMap<String, String>().newKeySet();

/**
* Adds support for custom mapping of classes to primitive types
*/
Expand Down Expand Up @@ -263,6 +269,17 @@ private PrimitiveType(Class<?> keyClass, String commonName) {
this.commonName = commonName;
}


/**
* Adds support for custom mapping of classes to primitive types
*
* @return Map of custom classes to primitive type
* @since 2.0.6
*/
public static Set<String> customExcludedClasses() {
return customExcludedClasses;
}

/**
* Adds support for custom mapping of classes to primitive types
*
Expand Down Expand Up @@ -307,7 +324,9 @@ public static PrimitiveType fromType(Type type) {
final Class<?> raw = TypeFactory.defaultInstance().constructType(type).getRawClass();
final PrimitiveType key = KEY_CLASSES.get(raw);
if (key != null) {
return key;
if (!customExcludedClasses.contains(raw.getName())) {
return key;
}
}

final PrimitiveType custom = customClasses.get(raw.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.swagger.v3.core.filter.SpecFilter;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.core.model.ApiDescription;
import io.swagger.v3.core.util.PrimitiveType;
import io.swagger.v3.jaxrs2.matchers.SerializationMatchers;
import io.swagger.v3.jaxrs2.resources.BasicFieldsResource;
import io.swagger.v3.jaxrs2.resources.BookStoreTicket2646;
Expand Down Expand Up @@ -53,6 +54,7 @@
import io.swagger.v3.jaxrs2.resources.Ticket2806Resource;
import io.swagger.v3.jaxrs2.resources.Ticket2818Resource;
import io.swagger.v3.jaxrs2.resources.Ticket2848Resource;
import io.swagger.v3.jaxrs2.resources.Ticket3015Resource;
import io.swagger.v3.jaxrs2.resources.UserAnnotationResource;
import io.swagger.v3.jaxrs2.resources.extensions.ExtensionsResource;
import io.swagger.v3.jaxrs2.resources.extensions.OperationExtensionsResource;
Expand Down Expand Up @@ -93,6 +95,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -1829,4 +1832,86 @@ public void testCallbackWithRef() {
" description: Post Path Item\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}

@Test
public void testTicket3015() {
Reader reader = new Reader(new OpenAPI());

OpenAPI openAPI = reader.read(Ticket3015Resource.class);
String yaml = "openapi: 3.0.1\n" +
"paths:\n" +
" /test/test:\n" +
" get:\n" +
" operationId: schemaImpl\n" +
" responses:\n" +
" 200:\n" +
" description: OK\n" +
" content:\n" +
" '*/*':\n" +
" schema:\n" +
" type: string\n" +
" format: uri\n" +
" 400:\n" +
" description: Bad Request\n" +
" 500:\n" +
" description: Internal Server Error\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
PrimitiveType.customExcludedClasses().add(URI.class.getName());
openAPI = reader.read(Ticket3015Resource.class);
yaml = "openapi: 3.0.1\n" +
"paths:\n" +
" /test/test:\n" +
" get:\n" +
" operationId: schemaImpl_1\n" +
" responses:\n" +
" 200:\n" +
" description: OK\n" +
" content:\n" +
" '*/*':\n" +
" schema:\n" +
" type: object\n" +
" properties:\n" +
" scheme:\n" +
" type: string\n" +
" fragment:\n" +
" type: string\n" +
" authority:\n" +
" type: string\n" +
" userInfo:\n" +
" type: string\n" +
" host:\n" +
" type: string\n" +
" port:\n" +
" type: integer\n" +
" format: int32\n" +
" path:\n" +
" type: string\n" +
" query:\n" +
" type: string\n" +
" schemeSpecificPart:\n" +
" type: string\n" +
" rawSchemeSpecificPart:\n" +
" type: string\n" +
" rawAuthority:\n" +
" type: string\n" +
" rawUserInfo:\n" +
" type: string\n" +
" rawPath:\n" +
" type: string\n" +
" rawQuery:\n" +
" type: string\n" +
" rawFragment:\n" +
" type: string\n" +
" absolute:\n" +
" type: boolean\n" +
" opaque:\n" +
" type: boolean\n" +
" 400:\n" +
" description: Bad Request\n" +
" 500:\n" +
" description: Internal Server Error\n";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
PrimitiveType.customExcludedClasses().remove(URI.class.getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.swagger.v3.jaxrs2.resources;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.net.URI;

@Path("test")
public class Ticket3015Resource {

@Operation(responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = URI.class))),
@ApiResponse(responseCode = "400", description = "Bad Request"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")
})
@GET
@Path("/test")
public void schemaImpl() {
}
}