Merge "Bug 809: Enhancements to the toaster example"
[controller.git] / opendaylight / md-sal / sal-rest-docgen / src / main / java / org / opendaylight / controller / sal / rest / doc / impl / ApiDocServiceImpl.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.rest.doc.impl;
9
10 import org.opendaylight.controller.sal.rest.doc.api.ApiDocService;
11 import org.opendaylight.controller.sal.rest.doc.swagger.ApiDeclaration;
12 import org.opendaylight.controller.sal.rest.doc.swagger.ResourceList;
13
14 import javax.ws.rs.core.Response;
15 import javax.ws.rs.core.UriInfo;
16
17 /**
18  * This service generates swagger
19  * (See <a href="https://helloreverb.com/developers/swagger">https://helloreverb.com/developers/swagger</a>)
20  * compliant documentation for RESTCONF APIs. The output of this is used by embedded Swagger UI.
21  */
22 public class ApiDocServiceImpl implements ApiDocService {
23
24   private static final ApiDocService INSTANCE = new ApiDocServiceImpl();
25
26   public static ApiDocService getInstance(){
27     return INSTANCE;
28   }
29
30   /**
31    * Generates index document for Swagger UI. This document lists out all modules with link to get APIs for
32    * each module. The API for each module is served by <code> getDocByModule()</code> method.
33    *
34    * @param uriInfo
35    * @return
36    */
37   @Override
38   public Response getRootDoc(UriInfo uriInfo) {
39
40     ApiDocGenerator generator = ApiDocGenerator.getInstance();
41     ResourceList rootDoc = generator.getResourceListing(uriInfo);
42
43     return Response.ok(rootDoc).build();
44   }
45
46   /**
47    * Generates Swagger compliant document listing APIs for module.
48    *
49    * @param module
50    * @param revision
51    * @param uriInfo
52    * @return
53    */
54   @Override
55   public Response getDocByModule(String module, String revision, UriInfo uriInfo) {
56     ApiDocGenerator generator = ApiDocGenerator.getInstance();
57
58     ApiDeclaration doc = generator.getApiDeclaration(module, revision, uriInfo);
59     return Response.ok(doc).build();
60   }
61
62   /**
63    * Redirects to embedded swagger ui.
64    *
65    * @param uriInfo
66    * @return
67    */
68   @Override
69   public Response getApiExplorer(UriInfo uriInfo) {
70     return Response.seeOther(uriInfo.getBaseUriBuilder().path("../explorer/index.html").build()).build();
71   }
72 }