-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(codegen): strip names from enums #1837
Conversation
This adds an integration to strip names from enums that GA'd without them in order to preserve backwards compatibility.
@@ -0,0 +1,550 @@ | |||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QQ: How is this generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path baseDir = Paths.get(getClass().getResource("services").toURI());
Set<Pair<StringShape, EnumTrait>> hasNames = new HashSet<>();
Set<Pair<StringShape, EnumTrait>> noNames = new HashSet<>();
for (Path path : Files.list(baseDir).collect(Collectors.toSet())) {
Model model = Model.assembler()
.discoverModels()
.addImport(path)
.assemble()
.unwrap();
model.shapes(StringShape.class)
.flatMap(s -> Trait.flatMapStream(s, EnumTrait.class))
.forEach(pair -> {
if (pair.getRight().getValues().get(0).getName().isPresent()) {
hasNames.add(pair);
} else {
noNames.add(pair);
}
});
}
List<String> shapes = noNames.stream()
.map(pair -> pair.getKey().getId().toString())
.sorted()
.collect(Collectors.toList());
Path output = Paths.get("/tmp/enums-sans-names.json");
Files.write(output, Node.prettyPrintJson(Node.fromStrings(shapes)).getBytes());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet! Thanks so much for doing this. LGTM +1
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Description of changes:
This adds an integration to strip names from enums that GA'd without them in order to preserve backwards compatibility.
I also took the liberty of updating your checkstyle so that more recent copyright years can be used.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.