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

V1 #290

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from
Draft

V1 #290

wants to merge 35 commits into from

Conversation

GREsau
Copy link
Owner

@GREsau GREsau commented May 12, 2024

Still to do:

  • Where we currently use a single-valued enum, instead use const (check which schema versions support const - may require a new visitor to change const to enum) - Use const instead of single-valued enum #291
  • Ensure compile times are OK for deriving JsonSchema on large types. Potentially reduce usages of json!/json_schema! for better performance, particularly in schemars_derive
  • Review doc comments
  • Update documentation
  • Review the behaviour of with/schema_with on enum variants - I think the current behaviour is inconsistent with how serde performs (de)serialization
  • move private Schema::flatten function to _private
  • flatten has been rewritten but I'm not confident that the new (or old tbh!) behaviour is correct in all cases- validate behaviour when flattening a normal struct into a struct with deny_unknown_fields
  • Regenerate schemas for tests and examples, remove TempFixupForTests
  • Re-add test coverage of different schema generator settings e.g. openapi3, since the schema_for_schema tests were previously removed
  • Maybe rename (and invert) is_referenceable() to always_inline()?
  • Maybe change JsonSchema::schema_name() to return a Cow<'static, str> instead of always an owned String?
  • Use $defs instead of definitions depending on json schema version
  • Consider re-adding something like the preserve_order feature flag to preserve field order in schemas
  • Support draft 2020-12, and use it by default
  • Consider making SchemaGenerator run visitors against definitions lazily again so that in general, a visitor can be run against any root schema and actually visit all subschemas. But what to do when definitions are not under definitions or $defs (e.g. in openapi3)?

Breaking changes (so far):

  • Methods that were deprecated are now removed
  • Schema is now defined as a wrapper around a serde_json::Value (which must be a Value::Bool or Value::Object), rather than a struct with a field for each JSON schema keyword (with some intermediary types). Schema is now available as schemars::Schema instead of schemars::schema::Schema, and all other types that were in the schemars::schema module have now been removed
    • functions that previously returned a RootSchema now just return a Schema
  • schemars no longer has its own Map/Set type aliases
    • The SchemaGenerator.definitions field is now a serde_json::Map<String, serde_json::Value> (ideally it would be some sort of Map<String, Schema>, but serde_json::Map only really works with a plain Value)
  • The impl_json_schema feature flag has been removed - JsonSchema is now always implemented on Schema
  • JsonSchema::schema_name() now returns Cow<'static, str> instead of String
  • JsonSchema::is_referenceable() has been removed, and replaced with JsonSchema::always_inline() which should returns the opposite value
  • All optional dependencies are now suffixed by their version:
    • chrono is now chrono04
    • either is now either1
    • smallvec is now smallvec1
    • url is now url2
    • bytes is now bytes1
    • rust_decimal is now rust_decimal1
    • enumset is now enumset1
    • smol_str is now smol_str02
    • semver is now semver1
    • indexmap, uuid08, arrayvec05 and bigdecimal03 have been removed
    • indexmap2, arrayvec07 and bigdecimal04 are unchanged
  • Remove the retain_examples field from SetSingleExample, which is now a unit struct
  • Newlines in doc comments are no longer collapsed when generating description
  • visit module and Visitor trait have been replace with transform and Transform respectively. Accordingly, these items have been renamed:
    • SchemaSettings::visitors -> SchemaSettings::transforms
    • SchemaSettings::with_visitor -> SchemaSettings::with_transform
    • SchemaGenerator::visitors_mut -> SchemaGenerator::transforms_mut
    • GenVisitor -> GenTransform
    • Visitor::visit_schema -> Transform::transform
      • visit_schema_object and visit_root_schema methods have been removed
    • visit::visit_schema -> transform::transform_subschemas
      • visit_schema_object and visit_root_schema functions have been removed

@GREsau GREsau marked this pull request as draft May 12, 2024 18:48
GREsau added 16 commits May 13, 2024 10:52
No longer use it for internally-tagged enums. Instead, use a private helper that adds the tag property.
This also changes the strategy for running visitors on subschemas - it is now done eagerly, as soon as they're added to the definitions map.
…efinitions` lazily (only if/when root schema is created).

Visitors will now always descend into `$defs`/`definitions`. If a generator is configured to use a different definitions path, then the visitor will also descend into that path (but a plain `Visitor` would NOT.
Since it's now the only method, there's no good reason to implement the trait without implementing that method.
I'm reasonably satisfied that the current behaviour of enum variants with `with`/`schema_with` attributes is correct
@GREsau GREsau marked this pull request as ready for review August 5, 2024 09:05
@GREsau GREsau marked this pull request as draft August 5, 2024 09:06
This means `SchemaSettings` and `SchemaGenerator` are both now `Send`
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

Successfully merging this pull request may close these issues.

None yet

1 participant