<artifactId>guava</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>mdsal-dom-api</artifactId>
<artifactId>yang-model-util</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.guicedee.services</groupId>
+ <artifactId>javax.inject</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.annotation</groupId>
+ <artifactId>jakarta.annotation-api</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.aaa.web</groupId>
<artifactId>web-api</artifactId>
+++ /dev/null
-/*
- * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.sal.rest.doc.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import javax.ws.rs.core.UriInfo;
-import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl.OAversion;
-import org.opendaylight.netconf.sal.rest.doc.swagger.CommonApiObject;
-import org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject;
-
-public class AllModulesDocGenerator {
- private final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040;
-
- public AllModulesDocGenerator(final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040) {
- this.apiDocGeneratorRFC8040 = requireNonNull(apiDocGeneratorRFC8040);
- }
-
- public CommonApiObject getAllModulesDoc(final UriInfo uriInfo, final OAversion oaversion) {
- final DefinitionNames definitionNames = new DefinitionNames();
- final SwaggerObject doc = apiDocGeneratorRFC8040.getAllModulesDoc(uriInfo, definitionNames, oaversion);
-
- return BaseYangSwaggerGenerator.getAppropriateDoc(doc, oaversion);
- }
-}
import static java.util.Objects.requireNonNull;
+import com.google.common.annotations.VisibleForTesting;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.netconf.sal.rest.doc.api.ApiDocService;
import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointSwagger;
import org.opendaylight.netconf.sal.rest.doc.swagger.CommonApiObject;
import org.opendaylight.netconf.sal.rest.doc.swagger.MountPointInstance;
+import org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
/**
* to work around this limitation, but given that this API is a dev only tool
* and not dependent UI, this was the fastest work around.
*/
-public class ApiDocServiceImpl implements ApiDocService {
-
+@Component
+@Singleton
+public final class ApiDocServiceImpl implements ApiDocService {
+ // FIXME: make this configurable
public static final int DEFAULT_PAGESIZE = 20;
+
// Query parameter
private static final String PAGE_NUM = "pageNum";
private final MountPointSwagger mountPointSwaggerRFC8040;
private final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040;
- private final AllModulesDocGenerator allModulesDocGenerator;
- public ApiDocServiceImpl(final MountPointSwaggerGeneratorRFC8040 mountPointSwaggerGeneratorRFC8040,
- final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040,
- final AllModulesDocGenerator allModulesDocGenerator) {
- mountPointSwaggerRFC8040 =
- requireNonNull(mountPointSwaggerGeneratorRFC8040).getMountPointSwagger();
+ @Inject
+ @Activate
+ public ApiDocServiceImpl(final @Reference DOMSchemaService schemaService,
+ final @Reference DOMMountPointService mountPointService) {
+ this(new MountPointSwaggerGeneratorRFC8040(schemaService, mountPointService),
+ new ApiDocGeneratorRFC8040(schemaService));
+ }
+
+ @VisibleForTesting
+ ApiDocServiceImpl(final MountPointSwaggerGeneratorRFC8040 mountPointSwaggerGeneratorRFC8040,
+ final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040) {
+ mountPointSwaggerRFC8040 = requireNonNull(mountPointSwaggerGeneratorRFC8040).getMountPointSwagger();
this.apiDocGeneratorRFC8040 = requireNonNull(apiDocGeneratorRFC8040);
- this.allModulesDocGenerator = requireNonNull(allModulesDocGenerator);
}
@Override
public synchronized Response getAllModulesDoc(final UriInfo uriInfo) {
- return Response.ok(allModulesDocGenerator.getAllModulesDoc(uriInfo, identifyOpenApiVersion(uriInfo))).build();
+ final OAversion oaversion = identifyOpenApiVersion(uriInfo);
+ final DefinitionNames definitionNames = new DefinitionNames();
+ final SwaggerObject doc = apiDocGeneratorRFC8040.getAllModulesDoc(uriInfo, definitionNames, oaversion);
+
+ return Response.ok(BaseYangSwaggerGenerator.getAppropriateDoc(doc, oaversion)).build();
}
/**
import javax.ws.rs.core.Application;
import org.opendaylight.netconf.sal.rest.doc.api.ApiDocService;
-public class ApiDocApplication extends Application {
+// FIXME: hide this class
+public final class ApiDocApplication extends Application {
private final ApiDocService apiDocService;
public ApiDocApplication(final ApiDocService apiDocService) {
*/
package org.opendaylight.netconf.sal.rest.doc.jaxrs;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.servlet.ServletException;
-import javax.ws.rs.core.Application;
import org.opendaylight.aaa.web.ResourceDetails;
import org.opendaylight.aaa.web.ServletDetails;
import org.opendaylight.aaa.web.WebContext;
import org.opendaylight.aaa.web.WebContextSecurer;
import org.opendaylight.aaa.web.WebServer;
import org.opendaylight.aaa.web.servlet.ServletSupport;
+import org.opendaylight.netconf.sal.rest.doc.api.ApiDocService;
import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
/**
* Initializes the wep app.
*
* @author Thomas Pantelis
*/
+@Singleton
+@Component(service = { })
public final class WebInitializer implements AutoCloseable {
private final Registration registration;
- public WebInitializer(final WebServer webServer, final WebContextSecurer webContextSecurer,
- final ServletSupport servletSupport, final Application webApp) throws ServletException {
- var webContextBuilder = WebContext.builder()
+ @Inject
+ @Activate
+ public WebInitializer(@Reference final WebServer webServer, @Reference final WebContextSecurer webContextSecurer,
+ @Reference final ServletSupport servletSupport, @Reference final ApiDocService apiDocService)
+ throws ServletException {
+ final var webContextBuilder = WebContext.builder()
.name("OpenAPI")
.contextPath("/apidoc")
.supportsSessions(true)
.addServlet(ServletDetails.builder()
- .servlet(servletSupport.createHttpServletBuilder(webApp).build())
+ .servlet(servletSupport.createHttpServletBuilder(new ApiDocApplication(apiDocService)).build())
.addUrlPattern("/swagger2/apis/*")
.addUrlPattern("/openapi3/apis/*")
.build())
}
@Override
+ @Deactivate
+ @PreDestroy
public void close() {
registration.close();
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
-Copyright © 2017 Inocybe Technologies and others. All rights reserved.
-
-This program and the accompanying materials are made available under the
-terms of the Eclipse Public License v1.0 which accompanies this distribution,
-and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
- <reference id="schemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
- <reference id="domMountPointService" interface="org.opendaylight.mdsal.dom.api.DOMMountPointService"/>
- <reference id="webServer" interface="org.opendaylight.aaa.web.WebServer"/>
- <reference id="webContextSecurer" interface="org.opendaylight.aaa.web.WebContextSecurer"/>
- <reference id="servletSupport" interface="org.opendaylight.aaa.web.servlet.ServletSupport" />
-
- <bean id="mountPointRFC8040" class="org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorRFC8040"
- destroy-method="close">
- <argument ref="schemaService" />
- <argument ref="domMountPointService" />
- </bean>
-
- <bean id="apiDocRFC8040" class="org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGeneratorRFC8040">
- <argument ref="schemaService" />
- </bean>
-
- <bean id="allModulesDoc" class="org.opendaylight.netconf.sal.rest.doc.impl.AllModulesDocGenerator">
- <argument ref="apiDocRFC8040" />
- </bean>
-
- <bean id="apiDocService" class="org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl">
- <argument ref="mountPointRFC8040" />
- <argument ref="apiDocRFC8040" />
- <argument ref="allModulesDoc" />
- </bean>
-
- <bean id="apiDocApplication" class="org.opendaylight.netconf.sal.rest.doc.jaxrs.ApiDocApplication">
- <argument ref="apiDocService" />
- </bean>
-
- <bean id="webInitializer" class="org.opendaylight.netconf.sal.rest.doc.jaxrs.WebInitializer"
- destroy-method="close">
- <argument ref="webServer"/>
- <argument ref="webContextSecurer"/>
- <argument ref="servletSupport"/>
- <argument ref="apiDocApplication"/>
- </bean>
-</blueprint>
new MountPointSwaggerGeneratorRFC8040(SCHEMA_SERVICE, service);
final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040 = new ApiDocGeneratorRFC8040(SCHEMA_SERVICE);
mountPointRFC8040.getMountPointSwagger().onMountPointCreated(INSTANCE_ID);
- final AllModulesDocGenerator allModulesDocGenerator = new AllModulesDocGenerator(apiDocGeneratorRFC8040);
- apiDocService = new ApiDocServiceImpl(mountPointRFC8040, apiDocGeneratorRFC8040, allModulesDocGenerator);
+ apiDocService = new ApiDocServiceImpl(mountPointRFC8040, apiDocGeneratorRFC8040);
}
@Test