Skip to content
Open
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 @@ -330,6 +330,10 @@ private void addSchemaRef(Schema schema, Set<String> referencedDefinitions) {
}
}

if (schema.getPropertyNames() != null) {
addSchemaRef(schema.getPropertyNames(), referencedDefinitions);
}

if (schema instanceof ArraySchema &&
((ArraySchema) schema).getItems() != null) {
addSchemaRef(((ArraySchema) schema).getItems(), referencedDefinitions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import io.swagger.v3.jaxrs2.resources.Ticket4859Resource;
import io.swagger.v3.jaxrs2.resources.Ticket4878Resource;
import io.swagger.v3.jaxrs2.resources.Ticket4879Resource;
import io.swagger.v3.jaxrs2.resources.Ticket5017Resource;
import io.swagger.v3.jaxrs2.resources.UploadResource;
import io.swagger.v3.jaxrs2.resources.UrlEncodedResourceWithEncodings;
import io.swagger.v3.jaxrs2.resources.UserAnnotationResource;
Expand Down Expand Up @@ -5503,4 +5504,61 @@ public void testTicket4907() {
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
ModelConverters.reset();
}

@Test
void testTicket5017() {
ModelResolver.enumsAsRef = true;
SwaggerConfiguration config = new SwaggerConfiguration().openAPI31(true);
Reader reader = new Reader(config);
OpenAPI openAPI = reader.read(Ticket5017Resource.class);

OpenAPISpecFilter filterImpl = new RemoveUnusedSchemasOAS31Filter();
SpecFilter f = new SpecFilter();
openAPI = f.filter(openAPI, filterImpl, null, null, null);

String yaml = "openapi: 3.1.0\n" +
"paths:\n" +
" /test:\n" +
" get:\n" +
" operationId: myMethod\n" +
" requestBody:\n" +
" content:\n" +
" '*/*':\n" +
" schema:\n" +
" $ref: \"#/components/schemas/Example\"\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
"components:\n" +
" schemas:\n" +
" Example:\n" +
" type: object\n" +
" properties:\n" +
" myMap:\n" +
" type: object\n" +
" additionalProperties:\n" +
" type: string\n" +
" propertyNames:\n" +
" $ref: \"#/components/schemas/MyEnum\"\n" +
" MyEnum:\n" +
" type: string\n" +
" enum:\n" +
" - FOO\n" +
" - BAR\n";
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
}

static class RemoveUnusedSchemasOAS31Filter extends AbstractSpecFilter {
@Override
public boolean isRemovingUnreferencedDefinitions() {
return true;
}

@Override
public boolean isOpenAPI31Filter() {
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.swagger.v3.jaxrs2.resources;

import io.swagger.v3.oas.annotations.media.Schema;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.util.Map;

@Path("/test")
public class Ticket5017Resource {
@GET
public void myMethod(Example request) {}

public static class Example {
@Schema(propertyNames = MyEnum.class)
private Map<MyEnum, String> myMap;

public Map<MyEnum, String> getMyMap() {
return myMap;
}

public void setMyMap(Map<MyEnum, String> myMap) {
this.myMap = myMap;
}
}

public enum MyEnum {
FOO, BAR
}
}