-
-
Notifications
You must be signed in to change notification settings - Fork 130
Conversation
It looks like there are conflicts. |
Pull in @bunyk changes from upstream
Thanks very much for sending the PR through, I appreciate the effort. That said, I think the interface is too complicated. A more convenient interface would be something like a type Human struct {
Name string
Age int
Owner *Owner `jsonschema:"oneOf"`
Renter *Renter `jsonschema:"oneOf"`
}
type Owner struct {
YearsOwned int `jsonschema:"required"`
MortgagePaid bool
}
type Renter struct {
YearsRenting int `jsonschema:"required"`
PlanToOwn bool `jsonschema:"required"`
TypicalLeaseLength int
} Additionally, are you sure that human/owner/renter schema is valid? I tried it in a validator and could not get data to validate against it. The |
@alecthomas Hey, sorry for the delay. The schema I provided had Against the fixed schema above, these are valid inputs: Our owner
Our renter
The issue with utilizing
For example:
Actually I do realize there is a bug now that stems from the first point as I'd love to implement this via tags as I totally get that this is too complicated and not intuitive, but I'm not really sure of a clear and concise way to do so with the above issues in mind. |
I'm going to close this PR and break these apart since we're rapidly adding more to our master branch. |
@welps Did you ever get the point of finishing a smaller |
@williammartin I did not, the arguments I made above haven't changed. As far as I can tell, there are a few jsonschema concepts that aren't intuitively implementable solely with tags so I've continued to maintain this schism in https://github.com/discovery-digital/jsonschema/releases |
This PR adds
oneOf
support (which includes work from @bunyk that I accidentally blew away from squashing) and adds tagnotEmpty
which will add"pattern": "^\\S"
as a validation rule.This was implemented in a way to allow use of
oneOf
as a standalone object or as a property to existing definitions. The latter allows this to be used as a factoring agent where the parent structure can contain the common requirements andoneOf
defines the divergences.oneOf implementation
Standalone
oneOf
where we accept mutually exclusive schemasStruct implementation
Human
struct holds our common requirements withOwner
andRenter
encapsulating the two mutually exclusive sets of information we will take.Struct implementation (and use
jsonschema.Reflector
to enable additional properties)notEmpty tag
Using the tag
notEmpty
on astring
will now add the regex pattern^\\S+$
.Example struct
Output