Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack.Swagger.Api supportedSubmitMethods

I have a service set up that uses ServiceStack.Swagger.Api. My service has several endpoints that support OPTIONS requests. Is there a way to configure the SwaggerAPI plugin to add 'options' to the js SwaggerUi.supportedSubmitMethods list in the index.html?

The options requests shows but the 'Try It Out' button does not exists because the supportedSubmitMethods doesn't have options in it.

*Using ServiceStack 4.5.6

like image 939
Dstum Avatar asked May 30 '26 11:05

Dstum


1 Answers

ServiceStack Swagger's embedded resource files are overridable using the Virtual File System so you can override Swagger UI's default index.html by taking a copy of index.html and adding it to your Host Project in the /swagger-ui/ folder, e.g:

/swagger-ui/index.html

Then modify your local copy of supportedSubmitMethods to include options, e.g:

window.swaggerUi = new SwaggerUi({
  url: url,
  dom_id: "swagger-ui-container",
  supportedSubmitMethods:['get', 'post', 'put', 'delete', 'patch', 'options'],
...

Note in the latest v4.5.8 Release if you have a lot of OPTIONS Services you can add it to the list of default verbs for Routes that don't explicitly specify an HTTP Verbs with:

Plugins.Add(new SwaggerFeature
{
     AnyRouteVerbs = { HttpMethods.Options },
});

Also if you're able to upgrade to v4.5.8 then you may want to consider switching to use the newer Open API Feature which implements v2.0 of the Open API specification which is the successor to Swagger.

like image 137
mythz Avatar answered Jun 02 '26 02:06

mythz