Skip to content

Commit

Permalink
Merge branch 'master' into bug/4817-add-patternproperties-support-in-…
Browse files Browse the repository at this point in the history
…spec-filter
  • Loading branch information
Opharion authored Jan 16, 2025
2 parents c6e6403 + 3e9db3c commit 1e7f7d0
Show file tree
Hide file tree
Showing 96 changed files with 806 additions and 587 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
if (reResolvedProperty.isPresent()) {
property = reResolvedProperty.get();
}
reResolvedProperty = AnnotationsUtils.getArraySchema(ctxArraySchema, annotatedType.getComponents(), null, openapi31, property);
reResolvedProperty = AnnotationsUtils.getArraySchema(ctxArraySchema, annotatedType.getComponents(), null, openapi31, property, true);
if (reResolvedProperty.isPresent()) {
property = reResolvedProperty.get();
}
Expand Down Expand Up @@ -2701,6 +2701,19 @@ protected void resolveSchemaMembers(Schema schema, AnnotatedType annotatedType,
Annotated a = beanDesc.getClassInfo();
Annotation[] annotations = annotatedType.getCtxAnnotations();
resolveSchemaMembers(schema, a, annotations, schemaAnnotation);
if (schemaAnnotation != null) {
if (schemaAnnotation.additionalProperties().equals(io.swagger.v3.oas.annotations.media.Schema.AdditionalPropertiesValue.TRUE)) {
schema.additionalProperties(true);
} else if (schemaAnnotation.additionalProperties().equals(io.swagger.v3.oas.annotations.media.Schema.AdditionalPropertiesValue.FALSE)) {
schema.additionalProperties(false);
} else {
if (!schemaAnnotation.additionalPropertiesSchema().equals(Void.class)) {
Schema additionalPropertiesSchema = resolve(new AnnotatedType(schemaAnnotation.additionalPropertiesSchema()), context, next);
additionalPropertiesSchema = buildRefSchemaIfObject(additionalPropertiesSchema, context);
schema.additionalProperties(additionalPropertiesSchema);
}
}
}

if (openapi31 && schema != null && schemaAnnotation != null) {
if (!Void.class.equals(schemaAnnotation.contentSchema())) {
Expand Down Expand Up @@ -2734,18 +2747,6 @@ protected void resolveSchemaMembers(Schema schema, AnnotatedType annotatedType,
schema.setUnevaluatedProperties(unevaluatedProperties);
}

if (schemaAnnotation.additionalProperties().equals(io.swagger.v3.oas.annotations.media.Schema.AdditionalPropertiesValue.TRUE)) {
schema.additionalProperties(true);
} else if (schemaAnnotation.additionalProperties().equals(io.swagger.v3.oas.annotations.media.Schema.AdditionalPropertiesValue.FALSE)) {
schema.additionalProperties(false);
} else {
if (!schemaAnnotation.additionalPropertiesSchema().equals(Void.class)) {
Schema additionalPropertiesSchema = resolve(new AnnotatedType(schemaAnnotation.additionalPropertiesSchema()), context, next);
additionalPropertiesSchema = buildRefSchemaIfObject(additionalPropertiesSchema, context);
schema.additionalProperties(additionalPropertiesSchema);
}
}

final Map<String, List<String>> dependentRequired = resolveDependentRequired(a, annotations, schemaAnnotation);
if (dependentRequired != null && !dependentRequired.isEmpty()) {
schema.setDependentRequired(dependentRequired);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public abstract class DateSchemaMixin {
@JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
public abstract Object getExample();

@JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
public abstract Object getDefault();

@JsonFormat (shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
public abstract Object getEnum();

@JsonIgnore
public abstract Object getJsonSchemaImpl();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ public static boolean hasSchemaAnnotation(io.swagger.v3.oas.annotations.media.Sc
&& schema.patternProperties().length == 0
&& schema.properties().length == 0
&& StringUtils.isBlank(schema._const())


&& schema.additionalProperties().equals(io.swagger.v3.oas.annotations.media.Schema.AdditionalPropertiesValue.USE_ADDITIONAL_PROPERTIES_ANNOTATION)
&& schema.additionalPropertiesSchema().equals(Void.class)
) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public void testEnumRefProperty() {
" type: object\n" +
" properties:\n" +
" a:\n" +
" $ref: '#/components/schemas/TestEnum'\n" +
" $ref: \"#/components/schemas/TestEnum\"\n" +
" b:\n" +
" $ref: '#/components/schemas/TestEnum'\n" +
" $ref: \"#/components/schemas/TestEnum\"\n" +
" c:\n" +
" $ref: '#/components/schemas/TestSecondEnum'\n" +
" $ref: \"#/components/schemas/TestSecondEnum\"\n" +
" d:\n" +
" type: string\n" +
" enum:\n" +
Expand Down Expand Up @@ -133,11 +133,11 @@ public void testEnumRefPropertyWithFQNTypeNameResolver() {
" type: object\n" +
" properties:\n" +
" a:\n" +
" $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestEnum'\n" +
" $ref: \"#/components/schemas/io.swagger.v3.core.oas.models.TestEnum\"\n" +
" b:\n" +
" $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestEnum'\n" +
" $ref: \"#/components/schemas/io.swagger.v3.core.oas.models.TestEnum\"\n" +
" c:\n" +
" $ref: '#/components/schemas/io.swagger.v3.core.oas.models.TestSecondEnum'\n" +
" $ref: \"#/components/schemas/io.swagger.v3.core.oas.models.TestSecondEnum\"\n" +
" d:\n" +
" type: string\n" +
" enum:\n" +
Expand Down Expand Up @@ -173,7 +173,7 @@ public void testEnumRefPropertyGlobal() {
" type: object\n" +
" properties:\n" +
" enumValue:\n" +
" $ref: '#/components/schemas/TestEnum'\n" +
" $ref: \"#/components/schemas/TestEnum\"\n" +
"TestEnum:\n" +
" type: string\n" +
" enum:\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void testModelPropertyExampleJson() {
" type: object\n" +
" properties:\n" +
" exampleJson:\n" +
" $ref: '#/components/schemas/ExampleJson'\n" +
" $ref: \"#/components/schemas/ExampleJson\"\n" +
" example:\n" +
" id: 19877734";
SerializationMatchers.assertEqualsToYaml(readAll(modelWithPropertyExampleOverrideJson.class), yaml);
Expand Down Expand Up @@ -464,7 +464,7 @@ public void testModelPropertyImplExampleJson() {
" type: object\n" +
" properties:\n" +
" exampleJson:\n" +
" $ref: '#/components/schemas/ExampleJson'\n";
" $ref: \"#/components/schemas/ExampleJson\"\n";
SerializationMatchers.assertEqualsToYaml(readAll(modelWithPropertyImplExampleOverrideJson.class), yaml);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ public void testDeserializeRefCallback() throws Exception {
" description: voila!\n" +
" callbacks:\n" +
" testCallback1:\n" +
" $ref: '#/components/callbacks/Callback'\n" +
" $ref: \"#/components/callbacks/Callback\"\n" +
" callbacks:\n" +
" testCallback1:\n" +
" $ref: '#/components/callbacks/Callback'\n" +
" $ref: \"#/components/callbacks/Callback\"\n" +
"components:\n" +
" callbacks:\n" +
" Callback:\n" +
Expand Down Expand Up @@ -542,4 +542,46 @@ public void testExampleDeserializationOnMediaType() throws Exception {
assertTrue(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExampleSetFlag());
}

@Test
public void testDateSchemaSerialization() throws Exception {
String content = FileUtils.readFileToString(new File("src/test/resources/dateSchema.yaml"), "UTF-8");
OpenAPI openAPI = Yaml.mapper().readValue(content, OpenAPI.class);
Yaml.prettyPrint(openAPI);
SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3\n" +
"info:\n" +
" title: Simple Inventory API\n" +
" version: 1.0.0\n" +
"paths:\n" +
" /inventory:\n" +
" get:\n" +
" operationId: searchInventory\n" +
" parameters:\n" +
" - name: test\n" +
" in: header\n" +
" schema:\n" +
" type: string\n" +
" format: date\n" +
" enum:\n" +
" - 2023-12-12\n" +
" default: 2023-12-12\n" +
" responses:\n" +
" \"200\":\n" +
" description: search results matching criteria\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" type: array\n" +
" items:\n" +
" $ref: \"#/components/schemas/InventoryItem\"\n" +
"components:\n" +
" schemas:\n" +
" InventoryItem:\n" +
" type: object\n" +
" properties:\n" +
" releaseDate:\n" +
" type: string\n" +
" format: date-time\n" +
" example: 2016-08-29T09:12:33.001Z");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public void testAllofResolving() {
" - type: object\n" +
" description: First user schema property\n" +
" nullable: true\n" +
" - $ref: '#/components/schemas/UserProperty'\n" +
" - $ref: \"#/components/schemas/UserProperty\"\n" +
" propertyTwo:\n" +
" allOf:\n" +
" - type: object\n" +
" description: Second user schema property\n" +
" example: example value for propertyTwo\n" +
" - $ref: '#/components/schemas/UserProperty'\n" +
" - $ref: \"#/components/schemas/UserProperty\"\n" +
" propertyThree:\n" +
" allOf:\n" +
" - type: object\n" +
" description: \"Third user schema property, with example for testing\"\n" +
" example: example value for propertyThree\n" +
" - $ref: '#/components/schemas/UserProperty'\n";
" - $ref: \"#/components/schemas/UserProperty\"\n";

SerializationMatchers.assertEqualsToYaml(c.getDefinedModels(), expectedYaml);
// stringSchemaMap = c.readAll(InlineSchemaSecond.class);
Expand All @@ -53,7 +53,7 @@ public void testAllofResolving() {
" type: object\n" +
" properties:\n" +
" basicProperty:\n" +
" $ref: '#/components/schemas/BasicProperty'\n" +
" $ref: \"#/components/schemas/BasicProperty\"\n" +
" description: Represents an order-specific property\n" +
" example: Order-specific example value\n" +
"OrderSchema:\n" +
Expand All @@ -64,13 +64,13 @@ public void testAllofResolving() {
" - type: object\n" +
" description: First order schema property\n" +
" nullable: true\n" +
" - $ref: '#/components/schemas/OrderProperty'\n" +
" - $ref: \"#/components/schemas/OrderProperty\"\n" +
" userProperty:\n" +
" allOf:\n" +
" - type: object\n" +
" description: \"Order schema property, references UserProperty\"\n" +
" example: example value for userProperty\n" +
" - $ref: '#/components/schemas/UserProperty'\n" +
" - $ref: \"#/components/schemas/UserProperty\"\n" +
"UserProperty:\n" +
" type: object\n" +
" description: Represents a user-specific property\n" +
Expand All @@ -83,19 +83,19 @@ public void testAllofResolving() {
" - type: object\n" +
" description: First user schema property\n" +
" nullable: true\n" +
" - $ref: '#/components/schemas/UserProperty'\n" +
" - $ref: \"#/components/schemas/UserProperty\"\n" +
" propertyTwo:\n" +
" allOf:\n" +
" - type: object\n" +
" description: Second user schema property\n" +
" example: example value for propertyTwo\n" +
" - $ref: '#/components/schemas/UserProperty'\n" +
" - $ref: \"#/components/schemas/UserProperty\"\n" +
" propertyThree:\n" +
" allOf:\n" +
" - type: object\n" +
" description: \"Third user schema property, with example for testing\"\n" +
" example: example value for propertyThree\n" +
" - $ref: '#/components/schemas/UserProperty'\n";
" - $ref: \"#/components/schemas/UserProperty\"\n";
SerializationMatchers.assertEqualsToYaml(c.getDefinedModels(), expectedYaml);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void testTicket2169() {
" type: string\n" +
" readOnly: true\n" +
" data:\n" +
" $ref: '#/components/schemas/Data'\n" +
" $ref: \"#/components/schemas/Data\"\n" +
" GetterJsonPropertyOnField:\n" +
" type: string\n" +
" GetterJsonPropertyOnFieldReadWrite:\n" +
Expand Down Expand Up @@ -141,7 +141,7 @@ public void testTicket2845() {
" type: object\n" +
" properties:\n" +
" child:\n" +
" $ref: '#/components/schemas/Ticket2845Child'");
" $ref: \"#/components/schemas/Ticket2845Child\"");

/*
TODO: Test demonstrating annotation not being resolved when class is used/refernces elsewhere with different annotations
Expand All @@ -165,9 +165,9 @@ and referenced (in the same or different class) with no or different @JsonIgnor
" type: object\n" +
" properties:\n" +
" child:\n" +
" $ref: '#/components/schemas/Ticket2845Child'\n" +
" $ref: \"#/components/schemas/Ticket2845Child\"\n" +
" childNoAnnotation:\n" +
" $ref: '#/components/schemas/Ticket2845Child'");
" $ref: \"#/components/schemas/Ticket2845Child\"");
}

static class Ticket2845Parent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testTicket2189() {
"SubClass:\n" +
" type: object\n" +
" allOf:\n" +
" - $ref: '#/components/schemas/BaseClass'\n" +
" - $ref: \"#/components/schemas/BaseClass\"\n" +
" - type: object\n" +
" properties:\n" +
" subClassProperty:\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void testCyclicBean() throws Exception {
" type: array\n" +
" description: Other related things\n" +
" items:\n" +
" $ref: '#/components/schemas/MyThing'\n" +
" $ref: \"#/components/schemas/MyThing\"\n" +
"description: Thing");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void testSubType() throws Exception {
"Ticket2862ModelImpl:\n" +
" type: string\n" +
" allOf:\n" +
" - $ref: '#/components/schemas/Ticket2862Model'\n" +
" - $ref: \"#/components/schemas/Ticket2862Model\"\n" +
" enum:\n" +
" - VALUE1\n" +
" - VALUE2\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void test2884_null() {
Assert.assertNotNull(o);
Assert.assertTrue(o.get$ref().contains(Ticket2884ModelClass.class.getSimpleName()));
SerializationMatchers.assertEqualsToYaml(schema.schema.getProperties(), "Ticket2884ModelClass:\n" +
" $ref: '#/components/schemas/Ticket2884ModelClass'");
" $ref: \"#/components/schemas/Ticket2884ModelClass\"");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public void testPropertyName() throws Exception {
" name:\n" +
" type: string\n" +
" perServing:\n" +
" $ref: '#/components/schemas/QuantitativeValue'\n" +
" $ref: \"#/components/schemas/QuantitativeValue\"\n" +
" per100Gram:\n" +
" $ref: '#/components/schemas/QuantitativeValue'\n" +
" $ref: \"#/components/schemas/QuantitativeValue\"\n" +
" description: Nutritional value specification");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public void testLocalTime() throws Exception {
" name:\n" +
" type: string\n" +
" a:\n" +
" $ref: '#/components/schemas/LocalTime'\n" +
" $ref: \"#/components/schemas/LocalTime\"\n" +
" b:\n" +
" $ref: '#/components/schemas/LocalTime'\n" +
" $ref: \"#/components/schemas/LocalTime\"\n" +
" c:\n" +
" $ref: '#/components/schemas/LocalTime'\n" +
" $ref: \"#/components/schemas/LocalTime\"\n" +
" d:\n" +
" type: string\n" +
" format: date-time\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testTicket3030() throws Exception {
String yaml = "Child:\n" +
" type: object\n" +
" allOf:\n" +
" - $ref: '#/components/schemas/Parent'\n" +
" - $ref: \"#/components/schemas/Parent\"\n" +
" - type: object\n" +
" properties:\n" +
" property:\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testTicket3063() throws Exception {
" type: object\n" +
" description: SubClass\n" +
" allOf:\n" +
" - $ref: '#/components/schemas/BaseClass'\n" +
" - $ref: \"#/components/schemas/BaseClass\"\n" +
" - type: object\n" +
" properties:\n" +
" additionalPropertyWhichShouldBeThere:\n" +
Expand Down
Loading

0 comments on commit 1e7f7d0

Please sign in to comment.