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

generated code makeover #81

Merged
merged 13 commits into from
Dec 18, 2023
Merged

generated code makeover #81

merged 13 commits into from
Dec 18, 2023

Conversation

andreykaipov
Copy link
Owner

@andreykaipov andreykaipov commented Dec 18, 2023

This is a breaking change PR. While the usage of the client library remains the same, we introduce the following breaking changes:

  • Motivated by Make API values optional #27 and InputVolumeMul doesn't accept 0 volume #60, we make all the API values optional by making every primitive request field a pointer (i.e. *int, *string, *bool). This is because values like 0, "", false respectively are all potentially valid values in requests, but if intentionally set they'll just be omitted as every field is tagged with omitempty. We also simply can't remove omitempty from our request fields as it'll make them non-optional. The solution is to introduce pointers for these fields as now we can distinguish between present, not present, and intentional zero-value fields. In addition, to ease the UX for this, we introduce a new builder pattern for param structs:

      params := inputs.NewCreateInputParams().
      	WithSceneName(scene).
      	WithInputName(name).
      	WithInputKind(kind)
      resp, err := client.Inputs.CreateInput(params)
  • We simplify the generation code for complex types (like Object and Array<Object> in the protocol documentation) and try to address any missing types that were once just interface{} and map[string]any. The only fields that remain map[string]any are mostly *Settings ones which are generic enough to merit map[string]any.

    • TODO add mapstructure to all response structs so we can have a Remaining field in case any fields are missed.

      • actually on second thought idk if this is the right approach. think it would overcomplicate a lot of stuff. the motivation behind this is so that if there's a missing field from one of the response structs, a user can still access it (albeit through a map[string]any) without having to wait for me to update the library. maybe instead i can just expose the raw response? the user can then just parse it into a map[string]any themselves

        • The raw approach is what I've taken. Each response now has a GetRaw() json.RawMessage method that returns the bytes it got from the server for that response
  • Change the types for fields ending in Id or Index to be ints instead of floats.

  • And of course update the examples and the test generation accordingly to reflect the above.

@andreykaipov andreykaipov force-pushed the feature/makeover branch 2 times, most recently from 05ae5be to ffdf9ce Compare December 18, 2023 06:55
@andreykaipov andreykaipov changed the title generate all the request structs with optional fields generation makeover Dec 18, 2023
@andreykaipov andreykaipov changed the title generation makeover generated code makeover Dec 18, 2023
@andreykaipov
Copy link
Owner Author

andreykaipov commented Dec 18, 2023

generate check will fail because i don't want to clutter the PR view with the diff from the generated files just yet

@andreykaipov andreykaipov force-pushed the feature/makeover branch 2 times, most recently from ae17f83 to c88b2cb Compare December 18, 2023 16:44
@andreykaipov andreykaipov merged commit 24f7b0a into main Dec 18, 2023
@andreykaipov andreykaipov deleted the feature/makeover branch December 18, 2023 18:43
This was referenced Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant