Skip to content
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

Merged
merged 2 commits into from
Dec 23, 2020

Conversation

JordonPhillips
Copy link
Member

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.

This adds an integration to strip names from enums that GA'd without
them in order to preserve backwards compatibility.
@JordonPhillips JordonPhillips changed the title Add integration to strip names from enums that GA'd without them fix(enums): Add integration to strip names from enums that GA'd without them Dec 23, 2020
@trivikr trivikr changed the title fix(enums): Add integration to strip names from enums that GA'd without them fix(codegen): strip names from enums Dec 23, 2020
@@ -0,0 +1,550 @@
[
Copy link
Contributor

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?

Copy link
Member Author

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());

Copy link
Contributor

@alexforsyth alexforsyth left a 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

@JordonPhillips JordonPhillips merged commit 0711503 into aws:master Dec 23, 2020
@github-actions
Copy link

github-actions bot commented Jan 8, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants