thema icon indicating copy to clipboard operation
thema copied to clipboard

Move schemas to the root of the json

Open undef1nd opened this issue 2 years ago • 3 comments

I guess it's better to illustrate what this PR does with an example:

before this PR schema is defined under $.components.schemas

{
    "openapi": "3.0.0",
    "info": {
        "title": "team",
        "version": "0.0"
    },
    "paths": {},
    "components": {
        "schemas": {
            "team": {
                "type": "object",
                "required": [
                    "name"
                ],
                "properties": {
                    "name": {
                        "description": "Name of the team.",
                        "type": "string"
                    }
                },
                "$schema": "http://json-schema.org/draft-04/schema#"
            }
        }
    }
}

This change moves the schema definition to the root of the JSON:

[
  {
    "team": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "description": "Name of the team.",
          "type": "string"
        }
      },
      "$schema": "http://json-schema.org/draft-04/schema#"
    }
  }
]

undef1nd avatar Jan 13 '23 16:01 undef1nd

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 13 '23 16:01 CLAassistant

From a JSON schema perspective I would expect an object with an $id at the root and $defs for subschemas.

{
    "$id": "http://example.com/schemas/0.0/team.json",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$defs": {
        "memberCount": { "type": "integer" }
    },
    "type": "object",
    "required": [
        "name"
    ],
    "properties": {
        "name": {
            "description": "Name of the team.",
            "type": "string"
        },
        "count": {
            "$ref": "#/$defs/memberCount"
        }
    }
}

This is more cleanly explained here: http://json-schema.org/understanding-json-schema/structuring.html

Duologic avatar Jan 16 '23 20:01 Duologic

is fixing this a blocker for fully automating our pipelines in grok, at least for grafonnet?

sdboyer avatar Jul 18 '23 13:07 sdboyer