Skip to content

[JSON Schema] Add base Hydra properties to collection items definition #3803

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

Merged

Conversation

alanpoulain
Copy link
Member

@alanpoulain alanpoulain commented Oct 30, 2020

Q A
Bug fix? yes/no
New feature? no
BC breaks? no
Deprecations? no
Tickets N/A
License MIT
Doc PR N/A

This PR is part of a set of PR whose purpose is to make the assertions assertMatchesResourceItemJsonSchema and assertMatchesResourceCollectionJsonSchema work correctly.
The PR are:

It adds the base Hydra properties (@id, @type) to collection items definition in the JSON Schema.

Before:

{
   "$schema":"http:\/\/json-schema.org\/draft-07\/schema#",
   "type":"object",
   "definitions":{
      "Application:jsonld":{
         "type":"object",
         "description":"",
         "properties":{
            "id":{
               "readOnly":true,
               "type":"integer"
            },
            "name":{
               "type":"string"
            }
         }
      }
   },
   "properties":{
      "hydra:member":{
         "type":"array",
         "items":{
            "$ref":"#\/definitions\/Application:jsonld"
         }
      },
      "hydra:totalItems":{
         "type":"integer",
         "minimum":0
      },
      "hydra:view":{
         "type":"object",
         "properties":{
            "@id":{
               "type":"string",
               "format":"iri-reference"
            },
            "@type":{
               "type":"string"
            },
            "hydra:first":{
               "type":"string",
               "format":"iri-reference"
            },
            "hydra:last":{
               "type":"string",
               "format":"iri-reference"
            },
            "hydra:next":{
               "type":"string",
               "format":"iri-reference"
            }
         }
      },
      "hydra:search":{
         "type":"object",
         "properties":{
            "@type":{
               "type":"string"
            },
            "hydra:template":{
               "type":"string"
            },
            "hydra:variableRepresentation":{
               "type":"string"
            },
            "hydra:mapping":{
               "type":"array",
               "items":{
                  "type":"object",
                  "properties":{
                     "@type":{
                        "type":"string"
                     },
                     "variable":{
                        "type":"string"
                     },
                     "property":{
                        "type":"string"
                     },
                     "required":{
                        "type":"boolean"
                     }
                  }
               }
            }
         }
      }
   },
   "required":[
      "hydra:member"
   ]
}

After:

{
   "$schema":"http:\/\/json-schema.org\/draft-07\/schema#",
   "type":"object",
   "definitions":{
      "Application:jsonld":{
         "type":"object",
         "description":"",
         "properties":{
            "@id":{
               "readOnly":true,
               "type":"string"
            },
            "@type":{
               "readOnly":true,
               "type":"string"
            },
            "id":{
               "readOnly":true,
               "type":"integer"
            },
            "name":{
               "type":"string"
            }
         }
      }
   },
   "properties":{
      "hydra:member":{
         "type":"array",
         "items":{
            "$ref":"#\/definitions\/Application:jsonld"
         }
      },
      "hydra:totalItems":{
         "type":"integer",
         "minimum":0
      },
      "hydra:view":{
         "type":"object",
         "properties":{
            "@id":{
               "type":"string",
               "format":"iri-reference"
            },
            "@type":{
               "type":"string"
            },
            "hydra:first":{
               "type":"string",
               "format":"iri-reference"
            },
            "hydra:last":{
               "type":"string",
               "format":"iri-reference"
            },
            "hydra:next":{
               "type":"string",
               "format":"iri-reference"
            }
         }
      },
      "hydra:search":{
         "type":"object",
         "properties":{
            "@type":{
               "type":"string"
            },
            "hydra:template":{
               "type":"string"
            },
            "hydra:variableRepresentation":{
               "type":"string"
            },
            "hydra:mapping":{
               "type":"array",
               "items":{
                  "type":"object",
                  "properties":{
                     "@type":{
                        "type":"string"
                     },
                     "variable":{
                        "type":"string"
                     },
                     "property":{
                        "type":"string"
                     },
                     "required":{
                        "type":"boolean"
                     }
                  }
               }
            }
         }
      }
   },
   "required":[
      "hydra:member"
   ]
}

@alanpoulain alanpoulain force-pushed the fix/json-schema-hydra-collection branch from 72e2589 to 90bb11c Compare November 2, 2020 16:18
@soyuka soyuka merged commit f07b2f6 into api-platform:2.5 Nov 2, 2020
@soyuka
Copy link
Member

soyuka commented Nov 2, 2020

thanks @alanpoulain

@alanpoulain alanpoulain mentioned this pull request Dec 19, 2020
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.

2 participants