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

additionalProperties and allOf together : how ? #837

Closed
ArthurLaudereau opened this issue Aug 8, 2018 · 1 comment
Closed

additionalProperties and allOf together : how ? #837

ArthurLaudereau opened this issue Aug 8, 2018 · 1 comment
Labels

Comments

@ArthurLaudereau
Copy link

ArthurLaudereau commented Aug 8, 2018

What version of Ajv are you using? Does the issue happen if you use the latest version?

6.5.2, yes

Ajv options object

{
allErrors: true,
schemaId: 'auto',
removeAdditional: true,
format: 'full'
}

JSON Schema

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "http://hl7.org/fhir/json-schema/Period",
  "$ref": "#/definitions/Period",
  "description": "see http://hl7.org/fhir/json.html#schema for information about the FHIR Json Schemas",
  "definitions": {
    "Period": {
      "allOf": [
        {
          "$ref": "Element#/definitions/Element"
        },
        {
          "additionalProperties": false,
          "properties": {
            "start": {
              "type": "string",
              "pattern": "-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?"
            },
            "end": {
              "type": "string",
              "pattern": "-?[0-9]{4}(-(0[1-9]|1[0-2])(-(0[0-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?"
            },
          }
        }
      ]
    }
  }
}

Sample data

{
    "id": "1",
    "start": "2000",
    "end": "2001",
    "foo": "qwqwqwqwqwq"
}

What results did you expect?

Start and End must be valid, the id should have made it too because it's defined in another schema named Element and referenced in the allOf but foo should be failing

Are you going to resolve the issue?

I tried so hard, but i could only have either start and end or id but not all three of them. The schema for Element is basically the same as Period, it just contains an id, and the same allOf

@epoberezkin
Copy link
Member

There are many ways it can be achieved, in all cases you would have to repeat all allowed property names on the top level. This question is not ajv specific, it is related to general JSON schema specification usage.

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

No branches or pull requests

2 participants