package org.opendaylight.controller.sal.rest.doc.impl;
import static org.opendaylight.controller.sal.rest.doc.util.RestDocgenUtil.resolvePathArgumentsName;
-
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
public class BaseYangSwaggerGenerator {
- private static Logger _logger = LoggerFactory.getLogger(BaseYangSwaggerGenerator.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BaseYangSwaggerGenerator.class);
protected static final String API_VERSION = "1.0.0";
protected static final String SWAGGER_VERSION = "1.2";
List<Resource> resources = new ArrayList<>(modules.size());
- _logger.info("Modules found [{}]", modules.size());
+ LOG.info("Modules found [{}]", modules.size());
for (Module module : modules) {
String revisionString = SIMPLE_DATE_FORMAT.format(module.getRevision());
Resource resource = new Resource();
- _logger.debug("Working on [{},{}]...", module.getName(), revisionString);
+ LOG.debug("Working on [{},{}]...", module.getName(), revisionString);
ApiDeclaration doc = getApiDeclaration(module.getName(), revisionString, uriInfo, schemaContext, context);
if (doc != null) {
resource.setPath(generatePath(uriInfo, module.getName(), revisionString));
resources.add(resource);
} else {
- _logger.debug("Could not generate doc for {},{}", module.getName(), revisionString);
+ LOG.debug("Could not generate doc for {},{}", module.getName(), revisionString);
}
}
public ApiDeclaration getApiDeclaration(String module, String revision, UriInfo uriInfo, SchemaContext schemaContext, String context) {
Date rev = null;
+
try {
- rev = SIMPLE_DATE_FORMAT.parse(revision);
+ if(revision != null && !revision.equals("0000-00-00")) {
+ rev = SIMPLE_DATE_FORMAT.parse(revision);
+ }
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
+
+ if(rev != null) {
+ Calendar cal = new GregorianCalendar();
+
+ cal.setTime(rev);
+
+ if(cal.get(Calendar.YEAR) < 1970) {
+ rev = null;
+ }
+ }
+
Module m = schemaContext.findModuleByName(module, rev);
Preconditions.checkArgument(m != null, "Could not find module by name,revision: " + module + "," + revision);
List<Api> apis = new ArrayList<Api>();
Collection<DataSchemaNode> dataSchemaNodes = m.getChildNodes();
- _logger.debug("child nodes size [{}]", dataSchemaNodes.size());
+ LOG.debug("child nodes size [{}]", dataSchemaNodes.size());
for (DataSchemaNode node : dataSchemaNodes) {
if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
- _logger.debug("Is Configuration node [{}] [{}]", node.isConfiguration(), node.getQName().getLocalName());
+ LOG.debug("Is Configuration node [{}] [{}]", node.isConfiguration(), node.getQName().getLocalName());
List<Parameter> pathParams = new ArrayList<Parameter>();
String resourcePath = getDataStorePath("/config/", context);
resourcePath = getDataStorePath("/operational/", context);
addApis(node, apis, resourcePath, pathParams, schemaContext, false);
}
+ }
- Set<RpcDefinition> rpcs = m.getRpcs();
- for (RpcDefinition rpcDefinition : rpcs) {
- String resourcePath = getDataStorePath("/operations/", context);
- addRpcs(rpcDefinition, apis, resourcePath, schemaContext);
- }
+ Set<RpcDefinition> rpcs = m.getRpcs();
+ for (RpcDefinition rpcDefinition : rpcs) {
+ String resourcePath = getDataStorePath("/operations/", context);
+ addRpcs(rpcDefinition, apis, resourcePath, schemaContext);
}
- _logger.debug("Number of APIs found [{}]", apis.size());
+ LOG.debug("Number of APIs found [{}]", apis.size());
if (!apis.isEmpty()) {
doc.setApis(apis);
try {
models = jsonConverter.convertToJsonSchema(m, schemaContext);
doc.setModels(models);
- if (_logger.isDebugEnabled()) {
- _logger.debug(mapper.writeValueAsString(doc));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(mapper.writeValueAsString(doc));
}
} catch (IOException | JSONException e) {
e.printStackTrace();
List<Parameter> pathParams = new ArrayList<Parameter>(parentPathParams);
String resourcePath = parentPath + createPath(node, pathParams, schemaContext) + "/";
- _logger.debug("Adding path: [{}]", resourcePath);
+ LOG.debug("Adding path: [{}]", resourcePath);
api.setPath(resourcePath);
Iterable<DataSchemaNode> childSchemaNodes = Collections.<DataSchemaNode> emptySet();
SortedSet<Module> sortedModules = new TreeSet<>(new Comparator<Module>() {
@Override
- public int compare(Module o1, Module o2) {
- int result = o1.getName().compareTo(o2.getName());
+ public int compare(Module module1, Module module2) {
+ int result = module1.getName().compareTo(module2.getName());
if (result == 0) {
- result = o1.getRevision().compareTo(o2.getRevision());
+ Date module1Revision = module1.getRevision() != null ? module1.getRevision() : new Date(0);
+ Date module2Revision = module2.getRevision() != null ? module2.getRevision() : new Date(0);
+ result = module1Revision.compareTo(module2Revision);
}
if (result == 0) {
- result = o1.getNamespace().compareTo(o2.getNamespace());
+ result = module1.getNamespace().compareTo(module2.getNamespace());
}
return result;
}