Skip to content

Commit ee0d71d

Browse files
committed
Changes report: Please add OpenAPI 3.1 supports #1181
1 parent e758d41 commit ee0d71d

File tree

1,450 files changed

+40040
-27072
lines changed

Some content is hidden

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

1,450 files changed

+40040
-27072
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

+29-19
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
*
33
* *
44
* * *
5-
* * * * Copyright 2019-2022 the original author or authors.
65
* * * *
7-
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8-
* * * * you may not use this file except in compliance with the License.
9-
* * * * You may obtain a copy of the License at
6+
* * * * * Copyright 2019-2022 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
1019
* * * *
11-
* * * * https://www.apache.org/licenses/LICENSE-2.0
12-
* * * *
13-
* * * * Unless required by applicable law or agreed to in writing, software
14-
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15-
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
* * * * See the License for the specific language governing permissions and
17-
* * * * limitations under the License.
1820
* * *
1921
* *
2022
*
@@ -54,9 +56,7 @@
5456
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
5557
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
5658
import io.swagger.v3.core.filter.SpecFilter;
57-
import io.swagger.v3.core.util.Json;
5859
import io.swagger.v3.core.util.ReflectionUtils;
59-
import io.swagger.v3.core.util.Yaml;
6060
import io.swagger.v3.oas.annotations.Hidden;
6161
import io.swagger.v3.oas.annotations.callbacks.Callback;
6262
import io.swagger.v3.oas.annotations.enums.ParameterIn;
@@ -84,9 +84,12 @@
8484
import org.springdoc.core.fn.RouterFunctionData;
8585
import org.springdoc.core.fn.RouterOperation;
8686
import org.springdoc.core.mixins.SortedOpenAPIMixin;
87+
import org.springdoc.core.mixins.SortedOpenAPIMixin31;
8788
import org.springdoc.core.mixins.SortedSchemaMixin;
89+
import org.springdoc.core.mixins.SortedSchemaMixin31;
8890
import org.springdoc.core.models.MethodAttributes;
8991
import org.springdoc.core.properties.SpringDocConfigProperties;
92+
import org.springdoc.core.properties.SpringDocConfigProperties.ApiDocs.OpenApiVersion;
9093
import org.springdoc.core.properties.SpringDocConfigProperties.GroupConfig;
9194
import org.springdoc.core.providers.ActuatorProvider;
9295
import org.springdoc.core.providers.CloudFunctionProvider;
@@ -317,6 +320,8 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
317320
Map<String, Object> findControllerAdvice = openAPIService.getControllerAdviceMap();
318321
// calculate generic responses
319322
openApi = openAPIService.getCalculatedOpenAPI();
323+
if (OpenApiVersion.OPENAPI_3_1 == springDocConfigProperties.getApiDocs().getVersion())
324+
openApi.openapi(OpenApiVersion.OPENAPI_3_1.getVersion());
320325
if (springDocConfigProperties.isDefaultOverrideWithGenericResponse()) {
321326
if (!CollectionUtils.isEmpty(mappingsMap))
322327
findControllerAdvice.putAll(mappingsMap);
@@ -343,8 +348,8 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
343348
List<Server> servers = openApi.getServers();
344349
List<Server> serversCopy = null;
345350
try {
346-
serversCopy = Json.mapper()
347-
.readValue(Json.mapper().writeValueAsString(servers), new TypeReference<List<Server>>() {});
351+
serversCopy = springDocProviders.jsonMapper()
352+
.readValue(springDocProviders.jsonMapper().writeValueAsString(servers), new TypeReference<List<Server>>() {});
348353
}
349354
catch (JsonProcessingException e) {
350355
LOGGER.warn("Json Processing Exception occurred: {}", e.getMessage());
@@ -1174,7 +1179,7 @@ protected void initOpenAPIBuilder(Locale locale) {
11741179
*/
11751180
protected String writeYamlValue(OpenAPI openAPI) throws JsonProcessingException {
11761181
String result;
1177-
ObjectMapper objectMapper = Yaml.mapper();
1182+
ObjectMapper objectMapper = springDocProviders.yamlMapper();
11781183
if (springDocConfigProperties.isWriterWithOrderByKeys())
11791184
sortOutput(objectMapper);
11801185
YAMLFactory factory = (YAMLFactory) objectMapper.getFactory();
@@ -1245,7 +1250,7 @@ protected boolean isActuatorRestController(String operationPath, HandlerMethod h
12451250
*/
12461251
protected String writeJsonValue(OpenAPI openAPI) throws JsonProcessingException {
12471252
String result;
1248-
ObjectMapper objectMapper = Json.mapper();
1253+
ObjectMapper objectMapper = springDocProviders.jsonMapper();
12491254
if (springDocConfigProperties.isWriterWithOrderByKeys())
12501255
sortOutput(objectMapper);
12511256
if (!springDocConfigProperties.isWriterWithDefaultPrettyPrinter())
@@ -1324,8 +1329,13 @@ enum ConditionType {
13241329
private void sortOutput(ObjectMapper objectMapper) {
13251330
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
13261331
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
1327-
objectMapper.addMixIn(OpenAPI.class, SortedOpenAPIMixin.class);
1328-
objectMapper.addMixIn(Schema.class, SortedSchemaMixin.class);
1332+
if (OpenApiVersion.OPENAPI_3_1 == springDocConfigProperties.getApiDocs().getVersion()){
1333+
objectMapper.addMixIn(OpenAPI.class, SortedOpenAPIMixin31.class);
1334+
objectMapper.addMixIn(Schema.class, SortedSchemaMixin31.class);
1335+
} else {
1336+
objectMapper.addMixIn(OpenAPI.class, SortedOpenAPIMixin.class);
1337+
objectMapper.addMixIn(Schema.class, SortedSchemaMixin.class);
1338+
}
13291339
}
13301340

13311341
/**

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

+54-30
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
*
33
* *
44
* * *
5-
* * * * Copyright 2019-2022 the original author or authors.
65
* * * *
7-
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8-
* * * * you may not use this file except in compliance with the License.
9-
* * * * You may obtain a copy of the License at
6+
* * * * * Copyright 2019-2022 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
1019
* * * *
11-
* * * * https://www.apache.org/licenses/LICENSE-2.0
12-
* * * *
13-
* * * * Unless required by applicable law or agreed to in writing, software
14-
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15-
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
* * * * See the License for the specific language governing permissions and
17-
* * * * limitations under the License.
1820
* * *
1921
* *
2022
*
@@ -65,6 +67,7 @@
6567
import org.springdoc.core.providers.ActuatorProvider;
6668
import org.springdoc.core.providers.CloudFunctionProvider;
6769
import org.springdoc.core.providers.JavadocProvider;
70+
import org.springdoc.core.providers.ObjectMapperProvider;
6871
import org.springdoc.core.providers.RepositoryRestConfigurationProvider;
6972
import org.springdoc.core.providers.RepositoryRestResourceProvider;
7073
import org.springdoc.core.providers.RouterFunctionProvider;
@@ -150,12 +153,13 @@ LocalVariableTableParameterNameDiscoverer localSpringDocParameterNameDiscoverer(
150153
/**
151154
* Additional models converter additional models converter.
152155
*
156+
* @param objectMapperProvider the object mapper provider
153157
* @return the additional models converter
154158
*/
155159
@Bean
156160
@Lazy(false)
157-
AdditionalModelsConverter additionalModelsConverter() {
158-
return new AdditionalModelsConverter();
161+
AdditionalModelsConverter additionalModelsConverter(ObjectMapperProvider objectMapperProvider) {
162+
return new AdditionalModelsConverter(objectMapperProvider);
159163
}
160164

161165
/**
@@ -173,25 +177,27 @@ PropertyCustomizingConverter propertyCustomizingConverter(Optional<List<Property
173177
/**
174178
* File support converter file support converter.
175179
*
180+
* @param objectMapperProvider the object mapper provider
176181
* @return the file support converter
177182
*/
178183
@Bean
179184
@ConditionalOnMissingBean
180185
@Lazy(false)
181-
FileSupportConverter fileSupportConverter() {
182-
return new FileSupportConverter();
186+
FileSupportConverter fileSupportConverter(ObjectMapperProvider objectMapperProvider) {
187+
return new FileSupportConverter(objectMapperProvider);
183188
}
184189

185190
/**
186191
* Response support converter response support converter.
187192
*
193+
* @param objectMapperProvider the object mapper provider
188194
* @return the response support converter
189195
*/
190196
@Bean
191197
@ConditionalOnMissingBean
192198
@Lazy(false)
193-
ResponseSupportConverter responseSupportConverter() {
194-
return new ResponseSupportConverter();
199+
ResponseSupportConverter responseSupportConverter(ObjectMapperProvider objectMapperProvider) {
200+
return new ResponseSupportConverter(objectMapperProvider);
195201
}
196202

197203
/**
@@ -210,14 +216,15 @@ SchemaPropertyDeprecatingConverter schemaPropertyDeprecatingConverter() {
210216
/**
211217
* Polymorphic model converter polymorphic model converter.
212218
*
219+
* @param objectMapperProvider the object mapper provider
213220
* @return the polymorphic model converter
214221
*/
215222
@Bean
216223
@ConditionalOnMissingBean
217224
@ConditionalOnProperty(name = SPRINGDOC_POLYMORPHIC_CONVERTER_ENABLED, matchIfMissing = true)
218225
@Lazy(false)
219-
PolymorphicModelConverter polymorphicModelConverter() {
220-
return new PolymorphicModelConverter();
226+
PolymorphicModelConverter polymorphicModelConverter(ObjectMapperProvider objectMapperProvider) {
227+
return new PolymorphicModelConverter(objectMapperProvider);
221228
}
222229

223230
/**
@@ -227,8 +234,8 @@ PolymorphicModelConverter polymorphicModelConverter() {
227234
* @param securityParser the security parser
228235
* @param springDocConfigProperties the spring doc config properties
229236
* @param propertyResolverUtils the property resolver utils
230-
* @param openApiBuilderCustomizers the open api builder customisers
231-
* @param serverBaseUrlCustomizers the server base url customizers
237+
* @param openApiBuilderCustomisers the open api builder customisers
238+
* @param serverBaseUrlCustomisers the server base url customisers
232239
* @param javadocProvider the javadoc provider
233240
* @return the open api builder
234241
*/
@@ -237,11 +244,10 @@ PolymorphicModelConverter polymorphicModelConverter() {
237244
@Lazy(false)
238245
OpenAPIService openAPIBuilder(Optional<OpenAPI> openAPI,
239246
SecurityService securityParser,
240-
SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils,
241-
Optional<List<OpenApiBuilderCustomizer>> openApiBuilderCustomizers,
242-
Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomizers,
243-
Optional<JavadocProvider> javadocProvider) {
244-
return new OpenAPIService(openAPI, securityParser, springDocConfigProperties, propertyResolverUtils, openApiBuilderCustomizers, serverBaseUrlCustomizers, javadocProvider);
247+
SpringDocConfigProperties springDocConfigProperties,PropertyResolverUtils propertyResolverUtils,
248+
Optional<List<OpenApiBuilderCustomizer>> openApiBuilderCustomisers,
249+
Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomisers, Optional<JavadocProvider> javadocProvider) {
250+
return new OpenAPIService(openAPI, securityParser, springDocConfigProperties, propertyResolverUtils, openApiBuilderCustomisers, serverBaseUrlCustomisers, javadocProvider);
245251
}
246252

247253
/**
@@ -332,16 +338,17 @@ ReturnTypeParser genericReturnTypeParser() {
332338
* @param propertyResolverUtils the property resolver utils
333339
* @param optionalDelegatingMethodParameterCustomizer the optional delegating method parameter customizer
334340
* @param optionalWebConversionServiceProvider the optional web conversion service provider
341+
* @param objectMapperProvider the object mapper provider
335342
* @return the generic parameter builder
336343
*/
337344
@Bean
338345
@ConditionalOnMissingBean
339346
@Lazy(false)
340347
GenericParameterService parameterBuilder(PropertyResolverUtils propertyResolverUtils,
341348
Optional<DelegatingMethodParameterCustomizer> optionalDelegatingMethodParameterCustomizer,
342-
Optional<WebConversionServiceProvider> optionalWebConversionServiceProvider) {
349+
Optional<WebConversionServiceProvider> optionalWebConversionServiceProvider, ObjectMapperProvider objectMapperProvider) {
343350
return new GenericParameterService(propertyResolverUtils, optionalDelegatingMethodParameterCustomizer,
344-
optionalWebConversionServiceProvider);
351+
optionalWebConversionServiceProvider, objectMapperProvider);
345352
}
346353

347354
/**
@@ -399,14 +406,18 @@ static BeanFactoryPostProcessor springdocBeanFactoryPostProcessor2() {
399406
* @param repositoryRestResourceProvider the repository rest resource provider
400407
* @param routerFunctionProvider the router function provider
401408
* @param springWebProvider the spring web provider
409+
* @param webConversionServiceProvider the web conversion service provider
410+
* @param objectMapperProvider the object mapper provider
402411
* @return the spring doc providers
403412
*/
404413
@Bean
405414
@ConditionalOnMissingBean
406415
@Lazy(false)
407416
SpringDocProviders springDocProviders(Optional<ActuatorProvider> actuatorProvider, Optional<CloudFunctionProvider> springCloudFunctionProvider, Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
408-
Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider, Optional<RouterFunctionProvider> routerFunctionProvider, Optional<SpringWebProvider> springWebProvider) {
409-
return new SpringDocProviders(actuatorProvider, springCloudFunctionProvider, springSecurityOAuth2Provider, repositoryRestResourceProvider, routerFunctionProvider, springWebProvider);
417+
Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider, Optional<RouterFunctionProvider> routerFunctionProvider,
418+
Optional<SpringWebProvider> springWebProvider, Optional<WebConversionServiceProvider> webConversionServiceProvider,
419+
ObjectMapperProvider objectMapperProvider) {
420+
return new SpringDocProviders(actuatorProvider, springCloudFunctionProvider, springSecurityOAuth2Provider, repositoryRestResourceProvider, routerFunctionProvider, springWebProvider, webConversionServiceProvider, objectMapperProvider);
410421
}
411422

412423
/**
@@ -535,4 +546,17 @@ RepositoryRestConfigurationProvider repositoryRestConfigurationProvider(Optional
535546
return new RepositoryRestConfigurationProvider(optionalRepositoryRestConfiguration);
536547
}
537548
}
549+
550+
/**
551+
* Object mapper provider object mapper provider.
552+
*
553+
* @param springDocConfigProperties the spring doc config properties
554+
* @return the object mapper provider
555+
*/
556+
@Bean
557+
@ConditionalOnMissingBean
558+
@Lazy(false)
559+
ObjectMapperProvider objectMapperProvider(SpringDocConfigProperties springDocConfigProperties){
560+
return new ObjectMapperProvider(springDocConfigProperties);
561+
}
538562
}

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

+16-13
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
*
33
* *
44
* * *
5-
* * * * Copyright 2019-2022 the original author or authors.
65
* * * *
7-
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8-
* * * * you may not use this file except in compliance with the License.
9-
* * * * You may obtain a copy of the License at
6+
* * * * * Copyright 2019-2022 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
1019
* * * *
11-
* * * * https://www.apache.org/licenses/LICENSE-2.0
12-
* * * *
13-
* * * * Unless required by applicable law or agreed to in writing, software
14-
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15-
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
* * * * See the License for the specific language governing permissions and
17-
* * * * limitations under the License.
1820
* * *
1921
* *
2022
*
@@ -35,6 +37,7 @@
3537
import org.springdoc.core.data.DataRestTagsService;
3638
import org.springdoc.core.properties.SpringDocConfigProperties;
3739
import org.springdoc.core.providers.DataRestHalProvider;
40+
import org.springdoc.core.providers.ObjectMapperProvider;
3841
import org.springdoc.core.providers.SpringRepositoryRestResourceProvider;
3942
import org.springdoc.core.service.AbstractRequestService;
4043
import org.springdoc.core.service.GenericParameterService;
@@ -93,8 +96,8 @@ public class SpringDocDataRestConfiguration {
9396
@ConditionalOnMissingBean
9497
@Primary
9598
@Lazy(false)
96-
DataRestHalProvider halProvider(Optional<RepositoryRestConfiguration> repositoryRestConfiguration, Optional<HateoasProperties> hateoasPropertiesOptional) {
97-
return new DataRestHalProvider(repositoryRestConfiguration, hateoasPropertiesOptional);
99+
DataRestHalProvider halProvider(Optional<RepositoryRestConfiguration> repositoryRestConfiguration, Optional<HateoasProperties> hateoasPropertiesOptional, ObjectMapperProvider objectMapperProvider) {
100+
return new DataRestHalProvider(repositoryRestConfiguration, hateoasPropertiesOptional, objectMapperProvider);
98101
}
99102

100103

0 commit comments

Comments
 (0)