C
C
Cat Anton2020-11-07 14:27:44
JSON
Cat Anton, 2020-11-07 14:27:44

How to help PhpStorm correctly generate json for schema?

We have the following json schema:

{
    "$schema": "http://json-schema.org/draft/2019-09/schema#",
    "type": "object",
    "required": [
        "property_1",
        "property_2",
        "property_3"
    ],
    "properties": {
        "property_1": {
            "type": "boolean",
            "default": true
        },
        "property_2": {
            "enum": [
                null,
                "enum1",
                "enum2"
            ],
            "default": null
        },
        "property_3": {
            "type": "array",
            "default": ["string_1", "string_2"],
            "items": {
                "type": "string",
                "minLength": 1
            }
        }
    },
    "additionalProperties": false
}


Specified schema in JSON Schema Mapping settings.

This is the json generated by PhpStorm by default:

test.json

{
    "property_1": true,
    "property_2":,
    "property_3": []
}


For some reason, PhpStrom does not see the default for the last two properties and generates the wrong one.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question