JSON Schema autocompletion if/then/else array of objects properties

Hello,

I have the following scenario:

main.json:

```json

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"strategies": {
"type": "array",
"items": {
"allOf": [
{
"if": {
"properties": { "type": { "const": "line" } }
},
"then": {
"$ref": "strategy-line.json"
}
},
{
"if": {
"properties": { "type": { "const": "node" } }
},
"then": {
"$ref": "strategy-node.json"
}
}
]
}
}
}
}

```

strategy-line.json:

```json

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"type": {
"const": "line"
},
"line": {
"type": "string"
},
"lineNumber": {
"type": "integer"
},
"file": {
"type": "string"
},
"directory": {
"type": "string"
}
},
"required": [
"type",
"line",
"lineNumber",
"file"
]
}

```

strategy-node.json:

```json

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"type": {
"const": "node"
},
"directory": {
"type": "string"
}
},
"required": [
"type"
]
}

```

 

 

Is that a PHPStorm issue or is something wrong with the JSON-Schema?

The validation works btw:

1
5 comments

Where do you test this? Could you please attach a code/file? 

 

0
Avatar
Permanently deleted user

I've been playing with similar JSON Schemas and I have the same problem.

 

Here is the schema I am working with

{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://flowable.org/channel.json",
"type": "object",
"title": "The Event Channel Schema",
"description": "The Channel Schema",
"required": [
"key",
"channelType",
"type"
],
"properties": {
"key": {
"type": "string",
"minLength": 1,
"title": "Channel key",
"description": "The identifier for the channel"
},
"category": {
"type": "string",
"title": "Channel category",
"description": "Channel Category metadata"
},
"name": {
"type": "string",
"title": "Channel Name",
"description": "The name of the channel"
},
"description": {
"type": "string",
"title": "Channel Description",
"description": "The description of the channel"
},
"channelType": {
"type": "string",
"title": "Channel channel type",
"description": "The channel type of the channel. Default known types are inbound and outboud",
"enum": [
"inbound",
"outbound"
]
},
"type": {
"type": "string",
"title": "Channel type",
"description": "The type of the channel. Default known types are jms, kafka, rabbit",
"enum": [
"kafka",
"jms",
"rabbit"
]
}
},
"definitions": {
"inboundChannel": {
"properties": {
"deserializerType": {
"type": "string",
"title": "Deserializer",
"description": "The type of the deserializer",
"enum": [
"json",
"xml",
"expression"
]
},
"deserializerDelegateExpression": {
"type": "string",
"title": "Deserializer Delegate",
"description": "The deserializer delegate"
},
"payloadExtractorDelegateExpression": {
"type": "string",
"title": "Payload Extractor Delegate",
"description": "The payload extractor delegate"
},
"eventTransformerDelegateExpression": {
"type": "string",
"title": "Event Transformer Delegate",
"description": "The event transformer delegate"
},
"pipelineDelegateExpression": {
"type": "string",
"title": "Pipeline delegate expression Delegate",
"description": "The payload extractor delegate"
}
},
"required": [
"deserializerType"
]
},
"chanelEventKeyDetection": {
"type": "object",
"title": "Channel Event Key Detection",
"description": "An explanation about the purpose of this instance.",
"properties": {
"fixedValue": {
"type": "string",
"title": "Deserializer Delegate",
"description": "The deserializer delegate"
},
"jsonField": {
"type": "string",
"title": "Deserializer Delegate",
"description": "The deserializer delegate"
},
"jsonPointerExpression": {
"type": "string",
"title": "Deserializer Delegate",
"description": "The deserializer delegate"
},
"xmlXPathExpression": {
"type": "string",
"title": "Deserializer Delegate",
"description": "The deserializer delegate"
},
"delegateExpression": {
"type": "string",
"title": "Deserializer Delegate",
"description": "The deserializer delegate"
}
},
"anyOf": [
{
"required": [
"fixedValue"
]
},
{
"required": [
"jsonField"
]
},
{
"required": [
"jsonPointerExpression"
]
},
{
"required": [
"xmlXPathExpression"
]
},
{
"required": [
"delegateExpression"
]
}
]
},
"jmsInboundChannel": {
"properties": {
"destination": {
"type": "string",
"title": "JMS destination",
"description": "The JMS Destination (Queue) to listen to"
},
"selector": {
"type": "string",
"title": "JMS Message selector",
"description": "JMS Message selector for filtering which messages to received"
},
"subscription": {
"type": "string",
"title": "JMS Subscription name",
"description": "JMS name for the durable subscription"
},
"concurrency": {
"type": "string",
"title": "JMS Concurrency limit",
"description": "JMS Concurrency limit for the listener"
}
},
"required": [
"destination"
]
},
"rabbitInboundChannel": {
"properties": {
"queues": {
"type": "array",
"minItems": 1,
"title": "Rabbit Queue names",
"description": "The queue names to listen to"
},
"exclusive": {
"type": "boolean",
"title": "Rabbit Exclusive consumer",
"description": "Whether a single consumer in the container will have exclusive use of the queues, preventing other consumers from receiving messages from the queue(s)."
},
"priority": {
"type": "string",
"title": "Rabbit priority",
"description": "Priority of the Rabbit Endpoint"
},
"admin": {
"type": "string",
"title": "RabbitAdmin bean name",
"description": "The bean name of the custom RabbitAdmin bean that should be used"
},
"concurrency": {
"type": "string",
"title": "Rabbit Concurrency",
"description": "Rabbit Concurrency for the listener"
},
"executor": {
"type": "string",
"title": "Rabbit TaskExecutor bean name",
"description": "The bean name of the custom TaskExecutor that should be used for the Rabbit container"
},
"ackMode": {
"type": "string",
"title": "Rabbit Acknowledge mode",
"description": "The custom acknowledge mode for the Rabbit container. Overrides the one from the globally configured one"
}
},
"required": [
"queues"
]
},
"kafkaInboundChannel": {
"properties": {
"groupId": {
"type": "string",
"title": "Kafka group id",
"description": "The group id of the Kafka consumer"
},
"topics": {
"type": "array",
"minItems": 1,
"title": "Kafka topics",
"description": "The Kafka topics to listen to"
},
"topicPattern": {
"type": "string",
"title": "Kafka topics pattern",
"description": "The Kafka topic pattern to listen to"
},
"clientIdPrefix": {
"type": "string",
"title": "Kafka client id prefix",
"description": "The prefix for the Kafka client"
},
"concurrency": {
"type": "string",
"title": "Kafka Concurrency",
"description": "Kafka Concurrency for the listener"
},
"customProperties": {
"type": "array",
"title": "Kafka custom properties for the consumer",
"description": "Custom properties for the kafka consumer",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Kafka property name",
"description": "The name of the custom Kafka property"
},
"value": {
"type": "string",
"title": "Kafka property value",
"description": "The value of the custom Kafka property"
}
},
"required": [
"name",
"value"
]
}
}
},
"oneOf": [
{
"required": [
"topics"
]
},
{
"required": [
"topicPattern"
]
}
]
}
},
"oneOf": [
{
"if": {
"properties": {
"channelType": {
"const": "inbound"
}
}
},
"then": {
"allOf": [
{
"$ref": "#/definitions/inboundChannel"
},
{
"if": {
"properties": {
"type": {
"const": "jms"
}
}
},
"then": {
"$ref": "#/definitions/jmsInboundChannel"
}
},
{
"if": {
"properties": {
"type": {
"const": "rabbit"
}
}
},
"then": {
"$ref": "#/definitions/rabbitInboundChannel"
}
},
{
"if": {
"properties": {
"type": {
"const": "kafka"
}
}
},
"then": {
"$ref": "#/definitions/kafkaInboundChannel"
}
}
]
}
}
]
}

 

 

