2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.rest.doc.impl;
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;
14 import javax.ws.rs.core.Response;
15 import javax.ws.rs.core.UriInfo;
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.
22 public class ApiDocServiceImpl implements ApiDocService {
24 private static final ApiDocService INSTANCE = new ApiDocServiceImpl();
26 public static ApiDocService getInstance(){
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.
38 public Response getRootDoc(UriInfo uriInfo) {
40 ApiDocGenerator generator = ApiDocGenerator.getInstance();
41 ResourceList rootDoc = generator.getResourceListing(uriInfo);
43 return Response.ok(rootDoc).build();
47 * Generates Swagger compliant document listing APIs for module.
55 public Response getDocByModule(String module, String revision, UriInfo uriInfo) {
56 ApiDocGenerator generator = ApiDocGenerator.getInstance();
58 ApiDeclaration doc = generator.getApiDeclaration(module, revision, uriInfo);
59 return Response.ok(doc).build();
63 * Redirects to embedded swagger ui.
69 public Response getApiExplorer(UriInfo uriInfo) {
70 return Response.seeOther(uriInfo.getBaseUriBuilder().path("../explorer/index.html").build()).build();