2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.util;
23 import java.io.IOException;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.ListIterator;
28 import org.onap.aai.setup.SchemaVersion;
29 import org.onap.aai.setup.SchemaVersions;
30 import org.onap.aai.util.swagger.GenerateSwagger;
32 import freemarker.template.TemplateException;
33 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
35 public class AutoGenerateHtml {
37 public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
38 //if the program is run from aai-common, use this directory as default"
39 public static final String ALT_SCHEMA_DIR = "aai-schema";
40 //used to check to see if program is run from aai-core
41 public static final String DEFAULT_RUN_DIR = "aai-core";
43 public static void main(String[] args) throws IOException, TemplateException {
44 String savedProperty = System.getProperty("aai.generate.version");
46 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
47 "org.onap.aai.config",
52 SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
54 List<SchemaVersion> versionsToGen = schemaVersions.getVersions();
55 Collections.sort(versionsToGen);
56 Collections.reverse(versionsToGen);
57 ListIterator<SchemaVersion> versionIterator = versionsToGen.listIterator();
59 if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
60 schemaDir = ALT_SCHEMA_DIR;
63 schemaDir = DEFAULT_SCHEMA_DIR;
65 String release = System.getProperty("aai.release", "onap");
66 while (versionIterator.hasNext()) {
67 System.setProperty("aai.generate.version", versionIterator.next().toString());
68 String yamlFile = schemaDir + "/src/main/resources/" + release + "/aai_swagger_yaml/aai_swagger_" + System.getProperty("aai.generate.version")+ ".yaml";
69 File swaggerYamlFile = new File(yamlFile);
70 if(swaggerYamlFile.exists()) {
71 GenerateSwagger.schemaVersions = schemaVersions;
72 GenerateSwagger.main(args);
75 String versionToGenerate = System.setProperty("aai.generate.version", savedProperty);