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
Spring Data Rest Documentation Question #834
Comments
You can achieve your goal by using @Component
public class OpenApiTagsCustomiser extends SpecFilter implements OpenApiCustomiser {
@Override
public void customise(OpenAPI openApi) {
// remove the property reference controller
openApi.getPaths().entrySet().removeIf(path -> path.getValue().readOperations().stream().anyMatch(
operation -> operation.getTags().stream().anyMatch(tag -> tag.endsWith("property-reference-controller"))));
// rename the operation tags
openApi.getPaths().values().stream().flatMap(pathItem -> pathItem.readOperations().stream())
.forEach(operation -> {
String tagName = operation.getTags().get(0);
// rename the entity-controller tags
if (tagName.endsWith("entity-controller")) {
String entityName = tagName.substring(0, tagName.length() - 18);
String myTagValue = "my-entity-" + entityName;
// Replace with the new tag value
operation.getTags().set(0, myTagValue);
}
// rename the search-controller tags
else if (tagName.endsWith("search-controller")) {
String entityName = tagName.substring(0, tagName.length() - 18);
String myTagValue = "my-search-" + entityName;
// Replace with the new tag value
operation.getTags().set(0, myTagValue);
}
});
removeBrokenReferenceDefinitions(openApi);
}
} |
Thanks for the in-depth example. BTW, is property referencing really a thing in Spring Data Rest API's? I get that impression for the generated docs. I'd like to share the video with you when the course goes live in about a month. Are you on LinkedIn? Here's my LinkedIn page: https://www.linkedin.com/in/mebowman. And my teaching website https://MaryEllenTeaches.me |
Hi @MiellyEllen, In fact property referencing is part of spring data rest: Here is sample about it: For the moment, it's generated by default for all entities on spring-data-rest. But what would be suitable for the projects, is to generate it dynamically, depending on the entity has relationships: : This is the ongoing enhancement about it: #792 It should be hopefully improved with the next release v1.4.5. Where we will introduce also the ability to add |
FYI, the version v1.4.5 is now released. |
Wow! Great improvement! |
In Fact, for your repositories you can use
For the profile-controller, it can be renamed, if needed using @Bean
OpenApiCustomiser OpenApiTagsCustomiser() {
return openApi -> openApi.getPaths().values().stream().flatMap(pathItem -> pathItem.readOperations().stream())
.forEach(operation -> {
String tagName = operation.getTags().get(0);
// rename the profile-controller tag
if ("profile-controller".equals(tagName)) {
// Replace with the new tag value
operation.getTags().set(0, "my-profile");
}
});
} |
Yep, the first thing I did was add @tag. happy to see it work. |
Is your feature request related to a problem? Please describe.
Question about how to better document Spring Data Rest Repositories
Describe the solution you'd like
I would like to override the "entityname"-entity-controller, "entityname"-search-controller tags and exclude the property apis.
Describe alternatives you've considered
Is there a way to do this without a code change
Additional context
I'm an instructor for LinkedIn Learning.https://www.linkedin.com/learning/instructors/mary-ellen-bowman. I'd like to include a demo of springdocs in one of my courses. I have MVC Controllers and Spring Data Rest Repositories. The MVC Controllers are easy to assign documentation with @tag, but I cannot figure out how to document my Spring Data REST API's better than what is generated by default.
The text was updated successfully, but these errors were encountered: