private static final String generateTypeXSD = "xsd";
private static final String generateTypeYAML = "yaml";
-
+
private static final String root = "../aai-schema/src/main/resources";
private static final String xsd_dir = root + "/aai_schema";
private static final String yaml_dir = root + "/aai_swagger_yaml";
-
+
private static int annotationsStartVersion = 9; // minimum version to support annotations in xsd
private static int swaggerSupportStartsVersion = 7; // minimum version to support swagger documentation
-
+
private static XPath xpath = XPathFactory.newInstance().newXPath();
}
private static boolean validVersion(String versionToGen) {
-
+
if ("ALL".equalsIgnoreCase(versionToGen)) {
return true;
}
-
+
for (Version v : Version.values()) {
if (v.name().equals(versionToGen)) {
return true;
return false;
}
-
+
private static boolean versionUsesAnnotations( String version) {
if (new Integer(version.substring(1)).intValue() >= annotationsStartVersion ) {
return true;
}
return false;
}
-
+
private static boolean versionSupportsSwagger( String version) {
if (new Integer(version.substring(1)).intValue() >= swaggerSupportStartsVersion ) {
return true;
}
return false;
}
-
+
public static void main(String[] args) throws IOException {
String versionToGen = System.getProperty("gen_version").toLowerCase();
String fileTypeToGen = System.getProperty("gen_type").toLowerCase();
if ( fileTypeToGen == null ) {
fileTypeToGen = generateTypeXSD;
}
-
+
if ( !fileTypeToGen.equals( generateTypeXSD ) && !fileTypeToGen.equals( generateTypeYAML )) {
System.err.println("Invalid gen_type passed. " + fileTypeToGen);
System.exit(1);
}
-
-
+
+
if ( versionToGen == null ) {
System.err.println("Version is required, ie v<n> or ALL.");
- System.exit(1);
+ System.exit(1);
}
-
+
responsesUrl = System.getProperty("yamlresponses_url");
String responsesLabel = System.getProperty("yamlresponses_label");
List<Version> versionsToGen = new ArrayList<>();
-
+
if (!"ALL".equalsIgnoreCase(versionToGen) && !versionToGen.matches("v\\d+") && !validVersion(versionToGen)) {
System.err.println("Invalid version passed. " + versionToGen);
System.exit(1);
}
-
+
if ("ALL".equalsIgnoreCase(versionToGen)) {
versionsToGen = Arrays.asList(Version.values());
Collections.sort(versionsToGen);
}
if ( fileTypeToGen.equals(generateTypeYAML) ) {
- if ( responsesUrl == null || responsesUrl.length() < 1
+ if ( responsesUrl == null || responsesUrl.length() < 1
|| responsesLabel == null || responsesLabel.length() < 1 ) {
System.err.println("generating swagger yaml file requires yamlresponses_url and yamlresponses_label properties" );
System.exit(1);
responsesUrl = "description: "+ responsesLabel+ "(" + responsesUrl + ").\n";
}
String oxmPath = root + "/oxm/";
-
+
String outfileName;
File outfile;
String fileContent;
-
+
for (Version v : versionsToGen) {
apiVersion = v.toString();
System.out.println("Generating " + apiVersion + " " + fileTypeToGen);
}
outfile = new File(outfileName);
File parentDir = outfile.getParentFile();
- if(! parentDir.exists())
+ if(! parentDir.exists())
parentDir.mkdirs();
-
+
try {
outfile.createNewFile();
} catch (IOException e) {
}
System.out.println( "GeneratedXSD successful, saved in " + outfileName);
}
-
+
}
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
String namespace = "org.openecomp";
if ( useAnnotationsInXsd ) {
- sb.append("<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://" + namespace + ".aai.inventory/"
+ sb.append("<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://" + namespace + ".aai.inventory/"
+ apiVersion + "\" xmlns:tns=\"http://" + namespace + ".aai.inventory/" + apiVersion + "\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
+ "\n"
+ "xmlns:jaxb=\"http://java.sun.com/xml/ns/jaxb\"\r\n" +
" xmlns:annox=\"http://annox.dev.java.net\" \r\n" +
" jaxb:extensionBindingPrefixes=\"annox\">\n\n");
} else {
- sb.append("<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://" + namespace + ".aai.inventory/"
+ sb.append("<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://" + namespace + ".aai.inventory/"
+ apiVersion + "\" xmlns:tns=\"http://" + namespace + ".aai.inventory/" + apiVersion + "\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n\n");
}
case "Network":
case "ServiceDesignAndCreation":
case "Business":
+ case "LicenseManagement":
case "CloudInfrastructure":
break;
default:
sb.append("swagger: \"2.0\"\ninfo:\n description: |\n Copyright © 2017 AT&T Intellectual Property. All rights reserved.\n\n Licensed under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License.\n\n You may obtain a copy of the License at\n\n (https://creativecommons.org/licenses/by/4.0/)\n\n Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\n ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property.\n\n This document is best viewed with Firefox or Chrome. Nodes can be found by appending /#/definitions/node-type-to-find to the path to this document. Edge definitions can be found with the node definitions.\n version: \"" + apiVersion +"\"\n");
sb.append(" title: Active and Available Inventory REST API\n");
sb.append(" license:\n name: Apache 2.0\n url: http://www.apache.org/licenses/LICENSE-2.0.html\n");
+ sb.append(" contact:\n name:\n url:\n email:\n");
+ sb.append("host:\nbasePath: /aai/" + apiVersion + "\n");
sb.append("schemes:\n - https\npaths:\n");
/*
sb.append("responses:\n");