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

Ensure oneOf exclusivity when merging schemas. #457

Merged
merged 20 commits into from
Jan 20, 2024
Merged

Ensure oneOf exclusivity when merging schemas. #457

merged 20 commits into from
Jan 20, 2024

Conversation

ahl
Copy link
Collaborator

@ahl ahl commented Dec 15, 2023

This is a work in progress, but it's pretty close.

  • As described in oneOf expansion is insufficiently exclusive #420, some generated types aren't enforcing sufficient exclusivity. We do seem to have a huge amount of generated json that's turning into huge doc comments. This seems like a problem and the doc comments aren't actually useful for types whose json is sort of fabricated rather than coming from the original document.
  • I've also got to figure out what to do about join_schemas which I've stopped using (for reasons that elude me).

Fixes #420.

Comment on lines +497 to +499
// We don't care if a property we're saying is not
// required was not present in the properties map.
let _ = properties.remove(not_required);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively we could do something like this:

let _ = properties.insert(not_required, Schema::Bool(false));

To indicate that this must not be present. The resulting types might be ugly or we could look for Option<Never> and do something different.

Comment on lines +1031 to +1035
// So. We merged the properties and we merged the array of
// properties that are required. We use the absence of a property
// in the properties map to indicate that the property must *not*
// be present. This is imprecise, but allows us to make progress
// without a most significant conversion to a new representation.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could change this to see if the property was invalid i.e. Schema::Bool(false)

typify-impl/tests/github.out Outdated Show resolved Hide resolved
Comment on lines +886 to +889
pub enum ShouldBeExclusive {
Variant0 { id: String },
Variant1 { reference: String },
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later it would be good if we could boil this down to

pub enum ShouldBeExclusive {
    Id(String),
    Reference(String),
}

@ahl ahl marked this pull request as ready for review January 20, 2024 06:10
@ahl ahl merged commit 16a4321 into main Jan 20, 2024
4 checks passed
@ahl ahl deleted the oneof-exclusion branch January 20, 2024 06:33
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.

oneOf expansion is insufficiently exclusive
1 participant