molgenis
Search…
Swagger specification
Swagger documentation can be divided into 2 sections:
  • REST API
  • Module specific controllers

How to use

The Swagger UI and the specification are served by the Swagger plugin.

Sending a request

Trying out the end points should be pretty straightforward. Each method is described, has a couple form elements that allow you to fill in request body and/or request parameters and at the bottom left you'll find a Try it out! button that will send the request to the server.

Specification of the REST API

The Molgenis REST API v1 and v2 are documented using the Swagger specification and you can browse the endpoints using the Swagger UI.
This is a work in progress and not all endpoints are fully documented yet.

Permissions

Admins can hand out plugin permissions on the Swagger plugin in the Permission Manager. Only users with view permission on the plugin can access the swagger specification. The specification uses enums for the entity_name parameter, and fills in the entities that the user can see.

URL

By default, the API documentation is added to the menu. If you remove it from the menu, users with plugin permissions can still access the plugin on the url <server>/plugin/swagger/.

Authorization

The Molgenis REST api supports two forms of authentication: The standard session token header and an x-molgenis-token header.

ApiKey

The Swagger 2 specification only supports ApiKey authorization. So the Molgenis Swagger plugin generates a Molgenis token and fills it in as the ApiKey in the Swagger UI. This token will then be added as an x-molgenis-token header by the Swagger UI to each request. You can view and edit the token by clicking the dark green Authorize button at the top of the page.
Api key authorization

Specification of module specific controllers

When you toggle the listbox in the header of the swagger documentation, you can choose different MOLGENIS-modules.
Swagger toggle modules
The workflow in swagger is pretty much the same as in the REST API documentation. Authentication does not work in this part of the MOLGENIS API documentation.

Contribute to module-API documentation

When you want to contribute to MOLGENIS and are developing a module, there are a few components that you have to configure.
  • Update module pom with swagger-maven-plugin:
    1
    <plugin>
    2
    <groupId>com.github.kongchen</groupId>
    3
    <artifactId>swagger-maven-plugin</artifactId>
    4
    <configuration>
    5
    <apiSources>
    6
    <apiSource>
    7
    <info>
    8
    <title>${project.name}</title>
    9
    <version>${project.version}</version>
    10
    <description>${project.description}</description>
    11
    </info>
    12
    <springmvc>true</springmvc>
    13
    <locations>
    14
    <location>#location of controller#</location>
    15
    </locations>
    16
    <swaggerDirectory>${build.directory}/generated-resources/swagger</swaggerDirectory>
    17
    <swaggerFileName>${project.name}-swagger</swaggerFileName>
    18
    </apiSource>
    19
    </apiSources>
    20
    </configuration>
    21
    <executions>
    22
    <execution>
    23
    <phase>compile</phase>
    24
    <goals>
    25
    <goal>generate</goal>
    26
    </goals>
    27
    </execution>
    28
    </executions>
    29
    </plugin>
    Copied!
  • Add module to view-swagger-ui.ftl
    1
    urls: [
    2
    { name: 'molgenis', url: '${molgenisUrl}' },
    3
    { name: 'core-ui', url: '${baseUrl}/swagger/core-ui-swagger.json'}
    4
    { name: '#module name from pom.xml#', url: '${baseUrl}/swagger/#module name from pom.xml#-swagger.json'}
    5
    ],
    Copied!
  • Add swagger-annotations dependency to module pom.xml
    1
    <dependency>
    2
    <groupId>io.swagger</groupId>
    3
    <artifactId>swagger-annotations</artifactId>
    4
    </dependency>
    Copied!
    Do not specify a version. The version is maintained by the master-pom.
  • Add annotations to controller
    1
    @Api("Example API")
    2
    @Controller
    3
    @RequestMapping(URI)
    4
    public class ExamplePluginController extends PluginController
    5
    {
    6
    7
    @ApiOperation("Example operation")
    8
    @ApiResponses({
    9
    @ApiResponse(code = 200, message = "This is an example operation", response = String.class)
    10
    })
    11
    @GetMapping
    12
    public String exampleOperation(@RequestParam(defaultValue = "false") boolean exmapleBoolean)
    13
    {
    Copied!
    For real life examples see the UserAccountController.java in MOLGENIS.
Last modified 1yr ago