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

Directive reports incorrect type when type keyword is nested under a oneOf #56

Closed
duncandewhurst opened this issue Oct 2, 2023 · 6 comments
Labels

Comments

@duncandewhurst
Copy link

I'm trying to add a jsonschema directive for the Record definition from the OCDS record package schema. However, the schema table incorrectly reports the type of releases as object when it should be array:

image

I think that's because the jsonschema directive defaults to object when there's no type keyword at the top-level of a property and the type keyword for releases is nested (and repeated) under a oneOf:

{
          "title": "Releases",
          "description": "All the releases about the contracting (or planning) process at the time of the record's publication. The releases must be sorted in date order, from oldest to newest.",
          "oneOf": [
            {
              "title": "Linked releases",
              "description": "A list of references to releases.",
              "type": "array",
              "items": {
                "$ref": "#/definitions/LinkedRelease"
              },
              "minItems": 1
            },
            {
              "title": "Embedded releases",
              "description": "A list of releases, with all the data.",
              "type": "array",
              "items": {
                "$ref": "https://standard.open-contracting.org/schema/1__1__5/release-schema.json"
              },
              "minItems": 1
            }
          ]
        }

I tried factoring the schema to move the type keyword to the top level of the releases property, but that causes the releases row to disappear altogether:

{
          "title": "Releases",
          "description": "All the releases about the contracting (or planning) process at the time of the record's publication. The releases must be sorted in date order, from oldest to newest.",
          "type": "array",
          "oneOf": [
            {
              "title": "Linked releases",
              "description": "A list of references to releases.",
              "items": {
                "$ref": "#/definitions/LinkedRelease"
              },
              "minItems": 1
            },
            {
              "title": "Embedded releases",
              "description": "A list of releases, with all the data.",
              "items": {
                "$ref": "https://standard.open-contracting.org/schema/1__1__5/release-schema.json"
              },
              "minItems": 1
            }
          ]
        }

image

@Bjwebb
Copy link
Member

Bjwebb commented Oct 12, 2023

There seem to be a few things going on here:

  1. This directive doesn't support oneOfs
  2. The directive assumes that a field is an object if its type is missing (although I think we rely on this elsewhere)
  3. A row for an array is only written out if it has an items property

Number 3 is easiest to fix, and will behave as you want if you do factor the schema. Does that work for you?

@jpmckinney
Copy link

Yes, we can factor the schema in this case.

@duncandewhurst
Copy link
Author

Works for me!

@Bjwebb
Copy link
Member

Bjwebb commented Oct 13, 2023

I've made a commit to do this. Could you give it a try by pip installing from this repo, e.g. pip install git+https://github.com/OpenDataServices/sphinxcontrib-opendataservices-jsonschema.git@56-array-row-missing#egg=sphinxcontrib-opendataservices-jsonschema

I'll write some tests, and get this ready for release.

@duncandewhurst
Copy link
Author

Looks good to me. Thanks!

image

@Bjwebb
Copy link
Member

Bjwebb commented Oct 23, 2023

This is now released in 0.6.1

@Bjwebb Bjwebb closed this as completed Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants