Skip to content

Commit

Permalink
Release of 1.1.7
Browse files Browse the repository at this point in the history
Signed-off-by: Bartosz Michalik <[email protected]>
  • Loading branch information
bartoszm committed Mar 27, 2018
1 parent e381785 commit 002c1a2
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>yangtools</artifactId>
<groupId>com.mrv.yangtools</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>yangtools</artifactId>
<groupId>com.mrv.yangtools</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
30 changes: 30 additions & 0 deletions common/src/main/java/com/mrv/yangtools/common/SwaggerUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 Amartus. 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
*
* Contributors:
* Bartosz Michalik <[email protected]>
*/
package com.mrv.yangtools.common;

import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author [email protected]
*/
public class SwaggerUtils {
public static <T> Map<String, T> sortMap(Map<String, T> toSort) {
return toSort.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
},
LinkedHashMap::new));
}
}
2 changes: 1 addition & 1 deletion examples/build-standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>examples</artifactId>
<groupId>com.mrv.yangtools</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

import com.mrv.yangtools.codegen.SwaggerGenerator;
import com.mrv.yangtools.codegen.impl.SegmentTagGenerator;
import com.mrv.yangtools.codegen.impl.path.odl.ODLPathHandlerBuilder;
import com.mrv.yangtools.codegen.impl.path.rfc8040.PathHandlerBuilder;
import com.mrv.yangtools.codegen.impl.postprocessor.PathPrunner;
import com.mrv.yangtools.codegen.impl.postprocessor.RemoveUnusedDefinitions;
import com.mrv.yangtools.codegen.impl.postprocessor.SingleParentInheritenceModel;

import java.io.*;
Expand All @@ -26,8 +30,11 @@ public class YamlGenerator {

public static void main(String[] args) throws Exception {
SwaggerGenerator generator;
String outputName = "swagger.swagger";
if(args.length == 1) {
generator = GeneratorHelper.getGenerator(new File(args[0]),m -> !m.getName().contains("path-computation"));
File file = new File(args[0]);
outputName = args[0] + ".swagger";
generator = GeneratorHelper.getGenerator(file, m -> true);
} else {
generator = GeneratorHelper.getGenerator(m -> m.getName().startsWith("tapi"));
}
Expand All @@ -36,12 +43,21 @@ public static void main(String[] args) throws Exception {

generator
.tagGenerator(new SegmentTagGenerator())
.elements(SwaggerGenerator.Elements.RCP)
.appendPostProcessor(new SingleParentInheritenceModel());


generator.generate(new FileWriter("swagger.yaml"));
// generator.generate(new OutputStreamWriter(System.out));
//if you wish to generate only to specific tree depth
// .maxDepth(3)
//define element type
// .elements(SwaggerGenerator.Elements.RCP);
//define path handling type
// .pathHandler(new ODLPathHandlerBuilder().withoutFullCrud())
.pathHandler(new PathHandlerBuilder().withoutFullCrud())
//define path pruninng strategy
// .appendPostProcessor(new PathPrunner("/operations").withType("tapi.common.GlobalClass"))
//and single inheritence model
// .appendPostProcessor(new SingleParentInheritenceModel())
.appendPostProcessor(new RemoveUnusedDefinitions());


generator.generate(new FileWriter(outputName));

}
}
2 changes: 1 addition & 1 deletion examples/maven-plugin-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>examples</artifactId>
<groupId>com.mrv.yangtools</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>yangtools</artifactId>
<groupId>com.mrv.yangtools</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<groupId>com.mrv.yangtools</groupId>
<artifactId>yangtools</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>
<modules>
<module>swagger-generator</module>
<module>common</module>
Expand Down
2 changes: 1 addition & 1 deletion swagger-codegen-jaxrs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>yangtools</artifactId>
<groupId>com.mrv.yangtools</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion swagger-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>yangtools</artifactId>
<groupId>com.mrv.yangtools</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
import com.mrv.yangtools.codegen.impl.UnpackingDataObjectsBuilder;
import com.mrv.yangtools.codegen.impl.postprocessor.ReplaceEmptyWithParent;
import com.mrv.yangtools.codegen.impl.postprocessor.SortComplexModels;
import io.swagger.models.ComposedModel;
import com.mrv.yangtools.common.SwaggerUtils;
import io.swagger.models.Info;
import io.swagger.models.RefModel;
import io.swagger.models.Swagger;
import org.opendaylight.yangtools.yang.model.api.*;
import org.slf4j.Logger;
Expand Down Expand Up @@ -265,22 +264,14 @@ public void generate(Writer target) throws IOException {

new SortComplexModels().accept(result);

result.setDefinitions(sortMap(result.getDefinitions()));
result.setPaths(sortMap(result.getPaths()));
result.setDefinitions(SwaggerUtils.sortMap(result.getDefinitions()));
result.setPaths(SwaggerUtils.sortMap(result.getPaths()));

mapper.writeValue(target, result);
}


private <T> Map<String, T> sortMap(Map<String, T> toSort) {
return toSort.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
},
LinkedHashMap::new));
}


/**
* Run Swagger generation for configured modules.
Expand Down
2 changes: 1 addition & 1 deletion swagger-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>yangtools</artifactId>
<groupId>com.mrv.yangtools</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit 002c1a2

Please sign in to comment.