Schemas with multiple predicate-keys with different allowed values

143 views
Skip to first unread message

Tommi Reiman

unread,
Apr 3, 2015, 9:40:50 AM4/3/15
to prismatic...@googlegroups.com
hi.

tried to create a Schema-representation of the following JSON Schema element: 

"responses": {
  "type": "object",
  "description": "Response objects names can either be any valid HTTP status code or 'default'.",
  "minProperties": 1,
  "additionalProperties": false,
  "patternProperties": {
    "^([0-9]+)$|^(default)$": {
      "$ref": "#/definitions/response"
    },
    "^x-": {
      "$ref": "#/definitions/vendorExtension"
    }
  } 

, but it requires two predicate keys, which is not allowed.

(s/defschema Responses
  {(s/either (s/eq :default) s/Int) (s/maybe Response)
   #"x-" VendorExtension})

... which fails on validation with More than one non-optional/required key schemata: [(either (eq :default) Int) #"x-"]

could combine the two keys into single either and wrap values into either too, but that would allow ill combinations.

Any suggestions?

Tommi

Jason Wolfe

unread,
Apr 8, 2015, 5:17:13 PM4/8/15
to Tommi Reiman, prismatic-plumbing
Hi Tommi,

I don't think there's an easy way to do this with the provided
implementations of the Schema protocol -- of course, you should be
able to create your own implementation that operates this way.

Cheers,
Jason
> --
> You received this message because you are subscribed to the Google Groups
> "Plumbing and Graph: the Clojure utility belt" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to prismatic-plumb...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages