1

Is it correct to make a definition (suppose with name "abc") and then refer to it from an attribute called "abc" whose type is "array"? Or it's incorrect and array and its items have to have different names?

Thanks!

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "newSchema.json",
  "title": "newSchema",
  "type": "object",
  "definitions": {
    "abc": {
      "properties": {
        "some_col": {
          "description": "hi",
          "type": "integer"
        }
      }
    }
  },
  "properties": {
    "abc": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/abc"
      }
    }
  }
}
Mary
  • 45
  • 8
  • This is fine. Is there anything that's lead you to wonder if it's OK or not specifically? If so, I may be able to point to a specific location in the specification to refute the concern. – Relequestual May 01 '19 at 11:17
  • It may LOOK better if the value under properties is `abcs`, as it's an array, but that's totally personal preference, and you may not have that option =] – Relequestual May 01 '19 at 11:18
  • I'm making an app which generates the schema based on SQL so I mark tables as "arrays" and was wondering whether I can name it same as table is originally named or I'd have to confuse user by naming the root attribute as "abc_t" and items "abc" or make a $ref named "abc_items" which may be a little confusing too. I guess I'll stay with "abc" in the end but if you have anything else to add - you're welcome to :) – Mary May 01 '19 at 15:12

1 Answers1

0

It's a totally valid JSON structure and JSON Schema setup.

If you intend for others to read your generated schemas, you could add annotations to them to give additional information, such as "This is an array of [table]" and "this object represents a row in [table]".

See the Schema Annotations section of the JSON Schema draft-7 validation specification.

Community
  • 1
  • 1
Relequestual
  • 11,631
  • 6
  • 47
  • 83