Skip to content

Commit ba51c98

Browse files
committed
swagger-core update to 2.2.30
1 parent c92f581 commit ba51c98

File tree

69 files changed

+1169
-1905
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1169
-1905
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
6363
<nexus-staging-maven-plugin>1.6.8</nexus-staging-maven-plugin>
6464
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
65-
<swagger-api.version>2.2.29</swagger-api.version>
65+
<swagger-api.version>2.2.30</swagger-api.version>
6666
<swagger-ui.version>5.20.7</swagger-ui.version>
6767
<gmavenplus-plugin.version>1.13.1</gmavenplus-plugin.version>
6868
<jjwt.version>0.9.1</jjwt.version>

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/configuration/SpringDocConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
import static org.springdoc.core.utils.Constants.SPRINGDOC_DEPRECATING_CONVERTER_ENABLED;
132132
import static org.springdoc.core.utils.Constants.SPRINGDOC_ENABLED;
133133
import static org.springdoc.core.utils.Constants.SPRINGDOC_ENABLE_EXTRA_SCHEMAS;
134+
import static org.springdoc.core.utils.Constants.SPRINGDOC_EXPLICIT_OBJECT_SCHEMA;
134135
import static org.springdoc.core.utils.Constants.SPRINGDOC_POLYMORPHIC_CONVERTER_ENABLED;
135136
import static org.springdoc.core.utils.Constants.SPRINGDOC_SCHEMA_RESOLVE_PROPERTIES;
136137
import static org.springdoc.core.utils.Constants.SPRINGDOC_SHOW_ACTUATOR;
@@ -680,8 +681,9 @@ GlobalOpenApiCustomizer globalOpenApiCustomizer() {
680681
*/
681682
@Bean
682683
@ConditionalOnMissingBean
684+
@ConditionalOnProperty(name = SPRINGDOC_EXPLICIT_OBJECT_SCHEMA, havingValue = "true")
683685
@Lazy(false)
684686
OAS31ModelConverter oas31ModelConverter(SpringDocConfigProperties springDocConfigProperties) {
685-
return springDocConfigProperties.isOpenapi31() ? new OAS31ModelConverter() : null;
687+
return springDocConfigProperties.isOpenapi31() ? new OAS31ModelConverter() : null;
686688
}
687689
}

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/converters/ResponseSupportConverter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.swagger.v3.core.converter.AnnotatedType;
3434
import io.swagger.v3.core.converter.ModelConverter;
3535
import io.swagger.v3.core.converter.ModelConverterContext;
36+
import io.swagger.v3.oas.models.media.ObjectSchema;
3637
import io.swagger.v3.oas.models.media.Schema;
3738
import io.swagger.v3.oas.models.media.StringSchema;
3839
import org.springdoc.core.providers.ObjectMapperProvider;
@@ -73,6 +74,8 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
7374
JavaType innerType = findResponseEntity(javaType).containedType(0);
7475
if (innerType == null)
7576
return new StringSchema();
77+
if(Object.class.equals(innerType.getRawClass()))
78+
return new ObjectSchema();
7679
return context.resolve(new AnnotatedType(innerType)
7780
.jsonViewAnnotation(type.getJsonViewAnnotation())
7881
.ctxAnnotations((type.getCtxAnnotations()))

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/properties/SpringDocConfigProperties.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* * * *
2222
* * *
2323
* *
24-
*
24+
*
2525
*/
2626

2727
package org.springdoc.core.properties;
@@ -279,6 +279,18 @@ public class SpringDocConfigProperties {
279279
*/
280280
private boolean enableExtraSchemas;
281281

282+
/**
283+
* Set explicit-object-schema to true to always include type:
284+
* object in the schema, or to false to omit type: object.
285+
*/
286+
private boolean explicitObjectSchema;
287+
288+
/**
289+
* When set to true, schemas without a defined type will be deserialized as an ArbitrarySchema (with no type),
290+
* instead of an ObjectSchema with type: object.
291+
*/
292+
private boolean useArbitrarySchemas;
293+
282294
/**
283295
* Is enable additional schemas resolution boolean.
284296
*
@@ -1903,4 +1915,40 @@ public boolean isEnableDefaultApiDocs() {
19031915
public void setEnableDefaultApiDocs(boolean enableDefaultApiDocs) {
19041916
this.enableDefaultApiDocs = enableDefaultApiDocs;
19051917
}
1918+
1919+
/**
1920+
* Is explicit object schema boolean.
1921+
*
1922+
* @return the boolean
1923+
*/
1924+
public boolean isExplicitObjectSchema() {
1925+
return explicitObjectSchema;
1926+
}
1927+
1928+
/**
1929+
* Sets explicit object schema.
1930+
*
1931+
* @param explicitObjectSchema the explicit object schema
1932+
*/
1933+
public void setExplicitObjectSchema(boolean explicitObjectSchema) {
1934+
this.explicitObjectSchema = explicitObjectSchema;
1935+
}
1936+
1937+
/**
1938+
* Is use arbitrary schemas boolean.
1939+
*
1940+
* @return the boolean
1941+
*/
1942+
public boolean isUseArbitrarySchemas() {
1943+
return useArbitrarySchemas;
1944+
}
1945+
1946+
/**
1947+
* Sets use arbitrary schemas.
1948+
*
1949+
* @param useArbitrarySchemas the use arbitrary schemas
1950+
*/
1951+
public void setUseArbitrarySchemas(boolean useArbitrarySchemas) {
1952+
this.useArbitrarySchemas = useArbitrarySchemas;
1953+
}
19061954
}

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/providers/ObjectMapperProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public ObjectMapperProvider(SpringDocConfigProperties springDocConfigProperties)
7474
if (openApiVersion == OpenApiVersion.OPENAPI_3_1) {
7575
jsonMapper = Json31.mapper();
7676
yamlMapper = Yaml31.mapper();
77+
if(springDocConfigProperties.isUseArbitrarySchemas()){
78+
System.setProperty(Schema.USE_ARBITRARY_SCHEMA_PROPERTY, "true");
79+
}
80+
if(springDocConfigProperties.isExplicitObjectSchema()){
81+
System.setProperty(Schema.EXPLICIT_OBJECT_SCHEMA_PROPERTY, "true");
82+
}
7783
}
7884
else {
7985
jsonMapper = Json.mapper();

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/Constants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ public final class Constants {
428428
* The constant SPRINGDOC_ENABLE_ADDITIONAL_SCHEMAS_RESOLUTION.
429429
*/
430430
public static final String SPRINGDOC_ENABLE_EXTRA_SCHEMAS = "springdoc.enable-extra-schemas";
431+
432+
/**
433+
* The constant SPRINGDOC_EXPLICIT_OBJECT_SCHEMA.
434+
*/
435+
public static final String SPRINGDOC_EXPLICIT_OBJECT_SCHEMA = "springdoc.explicit-object-schema";
431436

432437
/**
433438
* Instantiates a new Constants.

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/SpringDocUtils.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* * * *
2222
* * *
2323
* *
24-
*
24+
*
2525
*/
2626

2727
package org.springdoc.core.utils;
@@ -44,6 +44,7 @@
4444
import java.util.function.Predicate;
4545

4646
import io.swagger.v3.core.converter.AnnotatedType;
47+
import io.swagger.v3.oas.models.media.ComposedSchema;
4748
import io.swagger.v3.oas.models.media.Content;
4849
import io.swagger.v3.oas.models.media.Schema;
4950
import io.swagger.v3.oas.models.media.StringSchema;
@@ -433,7 +434,7 @@ public static boolean isValidPath(String path) {
433434
* @param parentTypes the parent types
434435
* @return the spring doc utils
435436
*/
436-
public SpringDocUtils addParentType(String ...parentTypes) {
437+
public SpringDocUtils addParentType(String... parentTypes) {
437438
PolymorphicModelConverter.addParentType(parentTypes);
438439
return this;
439440
}
@@ -491,7 +492,7 @@ public static String getParentTypeName(AnnotatedType type, Class<?> cls) {
491492
* @return the boolean
492493
*/
493494
public static boolean isComposedSchema(Schema referencedSchema) {
494-
return referencedSchema.getOneOf() != null || referencedSchema.getAllOf() != null || referencedSchema.getAnyOf() != null;
495+
return referencedSchema.getOneOf() != null || referencedSchema.getAllOf() != null || referencedSchema.getAnyOf() != null || referencedSchema instanceof ComposedSchema;
495496
}
496497

497498
/**
@@ -508,9 +509,12 @@ else if (schema.getItems() != null && schema.getItems().getType() != null
508509
&& CollectionUtils.isEmpty(schema.getItems().getTypes())) {
509510
schema.getItems().addType(schema.getItems().getType());
510511
}
511-
if(schema.getProperties() != null){
512+
if (schema.getProperties() != null) {
512513
schema.getProperties().forEach((key, value) -> handleSchemaTypes(value));
513514
}
515+
if (schema.getType() == null && schema.getTypes() == null && schema.get$ref() == null &&!isComposedSchema(schema)) {
516+
schema.addType("object");
517+
}
514518
}
515519
}
516520

@@ -520,7 +524,7 @@ else if (schema.getItems() != null && schema.getItems().getType() != null
520524
* @param content the content
521525
*/
522526
public static void handleSchemaTypes(Content content) {
523-
if(content !=null){
527+
if (content != null) {
524528
content.values().forEach(mediaType -> {
525529
if (mediaType.getSchema() != null) {
526530
handleSchemaTypes(mediaType.getSchema());
@@ -554,7 +558,7 @@ public SpringDocUtils initExtraSchemas() {
554558
* @return the spring doc utils
555559
*/
556560
public SpringDocUtils resetExtraSchemas() {
557-
SpringDocUtils.getConfig().removeFromSchemaMap(LocalTime.class,YearMonth.class,
561+
SpringDocUtils.getConfig().removeFromSchemaMap(LocalTime.class, YearMonth.class,
558562
MonthDay.class, Year.class, Duration.class, Period.class, OffsetTime.class,
559563
ZoneId.class, ZoneOffset.class, TimeZone.class, Charset.class, Locale.class);
560564
return this;

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.0.1/app3.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@
304304
"schemas": {
305305
"TweetDTO": {
306306
"required": [
307-
"createdAt"
307+
"createdAt",
308+
"text"
308309
],
309310
"type": "object",
310311
"properties": {

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.0.1/app5.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
"schemas": {
7171
"Tweet": {
7272
"required": [
73-
"createdAt"
73+
"createdAt",
74+
"text"
7475
],
7576
"type": "object",
7677
"properties": {

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.0.1/app66.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
"schemas": {
6565
"TweetDTO": {
6666
"required": [
67-
"createdAt"
67+
"createdAt",
68+
"text"
6869
],
6970
"type": "object",
7071
"properties": {

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.0.1/app68.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
"schemas": {
6565
"TweetDTO": {
6666
"required": [
67-
"createdAt"
67+
"createdAt",
68+
"text"
6869
],
6970
"type": "object",
7071
"properties": {

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.0.1/app72.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@
269269
},
270270
"Position": {
271271
"required": [
272-
"createdAt"
272+
"createdAt",
273+
"positionName"
273274
],
274275
"type": "object",
275276
"properties": {

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.0.1/app85.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@
269269
},
270270
"Position": {
271271
"required": [
272-
"createdAt"
272+
"createdAt",
273+
"positionName"
273274
],
274275
"type": "object",
275276
"properties": {

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.0.1/app90.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@
549549
},
550550
"Position": {
551551
"required": [
552-
"createdAt"
552+
"createdAt",
553+
"positionName"
553554
],
554555
"type": "object",
555556
"properties": {

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.1.0/app3.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@
319319
}
320320
},
321321
"required": [
322-
"createdAt"
322+
"createdAt",
323+
"text"
323324
]
324325
}
325326
},

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.1.0/app5.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
}
8686
},
8787
"required": [
88-
"createdAt"
88+
"createdAt",
89+
"text"
8990
]
9091
}
9192
},

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.1.0/app66.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
}
8080
},
8181
"required": [
82-
"createdAt"
82+
"createdAt",
83+
"text"
8384
]
8485
}
8586
},

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.1.0/app68.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
}
8080
},
8181
"required": [
82-
"createdAt"
82+
"createdAt",
83+
"text"
8384
]
8485
}
8586
},

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.1.0/app72.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@
287287
}
288288
},
289289
"required": [
290-
"createdAt"
290+
"createdAt",
291+
"positionName"
291292
]
292293
}
293294
}

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.1.0/app85.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@
287287
}
288288
},
289289
"required": [
290-
"createdAt"
290+
"createdAt",
291+
"positionName"
291292
]
292293
}
293294
}

springdoc-openapi-starter-webflux-api/src/test/resources/results/3.1.0/app90.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@
567567
}
568568
},
569569
"required": [
570-
"createdAt"
570+
"createdAt",
571+
"positionName"
571572
]
572573
},
573574
"Quote": {

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app105/SpringDocApp105Test.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@
2424

2525
package test.org.springdoc.api.v31.app105;
2626

27+
import java.util.Optional;
28+
29+
import io.swagger.v3.core.converter.ModelConverter;
30+
import io.swagger.v3.core.converter.ModelConverters;
2731
import io.swagger.v3.oas.models.Components;
2832
import io.swagger.v3.oas.models.OpenAPI;
2933
import io.swagger.v3.oas.models.info.Info;
3034
import io.swagger.v3.oas.models.info.License;
35+
import io.swagger.v3.oas.models.media.Schema;
3136
import io.swagger.v3.oas.models.security.SecurityScheme;
37+
import org.junit.jupiter.api.AfterAll;
3238
import org.junit.jupiter.api.Test;
39+
import org.springdoc.core.converters.OAS31ModelConverter;
3340
import org.springdoc.core.utils.Constants;
3441
import test.org.springdoc.api.v31.AbstractSpringDocTest;
3542

@@ -38,12 +45,14 @@
3845
import org.springframework.test.context.TestPropertySource;
3946

4047
import static org.hamcrest.Matchers.is;
48+
import static org.springdoc.core.utils.Constants.SPRINGDOC_EXPLICIT_OBJECT_SCHEMA;
4149
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
4250
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
4351
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
4452
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
4553

4654
@TestPropertySource(properties = {
55+
SPRINGDOC_EXPLICIT_OBJECT_SCHEMA+"=true",
4756
"springdoc.group-configs[0].group=stores",
4857
"springdoc.group-configs[0].paths-to-match=/store/**",
4958
"springdoc.group-configs[1].group=users",
@@ -57,7 +66,15 @@
5766
})
5867
public class SpringDocApp105Test extends AbstractSpringDocTest {
5968

60-
public static String className;
69+
@AfterAll
70+
public static void reset() {
71+
System.setProperty(Schema.EXPLICIT_OBJECT_SCHEMA_PROPERTY, "false");
72+
ModelConverters instance = ModelConverters.getInstance(true);
73+
Optional<ModelConverter> oas31ModelConverter =
74+
instance.getConverters()
75+
.stream().filter(modelConverter -> modelConverter instanceof OAS31ModelConverter).findAny();
76+
oas31ModelConverter.ifPresent(instance::removeConverter);
77+
}
6178

6279
@Test
6380
protected void testApp() throws Exception {

0 commit comments

Comments
 (0)