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

Add Enum constants to resource classes #516

Open
willselby opened this issue Jul 9, 2020 · 2 comments
Open

Add Enum constants to resource classes #516

willselby opened this issue Jul 9, 2020 · 2 comments
Assignees
Labels

Comments

@willselby
Copy link

Would it be possible to have the relevant enum values added as constants to the resource classes please?

Similar to what Stripe has;
https://github.com/stripe/stripe-php/blob/0aa6a385e66ffe7e095372737d8afe491a94e015/lib/Invoice.php#L130

This saves us having to do string comparisons when we want to check the value of a property.
e.g.
if ($invoice->state === 'paid') becomes if ($invoice->state === \Recurly\Resources\Invoice::STATE_PAID)

  • if the value is ever changed we don't need to update string comparisons in multiple places.
  • IDE can flag that the constant doesn't exist if one is removed or mis-typed.

I'd be happy to open a PR, but your contribution guidelines clearly state that you won't accept any PR's that modify resource files.

Thank you.

@bhelx bhelx self-assigned this Jul 9, 2020
@bhelx
Copy link
Contributor

bhelx commented Jul 9, 2020

@willselby We 100% agree with your reasoning for enum support. We should have enums in these places rather than strings.

I'd be happy to open a PR, but your contribution guidelines clearly state that you won't accept any PR's that modify resource files.

That's correct, that's the bad news. The good news is that we are already working on adding enum support into our code generator and we have it working for at least one other language. The same process which generates the resources from the OpenAPI spec will also generate, maintain, and document the enums for us. We've been holding off on implementing it because it's a breaking change for some languages, but we're going to be rolling it this quarter.

I'll leave this ticket open for now as a point of discussion. As soon as the code is ready in a branch, we'll come back here to ask for feedback. I'll try to prioritize getting PHP ready over the other languages since you've asked about it.

@willselby
Copy link
Author

That's great, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants