1f4b3b52c0e7c66a52d2f1723e5f2e1e2afa316b
[netconf.git] / restconf / sal-rest-docgen / src / main / java / org / opendaylight / netconf / 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.netconf.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.netconf.sal.rest.doc.swagger.ApiDeclaration;
14 import org.opendaylight.netconf.sal.rest.doc.swagger.ResourceList;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16
17 /**
18  * This class gathers all YANG-defined {@link org.opendaylight.yangtools.yang.model.api.Module}s and
19  * generates Swagger compliant documentation.
20  */
21 public class ApiDocGenerator extends BaseYangSwaggerGenerator {
22
23     private static final ApiDocGenerator INSTANCE = new ApiDocGenerator();
24     private SchemaService schemaService;
25
26     public ResourceList getResourceListing(final UriInfo uriInfo) {
27         Preconditions.checkState(schemaService != null);
28         final SchemaContext schemaContext = schemaService.getGlobalContext();
29         Preconditions.checkState(schemaContext != null);
30         return super.getResourceListing(uriInfo, schemaContext, "");
31     }
32
33     public ApiDeclaration getApiDeclaration(final String module, final String revision, final UriInfo uriInfo) {
34         final SchemaContext schemaContext = schemaService.getGlobalContext();
35         Preconditions.checkState(schemaContext != null);
36         return super.getApiDeclaration(module, revision, uriInfo, schemaContext, "");
37     }
38
39     /**
40      * Returns singleton instance.
41      */
42     public static ApiDocGenerator getInstance() {
43         return INSTANCE;
44     }
45
46     public void setDraft(final boolean newDraft) {
47         super.setDraft(newDraft);
48     }
49
50     public void setSchemaService(final SchemaService schemaService) {
51         this.schemaService = schemaService;
52     }
53 }