*/
package org.opendaylight.netconf.sal.rest.doc.impl;
-import static org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl.DEFAULT_PAGESIZE;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.TOP;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.buildDelete;
import static org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.buildGet;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Range;
import java.io.IOException;
-import java.net.URI;
import java.time.format.DateTimeParseException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.opendaylight.netconf.sal.rest.doc.swagger.Components;
import org.opendaylight.netconf.sal.rest.doc.swagger.Info;
import org.opendaylight.netconf.sal.rest.doc.swagger.OpenApiObject;
-import org.opendaylight.netconf.sal.rest.doc.swagger.Resource;
-import org.opendaylight.netconf.sal.rest.doc.swagger.ResourceList;
import org.opendaylight.netconf.sal.rest.doc.swagger.Server;
import org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject;
import org.opendaylight.netconf.sal.rest.doc.util.JsonUtil;
return schemaService;
}
- public ResourceList getResourceListing(final UriInfo uriInfo, final EffectiveModelContext schemaContext,
- final String context, final OAversion oaversion) {
- return getResourceListing(uriInfo, schemaContext, context, 0, true, oaversion);
- }
-
- /**
- * Return list of modules converted to swagger compliant resource list.
- */
- public ResourceList getResourceListing(final UriInfo uriInfo, final EffectiveModelContext schemaContext,
- final String context, final int pageNum, final boolean all,
- final OAversion oaversion) {
- final ResourceList resourceList = createResourceList();
-
- final Set<Module> modules = getSortedModules(schemaContext);
-
- final List<Resource> resources = new ArrayList<>(DEFAULT_PAGESIZE);
-
- LOG.info("Modules found [{}]", modules.size());
- final int start = DEFAULT_PAGESIZE * pageNum;
- final int end = start + DEFAULT_PAGESIZE;
- int count = 0;
- for (final Module module : modules) {
- final String revisionString = module.getQNameModule().getRevision().map(Revision::toString).orElse(null);
-
- LOG.debug("Working on [{},{}]...", module.getName(), revisionString);
- final SwaggerObject doc = getApiDeclaration(module.getName(), revisionString, uriInfo, schemaContext,
- context, oaversion);
- if (doc != null) {
- count++;
- if (count >= start && count < end || all) {
- final Resource resource = new Resource();
- resource.setPath(generatePath(uriInfo, module.getName(), revisionString));
- resources.add(resource);
- }
-
- if (count >= end && !all) {
- break;
- }
- } else {
- LOG.warn("Could not generate doc for {},{}", module.getName(), revisionString);
- }
- }
-
- resourceList.setApis(resources);
-
- return resourceList;
- }
-
public SwaggerObject getAllModulesDoc(final UriInfo uriInfo, final DefinitionNames definitionNames,
final OAversion oaversion) {
final EffectiveModelContext schemaContext = schemaService.getGlobalContext();
}
}
- public ResourceList createResourceList() {
- final ResourceList resourceList = new ResourceList();
- resourceList.setApiVersion(API_VERSION);
- resourceList.setSwaggerVersion(SWAGGER_VERSION);
- return resourceList;
- }
-
- public String generatePath(final UriInfo uriInfo, final String name, final String revision) {
- final URI uri = uriInfo.getRequestUriBuilder().replaceQuery("").path(generateCacheKey(name, revision)).build();
- return uri.toASCIIString();
- }
-
public CommonApiObject getApiDeclaration(final String module, final String revision, final UriInfo uriInfo,
final OAversion oaversion) {
final EffectiveModelContext schemaContext = schemaService.getGlobalContext();
true);
}
-
public SwaggerObject getSwaggerDocSpec(final Module module, final String context, final Optional<String> deviceName,
final EffectiveModelContext schemaContext, final OAversion oaversion,
final DefinitionNames definitionNames, final SwaggerObject doc,
public abstract String getResourcePathPart(String resourceType);
- private static String generateCacheKey(final String module, final String revision) {
- return module + "(" + revision + ")";
- }
-
private void addPaths(final DataSchemaNode node, final Optional<String> deviceName, final String moduleName,
final ObjectNode paths, final ArrayNode parentPathParams,
final EffectiveModelContext schemaContext, final boolean isConfig, final String parentName,
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. 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.swagger;
-
-import java.util.List;
-
-/**
- * Implementation of swagger spec (see <a href=
- * "https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#51-resource-listing"
- * > https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#51-
- * resource-listing</a>).
- */
-public class ResourceList {
- private String apiVersion;
- private String swaggerVersion;
- private List<Resource> apis;
-
- public String getApiVersion() {
- return apiVersion;
- }
-
- public void setApiVersion(String apiVersion) {
- this.apiVersion = apiVersion;
- }
-
- public String getSwaggerVersion() {
- return swaggerVersion;
- }
-
- public void setSwaggerVersion(String swaggerVersion) {
- this.swaggerVersion = swaggerVersion;
- }
-
- public List<Resource> getApis() {
- return apis;
- }
-
- public void setApis(List<Resource> apis) {
- this.apis = apis;
- }
-}