Add optional schemars (JsonSchema) derives to public models for API responses and OpenAPI generation
#81
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds optional
schemars::JsonSchemaderives to key public structs in thepropelauthcrate, gated behind feature flags. This lets downstream users:aideandutoipawithout duplicating or regenerating models.When the feature is disabled (default), there is no behavior change and no additional dependency is pulled in.
Motivation
Today, users who want to expose
propelauthmodels (e.g., API key validation responses, user/org metadata) as handler return types and include them in API docs typically must:JsonSchemaderives; orThis is unnecessary duplication and a frequent source of drift and maintenance burden. These models already derive
Serialize/Deserializeand are good candidates for generating schemas. By makingJsonSchemaavailable behind optional features, users can:This is especially useful for endpoints managing API keys, users, and organizations where correctness and alignment are critical.
What’s changed
ValidatePersonalApiKeyResponse,ValidateOrgApiKeyResponse, andOrgMetadata.Feature flags and versions
schemars09: enables derives usingschemars0.9 API.schemars1: enables derives for the latest compatible schemars (forward-friendly).Only one should be enabled at a time. There is no default feature change.
Suggested downstream usage:
Or forward-looking:
Compatibility
Testing and validation
--features schemars09--features schemars1Alternatives considered
JsonSchemaderives: rejected due to duplication, drift, and maintenance cost.Performance and size impact
Security
Checklist
schemars09schemars1Thanks for considering this! This should remove the need for users to regenerate or duplicate structs just to return them from endpoints and include them in API docs, keeping implementations and documentation in lockstep.