Skip to content

Commit 317ef5a

Browse files
author
bnasslahsen
committed
Added property to override @deprecated. Fixes #747
1 parent 5e05311 commit 317ef5a

File tree

8 files changed

+240
-1
lines changed

8 files changed

+240
-1
lines changed

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
group = org.springdoc
22
version = 1.4.3-SNAPSHOT
3-
org.gradle.daemon = true
3+
org.gradle.caching=true
4+
org.gradle.parallel=true

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public final class Constants {
7070
*/
7171
public static final String SPRINGDOC_ENABLED = "springdoc.api-docs.enabled";
7272

73+
74+
/**
75+
* The constant SPRINGDOC_DEPRECATING_CONVERTER_ENABLED.
76+
*/
77+
public static final String SPRINGDOC_DEPRECATING_CONVERTER_ENABLED = "springdoc.model-converters.deprecating-converter.enabled";
78+
7379
/**
7480
* The constant SPRINGDOC_SCHEMA_RESOLVE_PROPERTIES.
7581
*/

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,64 @@ public void setWriterWithDefaultPrettyPrinter(boolean writerWithDefaultPrettyPri
426426
this.writerWithDefaultPrettyPrinter = writerWithDefaultPrettyPrinter;
427427
}
428428

429+
/**
430+
* The type Model converters.
431+
*/
432+
public static class ModelConverters {
433+
434+
/**
435+
* The Deprecating converter.
436+
*/
437+
private DeprecatingConverter deprecatingConverter = new DeprecatingConverter();
438+
439+
/**
440+
* Gets deprecating converter.
441+
*
442+
* @return the deprecating converter
443+
*/
444+
public DeprecatingConverter getDeprecatingConverter() {
445+
return deprecatingConverter;
446+
}
447+
448+
/**
449+
* Sets deprecating converter.
450+
*
451+
* @param deprecatingConverter the deprecating converter
452+
*/
453+
public void setDeprecatingConverter(DeprecatingConverter deprecatingConverter) {
454+
this.deprecatingConverter = deprecatingConverter;
455+
}
456+
457+
/**
458+
* The type Deprecating converter.
459+
*/
460+
public static class DeprecatingConverter {
461+
462+
/**
463+
* The Enabled.
464+
*/
465+
private boolean enabled;
466+
467+
/**
468+
* Is enabled boolean.
469+
*
470+
* @return the boolean
471+
*/
472+
public boolean isEnabled() {
473+
return enabled;
474+
}
475+
476+
/**
477+
* Sets enabled.
478+
*
479+
* @param enabled the enabled
480+
*/
481+
public void setEnabled(boolean enabled) {
482+
this.enabled = enabled;
483+
}
484+
}
485+
}
486+
429487
/**
430488
* The type Webjars.
431489
* @author bnasslahsen

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.springframework.context.annotation.Lazy;
5757
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
5858

59+
import static org.springdoc.core.Constants.SPRINGDOC_DEPRECATING_CONVERTER_ENABLED;
5960
import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
6061
import static org.springdoc.core.Constants.SPRINGDOC_SCHEMA_RESOLVE_PROPERTIES;
6162
import static org.springdoc.core.SpringDocUtils.getConfig;
@@ -141,6 +142,7 @@ ResponseSupportConverter responseSupportConverter() {
141142
*/
142143
@Bean
143144
@ConditionalOnMissingBean
145+
@ConditionalOnProperty(name = SPRINGDOC_DEPRECATING_CONVERTER_ENABLED, matchIfMissing = true)
144146
@Lazy(false)
145147
SchemaPropertyDeprecatingConverter schemaPropertyDeprecatingConverter() {
146148
return new SchemaPropertyDeprecatingConverter();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package test.org.springdoc.api.app125;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
5+
/**
6+
* @author bnasslahsen
7+
*/
8+
public class DeprecatedEntity
9+
{
10+
@Schema(deprecated = false)
11+
private String myNonDeprecatedField;
12+
13+
@Schema(deprecated = true)
14+
private String mydeprecatedField;
15+
16+
public String getMyNonDeprecatedField()
17+
{
18+
return myNonDeprecatedField;
19+
}
20+
21+
@Deprecated
22+
public DeprecatedEntity setMyNonDeprecatedField(String myNonDeprecatedField)
23+
{
24+
this.myNonDeprecatedField = myNonDeprecatedField;
25+
return this;
26+
}
27+
28+
public String getMydeprecatedField() {
29+
return mydeprecatedField;
30+
}
31+
32+
public void setMydeprecatedField(String mydeprecatedField) {
33+
this.mydeprecatedField = mydeprecatedField;
34+
}
35+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package test.org.springdoc.api.app125;
2+
3+
import javax.validation.constraints.NotNull;
4+
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
* @author bnasslahsen
10+
*/
11+
@RestController
12+
public class HelloController {
13+
14+
@GetMapping(value = "/search", produces = { "application/xml", "application/json" })
15+
public DeprecatedEntity getAllPets(@NotNull String toto) {
16+
return null;
17+
}
18+
19+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2020 the original author or authors.
6+
* * * *
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
10+
* * * *
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.
18+
* * *
19+
* *
20+
*
21+
*
22+
*/
23+
package test.org.springdoc.api.app125;
24+
25+
import java.util.Optional;
26+
27+
import io.swagger.v3.core.converter.ModelConverter;
28+
import io.swagger.v3.core.converter.ModelConverters;
29+
import org.springdoc.core.converters.SchemaPropertyDeprecatingConverter;
30+
import test.org.springdoc.api.AbstractSpringDocTest;
31+
32+
import org.springframework.boot.autoconfigure.SpringBootApplication;
33+
import org.springframework.test.context.TestPropertySource;
34+
35+
36+
/**
37+
* Tests Spring meta-annotations as method parameters
38+
*/
39+
@TestPropertySource(properties = "springdoc.model-converters.deprecating-converter.enabled=false")
40+
public class SpringDocApp125Test extends AbstractSpringDocTest {
41+
42+
@SpringBootApplication
43+
static class SpringDocTestApp {}
44+
45+
static {
46+
Optional<ModelConverter> deprecatingConverterOptional =
47+
ModelConverters.getInstance().getConverters()
48+
.stream().filter(modelConverter -> modelConverter instanceof SchemaPropertyDeprecatingConverter).findAny();
49+
deprecatingConverterOptional.ifPresent(ModelConverters.getInstance()::removeConverter);
50+
}
51+
52+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/search": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "getAllPets",
20+
"parameters": [
21+
{
22+
"name": "toto",
23+
"in": "query",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "OK",
33+
"content": {
34+
"application/xml": {
35+
"schema": {
36+
"$ref": "#/components/schemas/DeprecatedEntity"
37+
}
38+
},
39+
"application/json": {
40+
"schema": {
41+
"$ref": "#/components/schemas/DeprecatedEntity"
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
},
50+
"components": {
51+
"schemas": {
52+
"DeprecatedEntity": {
53+
"type": "object",
54+
"properties": {
55+
"myNonDeprecatedField": {
56+
"type": "string"
57+
},
58+
"mydeprecatedField": {
59+
"type": "string",
60+
"deprecated": true
61+
}
62+
}
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)