-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add ability to hide rest endpoints from OpenAPI schema / Swagger #40007
Comments
/cc @EricWittmann (openapi), @MikeEdgar (openapi,swagger-ui), @phillip-kruger (openapi,swagger-ui) |
We do not support the swagger annotations. Please use MicroProfile OpenAPI |
Example: if this is an operation you can do |
Thanks @phillip-kruger, this helps a lot! As stated in description of this issue, I was able to find a lot of resources describing swagger way and even more resources for SB. I looked into openapi for examples, I scraped https://github.com/eclipse/microprofile-open-api/blob/main/spec/src/main/asciidoc/microprofile-openapi-spec.asciidoc too, but nothing popped up. https://quarkus.io/guides/openapi-swaggerui guide could be extended with examples how to hide methods/endpoints and fields of returrned objects. |
Agree, we can definitely update the docs. We also have on our to-do list to add support for swagger annotations, but it has never really been a priority. See smallrye/smallrye-open-api#752 |
@rsvoboda this is already possible, but it is nowhere documented and I found it by accident. So it works something like this: import io.quarkus.runtime.StartupEvent;
import io.quarkus.runtime.rest.DisabledRestEndpoints;
import jakarta.enterprise.event.Observes;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import java.util.HashMap;
import java.util.List;
/**
* Removes the internal api's from the Swagger UI & OpenAPI yaml.
*/
public class SwaggerUiConfig {
@ConfigProperty(name = "swagger-ui.show-internal-apis")
boolean showInternalApis;
@ConfigProperty(name = "swagger-ui.disabled-paths")
List<String> disabledPaths;
public void init(@Observes StartupEvent event) {
if (!this.showInternalApis) {
var result = new HashMap<String, List<String>>();
this.disabledPaths.forEach(path -> result.put(path, List.of("DELETE", "POST", "PATCH", "PUT")));
DisabledRestEndpoints.set(result);
}
}
} application.properties: mp.openapi.filter=io.quarkus.smallrye.openapi.runtime.filter.DisabledRestEndpointsFilter
swagger-ui.show-internal-apis=false
%dev.swagger-ui.show-internal-apis=true
swagger-ui.disabled-paths=/v1/admin/fruits,/v1/management/fruits/ Note that the disabled-path names should match the path names in your openapi.yml. I hope this helps you. |
Thanks @Serkan80! It's good there a way to achieve this right now. |
@rsvoboda I'm afraid that to achieve this through annotation, is going to be hard, because this needs to be a part of the MP OpenApi specification. So everyone needs to agree on it, and this can take a while. For the time being, this solution is good enough for me. |
Have you looked at using |
@rsvoboda can we close this ? |
I've created #43593 to reference the spec from the guide so people can find |
Description
I'm unable to hide JAXRS methods in OpenAPI schema / Swagger.
For endpoints that are experimental or legacy ones I don't want them to be part of the generated schema. That schema serves as public contract in many cases.
I found
io.swagger.v3.oas.annotations.Hidden
annotation, but no equivalent of it in Quarkus OpenAPI extension.SB has ways to hide endpoints from the generated document even without using
@Hidden
annotation.Please add ability to hide rest endpoints from OpenAPI schema / Swagger.
Implementation ideas
No response
The text was updated successfully, but these errors were encountered: