State parameter type design: String vs union type for API query parameters #54
SeanTAllen
started this conversation in
Research
Replies: 1 comment
-
|
PR #85 implemented The |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Several GitHub API endpoints accept a
statequery parameter that filters results by their status. The library currently passes these as plainStringvalues. This discussion explores whether introducing a union type (or similar mechanism) would be worthwhile.Where state-like parameters appear
Currently implemented
GetRepositoryIssuesstate"open","closed","all"Not yet implemented but will need this
GET /repos/{owner}/{repo}/pulls(list PRs)state"open","closed","all"GET /repos/{owner}/{repo}/milestones(list milestones)state"open","closed","all"GET /repos/{owner}/{repo}/issuessort"created","updated","comments"GET /repos/{owner}/{repo}/issuesdirection"asc","desc"GET /repos/{owner}/{repo}/pullssort"created","updated","popularity","long-running"GET /repos/{owner}/{repo}/pullsdirection"asc","desc"Response fields
The
Issuemodel already storesstateas(String | None)in the response. If we introduce a type for query params, should response fields use it too?Options
1. Keep as String (current approach)
Pros:
Cons:
"opne"compiles fine)2. Union type per parameter kind
Pros:
Cons:
Open/Closed/Allare very generic names; risk of collision with user code or future stdlib additions"all", butsortvalues differ between issues and PRs)3. Namespaced primitives
Pros:
Cons:
4. String with validation at construction boundary
Keep
Stringas the parameter type but validate inapply()and return aRequestErrorfor invalid values.Pros:
Cons:
Questions
sortanddirectionparameters follow the same pattern, or is this only forstate?Issue.state) use the same type as query parameters?Beta Was this translation helpful? Give feedback.
All reactions