Skip to content

Commit

Permalink
Added property to override @deprecated. Fixes #747
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Jun 29, 2020
1 parent 5e05311 commit 7c24981
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gradle.properties
@@ -1,3 +1,5 @@
group = org.springdoc
version = 1.4.3-SNAPSHOT
org.gradle.daemon = true
org.gradle.caching=true
org.gradle.parallel=true
Expand Up @@ -70,6 +70,12 @@ public final class Constants {
*/
public static final String SPRINGDOC_ENABLED = "springdoc.api-docs.enabled";


/**
* The constant SPRINGDOC_DEPRECATING_CONVERTER_ENABLED.
*/
public static final String SPRINGDOC_DEPRECATING_CONVERTER_ENABLED = "springdoc.model-converters.deprecating-converter.enabled";

/**
* The constant SPRINGDOC_SCHEMA_RESOLVE_PROPERTIES.
*/
Expand Down
Expand Up @@ -426,6 +426,64 @@ public void setWriterWithDefaultPrettyPrinter(boolean writerWithDefaultPrettyPri
this.writerWithDefaultPrettyPrinter = writerWithDefaultPrettyPrinter;
}

/**
* The type Model converters.
*/
public static class ModelConverters {

/**
* The Deprecating converter.
*/
private DeprecatingConverter deprecatingConverter = new DeprecatingConverter();

/**
* Gets deprecating converter.
*
* @return the deprecating converter
*/
public DeprecatingConverter getDeprecatingConverter() {
return deprecatingConverter;
}

/**
* Sets deprecating converter.
*
* @param deprecatingConverter the deprecating converter
*/
public void setDeprecatingConverter(DeprecatingConverter deprecatingConverter) {
this.deprecatingConverter = deprecatingConverter;
}

/**
* The type Deprecating converter.
*/
public static class DeprecatingConverter {

/**
* The Enabled.
*/
private boolean enabled;

/**
* Is enabled boolean.
*
* @return the boolean
*/
public boolean isEnabled() {
return enabled;
}

/**
* Sets enabled.
*
* @param enabled the enabled
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
}

/**
* The type Webjars.
* @author bnasslahsen
Expand Down
Expand Up @@ -56,6 +56,7 @@
import org.springframework.context.annotation.Lazy;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;

import static org.springdoc.core.Constants.SPRINGDOC_DEPRECATING_CONVERTER_ENABLED;
import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
import static org.springdoc.core.Constants.SPRINGDOC_SCHEMA_RESOLVE_PROPERTIES;
import static org.springdoc.core.SpringDocUtils.getConfig;
Expand Down Expand Up @@ -141,6 +142,7 @@ ResponseSupportConverter responseSupportConverter() {
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = SPRINGDOC_DEPRECATING_CONVERTER_ENABLED, matchIfMissing = true)
@Lazy(false)
SchemaPropertyDeprecatingConverter schemaPropertyDeprecatingConverter() {
return new SchemaPropertyDeprecatingConverter();
Expand Down
@@ -0,0 +1,35 @@
package test.org.springdoc.api.app125;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* @author bnasslahsen
*/
public class DeprecatedEntity
{
@Schema(deprecated = false)
private String myNonDeprecatedField;

@Schema(deprecated = true)
private String mydeprecatedField;

public String getMyNonDeprecatedField()
{
return myNonDeprecatedField;
}

@Deprecated
public DeprecatedEntity setMyNonDeprecatedField(String myNonDeprecatedField)
{
this.myNonDeprecatedField = myNonDeprecatedField;
return this;
}

public String getMydeprecatedField() {
return mydeprecatedField;
}

public void setMydeprecatedField(String mydeprecatedField) {
this.mydeprecatedField = mydeprecatedField;
}
}
@@ -0,0 +1,19 @@
package test.org.springdoc.api.app125;

import javax.validation.constraints.NotNull;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author bnasslahsen
*/
@RestController
public class HelloController {

@GetMapping(value = "/search", produces = { "application/xml", "application/json" })
public DeprecatedEntity getAllPets(@NotNull String toto) {
return null;
}

}
@@ -0,0 +1,39 @@
/*
*
* *
* * *
* * * * Copyright 2019-2020 the original author or authors.
* * * *
* * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * you may not use this file except in compliance with the License.
* * * * You may obtain a copy of the License at
* * * *
* * * * https://www.apache.org/licenses/LICENSE-2.0
* * * *
* * * * Unless required by applicable law or agreed to in writing, software
* * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * See the License for the specific language governing permissions and
* * * * limitations under the License.
* * *
* *
*
*
*/
package test.org.springdoc.api.app125;

import test.org.springdoc.api.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.test.context.TestPropertySource;


/**
* Tests Spring meta-annotations as method parameters
*/
@TestPropertySource(properties = "springdoc.model-converters.deprecating-converter.enabled=false")
public class SpringDocApp125Test extends AbstractSpringDocTest {

@SpringBootApplication
static class SpringDocTestApp {}
}
@@ -0,0 +1,66 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost",
"description": "Generated server url"
}
],
"paths": {
"/search": {
"get": {
"tags": [
"hello-controller"
],
"operationId": "getAllPets",
"parameters": [
{
"name": "toto",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/xml": {
"schema": {
"$ref": "#/components/schemas/DeprecatedEntity"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/DeprecatedEntity"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"DeprecatedEntity": {
"type": "object",
"properties": {
"myNonDeprecatedField": {
"type": "string"
},
"mydeprecatedField": {
"type": "string",
"deprecated": true
}
}
}
}
}
}

0 comments on commit 7c24981

Please sign in to comment.