Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move schemas to the root of the json #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

undef1nd
Copy link
Contributor

@undef1nd undef1nd commented Jan 13, 2023

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#"
    }
  }
]

Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com>
@CLAassistant
Copy link

CLAassistant commented Jan 13, 2023

CLA assistant check
All committers have signed the CLA.

@undef1nd undef1nd changed the title [WIP] Move schemas to the root of the json Move schemas to the root of the json Jan 14, 2023
Copy link
Contributor

@joanlopez joanlopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho, would be good to add at least few more test cases (with bit more complex cases of schema refs) but agree (and prefer) to merge this as-is and iterate later.

So, I'd say it LGTM! Although I'd wait for @sdboyer approval cause as I paired on part of these changes, I don't think I count as an actual reviewer.

@Duologic
Copy link
Member

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

Copy link
Contributor

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @Duologic that a $defs output is probably preferable, something along the lines of what he's output there.

I read into this a bit and got a bit stuck because it appears the $defs convention was only introduced in JSON Schema draft...10 i think? I can't remember exactly, but certainly later than draft 4/what we've been targeting here.

However, it's still valid in Draft 4, so in the absence of another convention, it's still probably the best way to organize the outputs.

This does shift the goalposts a bit on what we're actually trying to accomplish with hoisting schemas to the root. It deserves an issue with a more careful, precise writeup.

I'm hoping i can get to that in the latter half of this week.

@sdboyer
Copy link
Contributor

sdboyer commented Jul 18, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants