cwacek / python-jsonschema-objects

Automatic Python binding generation from JSON Schemas
MIT License
363 stars 96 forks source link

Can't define "type" in JSON #272

Closed kacperpaczos closed 10 months ago

kacperpaczos commented 10 months ago

Describe the bug I need:

"repository": {
      "type": "object",
      "properties": {
        "url": { "type": "string", "default": "https://example.com/your-username/my-new-project" },
        "type": { "type": "string", "default": "git" }
      }
    },

Like:

{
  "name": "my-new-project",
  "version": "1.0.0",
  "description": "My New Project description.",
  "main": "index.js",
  "repository": {
    "url": "https://example.com/your-username/my-new-project",
    "type": "git"
  },
  "author": "Your Name <you@example.com>",
  "license": "MIT"
}

But i have an error:

    raise error
jsonschema.exceptions.ValidationError: {'type': 'string'} is not valid under any of the given schemas

Failed validating 'anyOf' in schema['properties']['type']:
    {'anyOf': [{'$ref': '#/definitions/simpleTypes'},
               {'items': {'$ref': '#/definitions/simpleTypes'},
                'minItems': 1,
                'type': 'array',
                'uniqueItems': True}]}

On instance['type']:
    {'type': 'string'}
cwacek commented 10 months ago

The library expects the syntax of this to be the following:

{
    ...
    "type": "string",
    "default": "git",
    ...

. Can you point to a reference showing that "type": {"type": "string", "default": "git"} is valid syntax?

kacperpaczos commented 10 months ago

Can you point to a reference showing that "type": {"type": "string", "default": "git"} is valid syntax? I need the key name 'type' in the properties. How can I achieve this?

cwacek commented 10 months ago

Okay, I took your example and made a test out of it, and it works fine. See the example in the changes at https://github.com/cwacek/python-jsonschema-objects/pull/277/files.

Can you provide a specific example that doesn't work? Everything seems fine to me?

kacperpaczos commented 10 months ago

This issue exist in this project: https://github.com/kacperpaczos/Bennet

You need change vcs to type name in anvil_base_schema.json file: "repository": { "title": "repository", "type": "object", "properties": { "url": { "type": "string", "default": "https://example.com/your-username/my-new-project" }, "vcs": { "type": "string", "default": "git" } } },