Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bug/4817-add-patternproperties-support-in-…
Browse files Browse the repository at this point in the history
…spec-filter
Opharion authored Jan 16, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents c6e6403 + 3e9db3c commit 1e7f7d0
Showing 96 changed files with 806 additions and 587 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
@@ -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())) {
@@ -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);
Original file line number Diff line number Diff line change
@@ -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();

Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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" +
@@ -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" +
@@ -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" +
Original file line number Diff line number Diff line change
@@ -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);
@@ -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);
}

Original file line number Diff line number Diff line change
@@ -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" +
@@ -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
@@ -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);
@@ -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" +
@@ -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" +
@@ -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);
}

Original file line number Diff line number Diff line change
@@ -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" +
@@ -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
@@ -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 {
Original file line number Diff line number Diff line change
@@ -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" +
Original file line number Diff line number Diff line change
@@ -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");
}

Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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
@@ -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");
}

Original file line number Diff line number Diff line change
@@ -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" +
Original file line number Diff line number Diff line change
@@ -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" +
Original file line number Diff line number Diff line change
@@ -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" +
Loading

0 comments on commit 1e7f7d0

Please sign in to comment.