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

patternProperties in editor #811

Closed
svsolopov opened this issue Aug 19, 2020 · 9 comments
Closed

patternProperties in editor #811

svsolopov opened this issue Aug 19, 2020 · 9 comments

Comments

@svsolopov
Copy link

Object with patternProperties not show in editor

Direct link to example: https://json-editor.github.io/json-editor/

{
  "type": "object",
  "patternProperties": {
    "^[0-9]+$": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "pattern": "^[01]{1}$"
        }
      },
      "required": [
        "code"
      ]
    }
  },
  "additionalProperties": false
}

Valid result
{"0":{"code":"1"},"1":{"code":"1"},}

@schmunk42
Copy link
Collaborator

Could you elaborate further? I do not understand the problem.

@germanbisurgi
Copy link
Collaborator

hi @svsolopov

  1. correct format of json data (there is an extra comma at the end)
{
	"0": {
		"code": "1"
	},
	"1": {
		"code": "1"
	}
}
  1. use "additionalProperties": true

@theotherwillembotha
Copy link

I suspect what @svsolopov meant was that if one is to use "additionalProperties": true it allows for creating arbitrary properties, not just a property that fall within the defined patternProperties.

The original intention may have been that the "keys" are only allowed to be strings consisting of numbers, and all other keys (apart from those specified in the properties section) are invalid.

@germanbisurgi
Copy link
Collaborator

germanbisurgi commented Dec 11, 2020

The don't display because there are no properties defined in the schema and "additionalProperties" is set to false. If you set it to true and add properties with number keys it works

@theotherwillembotha
Copy link

I think my explanation is unclear.

This is the schema:

{
  "type": "object",
  "patternProperties": {
    "^[0-9]+$": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        }
      },
      "required": [
        "code"
      ]
    }
  },
  "additionalProperties": true
}

And this is the JSON.

{
  "12": {
    "code": "bang"
  },
  "16": {
    "code": "pop"
  },
  "foo": "fizz"
}

"foo" is valid because we allow additional properties, but it shouldn't be because it doesn't match the pattern "^[0-9]+$"

@germanbisurgi
Copy link
Collaborator

Now is clear, and yes the logic should be completed, based on this spec https://json-schema.org/understanding-json-schema/reference/object.html

robocoder added a commit to robocoder/json-editor that referenced this issue Feb 12, 2021
robocoder added a commit to robocoder/json-editor that referenced this issue Feb 12, 2021
@robocoder
Copy link
Contributor

(Kindly ignore my commits referencing this issue.)

additionalProperties needs to be true to allow properties that aren't explicit properties.

The proper fix would be to support propertyNames (introduced in version 6 of the spec).

@schmunk42
Copy link
Collaborator

The proper fix would be to support propertyNames (introduced in version 6 of the spec).

PRs welcome ;) we currently only fully support up to v4

robocoder added a commit to robocoder/json-editor that referenced this issue Feb 12, 2021
robocoder added a commit to robocoder/json-editor that referenced this issue Feb 12, 2021
@robocoder
Copy link
Contributor

Fixed by #915

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

No branches or pull requests

5 participants