swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Disable 'Try it out' button

Open peter004 opened this issue 13 years ago • 50 comments

How can I just disable 'Try it out' button for specific POST method?

Thanks in advance

peter004 avatar Feb 28 '13 22:02 peter004

Hi, currently this isn't supported, but you should be able to modify the json before calling swaggerUi.load();

fehguy avatar Mar 01 '13 06:03 fehguy

Disabling 'Try it out' button would be very useful in some situations.

vasiliysablin avatar Aug 18 '13 14:08 vasiliysablin

@woodoo wouldn't a static version of the documentation be a better solution when you don't want people trying it out? See here

fehguy avatar Aug 19 '13 16:08 fehguy

A hack would be to use a CSS selector setting display: none;

Xyand avatar Dec 04 '13 14:12 Xyand

I think this would be a good feature.

jchannon avatar Aug 12 '14 10:08 jchannon

+1

matiwinnetou avatar Sep 24 '14 12:09 matiwinnetou

agreed. There are cases where one can't really Try the API w/o making other call(s), or it's too much work for the service provider to setup dummy data for the TryIt function to work. Most 'Delete' operations fall into this bucket. It is still useful for the end user to see the operation (e.g. Delete) in the same locations as the other operations.

lluu avatar Sep 24 '14 21:09 lluu

+1 it's important for us to be able to disable this in production, whereas it's useful in dev and qa for testing.

defaultbob avatar Sep 25 '14 09:09 defaultbob

I see a problem with implementing this, but let's open this for a discussion. Perhaps together we can come up with a possible solution.

The problem I'm seeing here is that the Swagger specification is meant for API documentation, and Swagger-UI utilizes that documentation in order to display and execute the available API documentation.

Disabling the Try it out button is a functionality issue and not a documentation issue, so adding meta data on this in the Swagger documentation seems wrong. However, since most of you are not talking about all-or-nothing but want to disable specific operations, I'm not sure how those can be decided. We could possibly offer some kind of a generic way to define which operations should not be enabled for testing, but that would lead to a maintenance issue as it won't depend on the swagger specification served by the server exposing the API.

In Swagger 2.0 we could use the vendor extensions for this, but I'm reluctant to do so as it breaks the barrier between documentation and specific tool functionality. If we allow support for say x-swagger-ui-disable-execution: true, soon enough people would request the community libraries to support it inherently and it becomes de-facto part of the spec and not really a 'vendor extension'. This ends up blurring the boundary between documentation and functionality, which I don't like.

webron avatar Sep 25 '14 09:09 webron

@lluu "...too much work for the service provider to setup dummy data..."

This is a documentation and debug/testing tool. It is not the serice provider's job to setup dummy data. The developers should know (because the documentation tells them) that they cannot delete something that does not exist, so they first must PUT/POST to create the resource, then they can and should be able to DELETE it.

I don't see the issue here. Why do you want to disable things in only some cases? As long as it is documented well and the preconditions and error cases are documented, why not allow your developers to "Try it out"? What am I missing?

rage-shadowman avatar Sep 25 '14 18:09 rage-shadowman

Depending on organisations sometimes swagger endpoints are exposes in production for all users of a particular organisation but still internal in those orgs. In many cases we want to restrict that those users simply cannot invoke any state modifying methods. Swagger-ui is also easier to use instead of a static doc generation tool, therefore sometimes the only usecase you want to serve by using this single page webapp is - documentation, nothing less nothing more.

matiwinnetou avatar Sep 25 '14 18:09 matiwinnetou

@matiwinnetou Turning the button off completely can make sense to me. It's the partially-turned-off part that confuses me.

If the RESTful endpoint is accessible, then the user could just as easily run a curl script to execute that function. The user doesn't need the "Try it out" button to do it. If the endpoint really is internal, then it should be secured and the "Try it out" button should result in a 401 or 403 error if they don't have the required priveleges.

Otherwise it is even more broken than "security through obscurity" (since you aren't really obscuring anything and they now know exactly how to execute this function with curl).

rage-shadowman avatar Sep 25 '14 19:09 rage-shadowman

@rage-shadowman You are totally right and we discussed this use case, it is not that we are afraid of malicious users so much, rather somebody when it is too easy will be overusing this functionality. It is just we think - it will be way too easy for users to access try it out feature, it also doesn't make sense to me to have try it out exposed when we know this is something that doesn't work, hence would be nice to disable this with one property on swaggerUi javascript object. Sometimes a service may require authentication for state modifying methods and try it out would simply be failing all the time, which makes no sense. In some cases all methods would require auth but it does not change the fact that swagger docs (api-docs) could be exposed rather than secured as well. After all this is only information about service. Unfortunately I don't know very well Swagger-UI internally, is this a difficult feature to implement?

matiwinnetou avatar Sep 25 '14 19:09 matiwinnetou

@matiwinnetou - but how would you define which operations need to be disabled? "state modifying methods" is not good enough, as we can't really know which ones are state modifying. You can say that non-GET operations are state-modifying, but that's not necessarily true. I've seen people use POST for complex search queries (not saying I like it, saying it is done), and those are definitely not state modifying ops. We could allow for blocking it for specific HTTP methods and just say that it may be useful to some users, but I'm not sure that's the right way to go.

webron avatar Sep 25 '14 19:09 webron

@webron I would be fine to have a switch disable any method invocations, both non state modifying and state modifying at least for my requirements. I cannot speak for others (think static or read only mode).

matiwinnetou avatar Sep 25 '14 19:09 matiwinnetou

You mean all method invocations?

webron avatar Sep 25 '14 19:09 webron

@webron If there is still a verb-based disabler in v2.0 (GET/PUT/POST/DELETE) that might solve hist issue.

rage-shadowman avatar Sep 25 '14 19:09 rage-shadowman

@rage-shadowman, I'm not even aware of one prior to v2.0 (doesn't mean there isn't one). I suggested it may be possible to implement it, but I'm not sure it's the right approach.

webron avatar Sep 25 '14 19:09 webron

@webron In the version I'm still using (swagger-ui v2.0.3, based on older spec) there is a "supportedSubmitMethods" property for SwaggerUI that takes an array of verbs "['get', 'post', 'put', 'delete']".

rage-shadowman avatar Sep 25 '14 19:09 rage-shadowman

I don't see a reason it should be dropped, though as part of the migration some thing may accidentally get lost. If they do, just open an ticket :)

webron avatar Sep 25 '14 19:09 webron