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

Gracefully handle invalid transaction flag values from server #82

Merged
merged 4 commits into from
Aug 29, 2024

Conversation

bradymholt
Copy link
Member

@bradymholt bradymholt commented Jul 16, 2024

The OpenAPI Generator, by default, throws an error if enum type data is received from the server that is not defined in the spec. In theory, the spec should always match what the server returns but in some cases there are unexpected values (new enum values not introduced in client, old enum values no longer in use, etc., bugs).

To work around this, we'll gracefully handle unsupported values by converting them to nil in the client, rather than throwing an error.

Fixes #81

@bradymholt bradymholt changed the title Gracefully handle invalid transaction flag value from server Gracefully handle invalid transaction flag values from server Jul 16, 2024
Copy link

@davidstosik davidstosik left a comment

Choose a reason for hiding this comment

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

Thank you for taking a look at this! ❤️
Just not sure this approach would stick, long-term. 🤔

return value
else
return nil
end
Copy link

@davidstosik davidstosik Jul 17, 2024

Choose a reason for hiding this comment

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

I'd expect these changes not to stick and a regression to happen as soon as the API Ruby code is regenerated from the OpenAPI spec file (for example using rake generate).

Is there a mechanism in place to prevent this kind of accidental regression to happen?

Note the comment at the top of most files:

Generated by: OpenAPI Generator (https://openapi-generator.tech)

Update: I had missed that you added a code generation template at templates/partial_model_enum_class.mustache! I didn't even know that was a thing.
I don't know how those templates get picked up by the generator (update again: here?), but that looks good to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes - that template should ensure the changes stay intact on next generation.

@bradymholt bradymholt merged commit a3855a2 into main Aug 29, 2024
1 check passed
@bradymholt bradymholt deleted the gracefully-handle-invalid-flag branch August 29, 2024 23:50
Copy link

The changes in this PR were just released in 3.6.0 🎉.

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.

Flag color validation fails on some existing transactions fetched through the API
2 participants