-
-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to override @Deprecated? #747
Comments
First solution, you override SchemaPropertyDeprecatingConverter: @Component
public class DeprecatedPropertyCustomizer extends SchemaPropertyDeprecatingConverter {
@Override
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
if (chain.hasNext()) {
Schema<?> resolvedSchema = chain.next().resolve(type, context, chain);
if (type.isSchemaProperty() && containsDeprecatedAnnotation(type.getCtxAnnotations()) && !"myNonDeprecatedField".equals(type.getPropertyName()))
resolvedSchema.setDeprecated(true);
return resolvedSchema;
}
return null;
}
} Second solution, you use OpenApiCustomiser: @Bean
public OpenApiCustomiser sortSchemasAlphabetically() {
return openApi -> {
if (openApi.getComponents() != null) {
Schema schema = openApi.getComponents().getSchemas().get("DeprecatedEntity");
Map<String, Schema> properties = schema.getProperties();
Schema myNonDeprecatedFieldSchema = properties.get("myNonDeprecatedField");
myNonDeprecatedFieldSchema.setDeprecated(false);
}
};
} |
Thank you for the solutions. These solutions are based on the class and/or field name. I am trying to avoid duplicating 'magic' names and references to a field in other classes. If I would change the field name, then this functionality would stop working if I forget about it. The whole idea of using Swagger and |
The whole idea of springdoc-openapi is to get your documentation the closest to the code, with minimal code changes. Here, you want to declare a field on swagger as non deprecated, even with the java code, the field contains Additionally to the previous mentioned solutions, you can use the following property that will be available with the next release v1.4.3: springdoc.model-converters.deprecating-converter.enabled=false This property, will disable the |
I have a situation in which one of my setters has a
@java.lang.Deprecated
annotation on an entity. The field itself does not have this annotation.In swagger, in my schema/model, this fields ends up with the deprecated: true text. I did not expect that, and would like to avoid that.
I have tried overriding this with
@Schema(deprecated = false)
on both the setter and the field, but this does not seem to work. I assume that processing@Deprecated
is done by the springdoc library, although I'm not sure what part is springdoc and what part is swagger.Using springdoc-openapi 1.4.1. See attached project.
springdoc-issue-override-deprecated.zip
The text was updated successfully, but these errors were encountered: