Skip to content

Remove boilerplate code for enum conversion #59

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

Merged
merged 3 commits into from
Aug 17, 2020

Conversation

michel-tricot
Copy link
Contributor

What

JsonSchema duplicates enum definition which forces creating conversion methods. Let's streamline the conversion.

How

Convert enums from one enum to the next using name.

Tradeoff: static check becomes dynamic but this is alleviated by the fact that it is generated code.

If we want to keep the same exception message, let me know, I can create a overload with an exeptions generator. Right now the returned exception is:
java.lang.IllegalArgumentException: No enum constant io.dataline.commons.enums.EnumsTest.E2.TEST2

@michel-tricot michel-tricot requested a review from cgardens August 14, 2020 17:38
@@ -415,4 +315,33 @@ private SourceSchema toApiSchema(Schema persistenceSchema) {
apiSchema.setTables(persistenceTables);
return apiSchema;
}

private StandardSync.Status toPersistenceStatus(ConnectionStatus apiStatus) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have unit tests that assert the completeness of this conversion by iterating through all enum values? Then we can guarantee correctness for each version of generated code.

@cgardens
Copy link
Contributor

cool.

@michel-tricot michel-tricot merged commit 97a9dc2 into master Aug 17, 2020
@michel-tricot michel-tricot deleted the mt-add-helper-enums branch August 17, 2020 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants