Add optional schemars (JsonSchema) derives to public models for API responses and OpenAPI generation#81
Conversation
|
@mrmauer let me know if you have any questions. This should be non-breaking and non-controversial :) |
|
Thanks for the PR, @shiftcontrol-dan! Especially with the great, detailed breakdown of all steps/tests/etc. We'll take a deeper look and circle back to you. |
…` for models and parameters. Update `Cargo.toml` to include dependencies for `schemars09` and `schemars-latest`.
… about elided lifetimes
…th `schemars09` and `schemars-latest`. Update all relevant models and APIs.
…, APIs, and `Cargo.toml`.
2f0c89e to
b113ad1
Compare
- Bump chrono from 0.4.39 to 0.4.44 - Upgrade jsonwebtoken from 9.3.0 to 10.3.0 with rust_crypto feature - Update url from ^2.2 to ^2.5 - Upgrade reqwest from ^0.12 to ^0.13 - Bump openssl dev dependency from 0.10.68 to 0.10.76 - Replace rustls-tls with rustls in rustls feature flag - Add reqwest/query to __reqwest feature dependencies - Maintain compatibility with existing schemars feature flags
|
@mrmauer any chance you guys will look at this? |
|
@shiftcontrol-dan, apologies for the big delay on this one. After some review, we don't plan to merge this in. We want to avoid layering external dependencies or additional development requirements for any reasons beyond the core functionality of the crate. Of course, I appreciate the operational burden for your team that you're trying to solve here. As another path to address that, you may be able to leverage our Postman collection's response types with a bit of parsing logic. |
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.