And here is an example test json for it.

 

{
"key": "test",
"channelType": "inbound",
"type": "kafka",
"deserializerType": "json",
"channelEventKeyDetection": {
"fixedValue": "reviewEvent"
},
"<caret>"
}

 

The validation is correct saying that there is a missing property `topics` or `topicPattern`. However, when you have the caret at `<caret>` it only suggests properties from the main schema definition. Does not suggest `topics`, `topicPattern`, `groupId`, `clientIdPrefix` etc.

 

If you change the `type` to `jms` there should be another missing property (`destination`) and other suggested properties.

 

Is this expected or is this in an issue?

 

This can easily be tested by adding the schema json from here as a manual Schema file and match the pattern for the example json. For example create the example in `example.channel` and use file pattern `*.channel`

0
Avatar
Permanently deleted user

I forgot to mention I am using IntelliJ IDEA. More specifically:

IntelliJ IDEA 2020.1 EAP (Ultimate Edition)
Build #IU-201.6251.22, built on March 12, 2020

0

Is there an update on this?

As said above, validation works properly but redirection into schema when clicking on those attributes or searches for new suggestions doesn't. Thanks in advances.

IntelliJ IDEA 2020.3 (Community Edition)
Build #IC-203.5981.155, built on November 30, 2020

0

It's a known issue unfortunately, please follow https://youtrack.jetbrains.com/issue/WEB-48859 for updates

0

Please sign in to leave a comment.