Using Swagger-ui to Test CUBA-Rest Services

Hello,

i am wondering if it is possible to get swagger-ui to show all the webservices provided through the rest-api-addon.
I tried to integrate it into our application but i can’t seem to get it to show the services provided through the plugin.
How do i configure the swagger-ui to display all the services?

Hi,
can you please explain in more details what is your task?
URLs for getting general and project-specific swagger documentation are described in the here. So just run swagger UI and use the URL from the documentation.

Hi Max,

thanks for your reply, i’m trying to run swagger-ui in our application context. I’m able to open the ui under http://localhost:8080/app/dispatch/swagger-ui.html
but it just displays the following services


and not my custom rest-service or the cuba-rest-api.
I thought it should be possible to test my custom webservice through the swagger-ui

Maybe it’s not meant to do what i wanted.

What URL for swagger YAML file did you use? Was it something like http://localhost:8080/app/rest/v2/docs/swaggerDetailed.yaml?

I’m configuring swagger as a bean via:

@EnableSwagger2
@PropertySource(“classpath:/de/agentes/ksm/swagger.properties”)
public class SwaggerConfig {

@Bean
public Docket orderValidationApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .groupName("all")
            .apiInfo(metadata())
            .select().paths(PathSelectors.any())
            .build();
}

With swagger.properties:

springfox.documentation.swagger.v2.path=/swagger-api

Where should ich put the YAML?

You didn’t mention that you use springfox. Swagger UI bundled into springfox doesn’t allow to select a json/yaml file with the documentation.
If you want to see REST API addon controllers and your custom MVC controllers, then you need to register the SwaggerConfig bean in the spring context of the REST API (in the rest-dispatcher-spring.xml) file.

See the sample project: restapi-sample.zip (99.5 KB)

Swagger UI is available by URL http://localhost:8080/app/rest/swagger-ui.html

You’ll find REST API controllers (entities-controller, services-controller) and custom MVC controllers there.

Also you may run a standalone swagger-ui instance - download it from the swagger website and run it locally on your machine. In this case swagger ui will allow you to define a URL for swagger documentation file. If you use this: http://localhost:8080/app/rest/v2/docs/swaggerDetailed.yaml
then you’ll get project-specific swagger documentation:

Just in case, you have another option to test REST API. You may use Postman - it allows to import swagger JSON and YAML files.

2 Likes

I am so sorry, i didn’t know there was tha kind of difference in using springfox.
Thank you very much, i did miss the rest-dispacher-spring.xml settings in my project, now i’m able to do test what i wanted.