Merge "Reduce/enhance logging in AbstractLeader"
[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
17 /**
18  * This class gathers all yang defined {@link Module}s and generates Swagger compliant documentation.
19  */
20 public class ApiDocGenerator extends BaseYangSwaggerGenerator {
21
22     private static final ApiDocGenerator INSTANCE = new ApiDocGenerator();
23     private SchemaService schemaService;
24
25     public ResourceList getResourceListing(UriInfo uriInfo) {
26         Preconditions.checkState(schemaService != null);
27         SchemaContext schemaContext = schemaService.getGlobalContext();
28         Preconditions.checkState(schemaContext != null);
29         return super.getResourceListing(uriInfo, schemaContext, "");
30     }
31
32     public ApiDeclaration getApiDeclaration(String module, String revision, UriInfo uriInfo) {
33         SchemaContext schemaContext = schemaService.getGlobalContext();
34         Preconditions.checkState(schemaContext != null);
35         return super.getApiDeclaration(module, revision, uriInfo, schemaContext, "");
36     }
37
38     /**
39      * Returns singleton instance
40      *
41      * @return
42      */
43     public static ApiDocGenerator getInstance() {
44         return INSTANCE;
45     }
46
47     /**
48      *
49      * @param schemaService
50      */
51     public void setSchemaService(SchemaService schemaService) {
52         this.schemaService = schemaService;
53     }
54 }