swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.42k stars 8.93k forks source link

Is there a way to disable/hide an endpoint in swagger file (json/doc/yamlConfig)? #6007

Open ghost opened 4 years ago

ghost commented 4 years ago

Hi,

I have generated a Swagger for an API consisting of both internal and external methods. The internal methods should not be consumed by external clients, and thus not exposed in my API Gateway afterwards.

I want to expose to my gateway just a white list of controllers/actions, I thought to update the swagger json/yaml config like this for example:

 "paths": {
     "/api/BankAccountApi/GetBankAccount": {
            "post": {
                  "tags": [
                      "internal"
                    ],
                    "hidden": true // this what I'm looking for

Is there a way to remove/hide/disable certain methods from swagger specification? Any annotations we could use, to flag methods as private or public or any alternative?

Thank you!

jjkcharles commented 4 years ago

might be a silly question, but, if you don't want your operations/methods to be consumed by external parties, can you not simply remove them from the swagger config (json/yaml) file?

paulmwatson commented 3 years ago

Being able to hide a path from the Swagger UI would be useful. Still accessible via the API just not shown in the UI. We have some "admin" paths we don't need to show our API users.

tarchiba commented 2 years ago

Any updates on this one? This seems like a feature miss within swagger-ui. @jjkcharles - your suggestion to remove definitions that should not be externally visible is not a good solution here. The code generation from the yaml/json files should align with the annotations supported - in this case the ability to hide endpoints. There are use cases where the definitions are used to generate the code vs. manually implementing the endpoint definitions in the classes via annotations and that is where the feature miss is here.

SimonLopez-Volue-MarketServices commented 2 years ago

Interested in this question as well. Seems no dev is on it.

ricmalta commented 2 years ago

During the API development this is a very useful feature to have, mainly when you are also using code generator which requires you to keep the spec for that purpose.

vijaykrajpoot commented 2 years ago

We are also looking same kind of feature to hide our admin from swagger ui. Is it done or in progress?

Kryan90 commented 2 years ago

+1 it would be awesome to be able to use the spec for request/response validation without including specific paths in the UI

geologyrocks commented 5 months ago

This would be so useful for us! We have API management service over the top of an API, and that APIM uses the Swagger to decide which API endpoints to permit access to.

heidererkatrin commented 4 months ago

Also looking for a solution for this. We are creating our API-Gateway with the same .yaml so it needs to include all the endpoints. however, I do not want to have all endpoints to be accessable by the Enduser. Also : For CORS I need to add OPTIONS route, and also want to hide this

himanshupareek commented 2 months ago

Anyone working on it??

NicolasNewman commented 1 week ago

Also looking for a solution for this. We are creating our API-Gateway with the same .yaml so it needs to include all the endpoints. however, I do not want to have all endpoints to be accessable by the Enduser. Also : For CORS I need to add OPTIONS route, and also want to hide this

I have the exact same use case with the OPTIONS route in API Gateway. Right now we're using an action to make a second copy that is served to end-users which is far from ideal.