modelina
modelina copied to clipboard
JSON Schema enum pattern to define enum key and value with oneOf
Reason/Context
A new pattern emerged for JSON Schema that enable you to define enums with key and value.
Severity:
type: integer
oneOf:
- title: HIGH
const: 2
description: An urgent problem
- title: MEDIUM
const: 1
- title: LOW
const: 0
description: Can wait forever
Which expect to be rendered as the following:
public enum Source {
HIGH(2), MEDIUM(1), LOW(0);
}
But currently is split out into 3 enums:
public enum Low {
NUMBER_0((int)0);
private int value;
Low(int value) {
this.value = value;
}
...
}
To solve this I expect the following change is needed:
- We need to adapt the CommonModel to allow enums to be defined with key and value instead of just value.
- We need to adapt the CommonModel to MetaModel conversion to respect the new key and value
- We need to adapt the interpreter to look for this pattern in oneOf and anyOf, maybe a post process of the keyword interpretation we can merge all enums together.
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
@jonaslagoni still valid?
@AnimeshKumar923 yes, this is still valid.
I would like to work on this
Hey @jonaslagoni can you please share how one can reproduce or test this particular thing in local development.
You can use the following input:
{
"asyncapi": "2.5.0",
"info": {
"title": "Streetlights API",
"version": "1.0.0",
"description": "The Smartylighting Streetlights API allows you\nto remotely manage the city lights.\n",
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0"
}
},
"servers": {
"mosquitto": {
"url": "mqtt://test.mosquitto.org",
"protocol": "mqtt"
}
},
"channels": {
"light/measured": {
"publish": {
"summary": "Inform about environmental lighting conditions for a particular streetlight.",
"operationId": "onLightMeasured",
"message": {
"name": "LightMeasured",
"payload": {
"type": "object",
"$id": "LightMeasured",
"properties": {
"id": {
"type": "integer",
"minimum": 0,
"description": "Id of the streetlight."
},
"lumens": {
"type": "integer",
"oneOf": [
{
"title": "HIGH",
"const": 2,
"description": "An urgent problem"
},
{
"title": "MEDIUM",
"const": 1
},
{
"title": "LOW",
"const": 0,
"description": "Can wait forever"
}
]
},
"sentAt": {
"type": "string",
"format": "date-time",
"description": "Date and time when the message was sent."
}
}
}
}
}
}
}
}