Rohanil
Rohanil

Reputation: 1887

Why doesn't jsonschema validate following definition from schema?

I have definition as below. And it does not validate my_field_type_1 at all. What could be the reason? I am using jsonschema's python module.

definitions:
  TestRouteSchema1:
    required:
    - my_field
    properties:
      my_field:
        type: object
        my_field_type_1:
          $ref: "#/definitions/MyFieldType1"
        my_field_type_2:
          $ref: "#/definitions/MyFieldType2"

Upvotes: 0

Views: 580

Answers (1)

erosb
erosb

Reputation: 3141

You must nest my_field_type_1 and my_field_type_1 under a new properties key. So something like

definitions:
  TestRouteSchema1:
    required:
    - my_field
    properties:
      my_field:
        type: object
        properties:
          my_field_type_1:
            $ref: "#/definitions/MyFieldType1"
          my_field_type_2:
            $ref: "#/definitions/MyFieldType2"

Upvotes: 3

Related Questions