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

Validate code samples against API schema #133

Open
razor-x opened this issue Nov 14, 2024 · 0 comments
Open

Validate code samples against API schema #133

razor-x opened this issue Nov 14, 2024 · 0 comments

Comments

@razor-x
Copy link
Collaborator

razor-x commented Nov 14, 2024

Code sample request and responses should validate against the actual API spec.

  • The responses are allowed to be missing "required" properties, since code samples intentionally omit some content for brevity.
  • Request and responses should validate property keys and types. If a key does not exist in the schema this is an error. And if the value does not match the expected shape, this is an error.

How to implement this? Few ideas:

  1. Use some existing openapi tool to validate the request / response data. As long as we can handle the "missing" response values, this seems like a good option. However, if the openapi spec is not "good enough" the validation might be too fragile.
  2. Since the types module exports zod types we could use those with .parse directly. This would work for the resources as long as we can apply a nested partial to the shapes (or ignore errors about missing required keys). To handle the request body, we would need to fill out the route schemas: https://github.com/seamapi/types/blob/bfbf26dc210dffed4cb37058ab915a6fda278f47/src/lib/seam/connect/index.ts#L9-L10
  3. Custom validation based on the blueprint. This is guaranteed to work, but is essentially a custom implementation of a schema validator.
    • Maybe this approach would work well if combined with (2). The resources all have good Zod types. While the request bodies are generally much simpler and we could generate zod types for them if they are not provided by the types module.
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

No branches or pull requests

1 participant