0

I am trying to use swagger with play framework.

I have added the API annotations in the code and i can access it via

localhost:9000/api-docs

{
    apiVersion: "beta",
    swaggerVersion: "1.2",
    basePath: "http://localhost",
    resourcePath: "/metrics",
    produces: [
      "application/json"
    ],
    apis: [
      {
         path: "/metrics",
         operations: [
            {
              method: "POST",
              summary: "Save metrics",
              ...
              authorizations: { },
              parameters: [ ],
              responseMessages: [
                 {
                    code: 400,
                    message: "Expecting Json data"
                 },
              ]
            }
         ]
      }
   ]
}

But when i try exploring it with the swagger ui, i am not able to expand or list operations.

In the swagger ui index.html, i made the following changes.

$(function () {
  var url = window.location.search.match(/url=([^&]+)/);
  if (url && url.length > 1) {
    url = url[1];
  } else {
    url = "http://localhost:9000/api-docs";
  }
...

  window.authorizations.add("Accept", new ApiKeyAuthorization("Accept", "application/json", "header"));

Am i missing any configurations. Please provide suggestions or pointers.

  • Which version of swagger-ui do you use? – Ron Jan 08 '15 at 09:29
  • I am using the latest version. Somehow i figured out the reason. There is a nickname field in the ApiOperation Annotation. That is required. If the nick name field is not configured, then we will not be able to expand operations. – Kousik Kumar Gopalan Jan 09 '15 at 04:52

1 Answers1

0

There were two issues.

  1. Base url was not configured properly. I added the following field in the the conf file to fix that.

    swagger.api.basepath="http://localhost:9000/"

  2. There is a nickname field in the ApiOperation Annotation. That is required. If the nick name field is not given, then we will not be able to expand operations in the the UI.