-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for #57
- Loading branch information
Showing
19 changed files
with
466 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
*.yaml | ||
.idea/ | ||
**/*.iml | ||
target/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
cli/src/test/java/com/mrv/yangtools/codegen/main/Issue57.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.mrv.yangtools.codegen.main; | ||
|
||
import io.swagger.models.Swagger; | ||
import io.swagger.parser.SwaggerParser; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.kohsuke.args4j.CmdLineParser; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.net.URISyntaxException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class Issue57 { | ||
private static String path; | ||
|
||
static { | ||
try { | ||
path = Paths.get(Issue57.class.getResource("/bug_57/").toURI()).toAbsolutePath().toString(); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRegular() { | ||
|
||
List<String> args = Stream.of( | ||
"-yang-dir", | ||
path | ||
).collect(Collectors.toList()); | ||
|
||
Swagger swagger = runParser(args); | ||
assertContainsOnly(swagger, s -> s.endsWith("Input"), | ||
"objects.createobject.Input","objects.updateobject.Input"); | ||
} | ||
|
||
@Test | ||
public void testOptimized() { | ||
|
||
List<String> args = Stream.of( | ||
"-reuse-groupings", | ||
"-yang-dir", | ||
path | ||
).collect(Collectors.toList()); | ||
|
||
Swagger swagger = runParser(args); | ||
|
||
assertContainsOnly(swagger, s -> s.endsWith("Input"), "objects.createobject.Input"); | ||
} | ||
|
||
private void assertContainsOnly(Swagger swagger, Predicate<String> filterDefs, String... name) { | ||
Set<String> result = swagger.getDefinitions().keySet().stream() | ||
.filter(filterDefs) | ||
.collect(Collectors.toSet()); | ||
Set<String> expected = Stream.of(name) | ||
.collect(Collectors.toSet()); | ||
Assert.assertEquals(expected, result); | ||
} | ||
|
||
private Swagger runParser(List<String> args) { | ||
Main main = new Main(); | ||
CmdLineParser parser = new CmdLineParser(main); | ||
try { | ||
parser.parseArgument(args); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
main.out = baos; | ||
main.init(); | ||
main.generate(); | ||
|
||
return new SwaggerParser().parse(new String(baos.toByteArray(), StandardCharsets.UTF_8)); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module objects { | ||
|
||
yang-version "1.1"; | ||
namespace "urn:objects"; | ||
prefix "obje"; | ||
|
||
grouping id_1 { | ||
leaf id_1 { | ||
type "string"; | ||
} | ||
} | ||
|
||
grouping id_2 { | ||
leaf id_2 { | ||
type "string"; | ||
} | ||
} | ||
|
||
rpc create-object { | ||
input { | ||
uses id_1; | ||
uses id_2; | ||
} | ||
output { | ||
} | ||
} | ||
|
||
rpc update-object { | ||
input { | ||
uses id_1; | ||
uses id_2; | ||
} | ||
output { | ||
} | ||
} | ||
} |
Oops, something went wrong.