633d419fa9ae4219e2d276eb530fe4780514a88d
[controller.git] / opendaylight / md-sal / sal-rest-docgen / src / main / java / org / opendaylight / controller / sal / rest / doc / impl / ApiDocGenerator.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 com.google.common.base.Preconditions;
11 import javax.ws.rs.core.UriInfo;
12 import org.opendaylight.controller.sal.core.api.model.SchemaService;
13 import org.opendaylight.controller.sal.rest.doc.swagger.ApiDeclaration;
14 import org.opendaylight.controller.sal.rest.doc.swagger.ResourceList;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * This class gathers all yang defined {@link Module}s and generates Swagger compliant documentation.
21  */
22 public class ApiDocGenerator extends BaseYangSwaggerGenerator {
23
24     private static Logger _logger = LoggerFactory.getLogger(ApiDocGenerator.class);
25
26     private static final ApiDocGenerator INSTANCE = new ApiDocGenerator();
27     private SchemaService schemaService;
28
29     public ResourceList getResourceListing(UriInfo uriInfo) {
30         Preconditions.checkState(schemaService != null);
31         SchemaContext schemaContext = schemaService.getGlobalContext();
32         Preconditions.checkState(schemaContext != null);
33         return super.getResourceListing(uriInfo, schemaContext, "");
34     }
35
36     public ApiDeclaration getApiDeclaration(String module, String revision, UriInfo uriInfo) {
37         SchemaContext schemaContext = schemaService.getGlobalContext();
38         Preconditions.checkState(schemaContext != null);
39         return super.getApiDeclaration(module, revision, uriInfo, schemaContext, "");
40     }
41
42     /**
43      * Returns singleton instance
44      *
45      * @return
46      */
47     public static ApiDocGenerator getInstance() {
48         return INSTANCE;
49     }
50
51     /**
52      *
53      * @param schemaService
54      */
55     public void setSchemaService(SchemaService schemaService) {
56         this.schemaService = schemaService;
57     }
58 }