-
Notifications
You must be signed in to change notification settings - Fork 0
Description
To enhance YAML support for Zserio within our project, we need an efficient way to generate JSON schema definitions directly from Zserio schemas. This JSON schema is required to utilize RedHat's YAML extension for VS Code, which significantly aids in authoring YAML files that are compatible with Zserio imports.
Requirements:
- Parse Zserio Schema: The extension should parse Zserio schema files, including resolving any imports.
- Type Mapping: Map Zserio types to corresponding JSON schema types (e.g.,
string
to"type": "string"
,int32
to"type": "integer"
). - Generate JSON Schema: For each specified Zserio type, generate a corresponding JSON schema definition.
- Output JSON Schema: Allow specifying a list of Zserio types for which schemas should be generated, with each type getting its own schema file. This enables activating/deactivating specific schemas in YAML configurations.
Key Features:
- Import Resolution: Handle Zserio imports to create comprehensive JSON schema definitions.
- Complex Types Support: Support for complex and nested Zserio types, including arrays and custom structs.
- Command-line Tool: A CLI tool that takes Zserio schema files as input and outputs the JSON schema for specified types.
- Integration with RedHat YAML Extension: Ensure the generated JSON schema is compatible with RedHat's YAML extension for VS Code.
Example:
For the given Zserio schema:
package person;
struct Person
{
string name;
string birthdate;
string birth_location;
string current_job;
int32 income;
RoleExperience experience[];
};
struct RoleExperience
{
string role;
int32 years;
};
If the user specifies Person
and RoleExperience
, the tool should generate JSON schemas similar to:
Person.json
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"birthdate": {
"type": "string"
},
"birth_location": {
"type": "string"
},
"current_job": {
"type": "string"
},
"income": {
"type": "integer"
},
"experience": {
"type": "array",
"items": {
"type": "object",
"properties": {
"role": {
"type": "string"
},
"years": {
"type": "integer"
}
}
}
}
}
}
RoleExperience.json
{
"type": "object",
"properties": {
"role": {
"type": "string"
},
"years": {
"type": "integer"
}
}
}
YAML Reference Example:
To use the generated JSON schemas in a YAML file, reference them as follows:
Person.yaml
# yaml-language-server: $schema=./Person.json
name: John Doe
birthdate: 1980-01-01
birth_location: New York
current_job: Engineer
income: 100000
experience:
- role: Developer
years: 5
- role: Manager
years: 3
Benefits:
- Efficiency: Streamlines the process of authoring YAML files compatible with Zserio.
- Accuracy: Reduces manual errors by automating the conversion from Zserio schema to JSON schema.
- Enhanced Support: Leverages the robust features of RedHat's YAML extension for a better development experience.
- Flexibility: Users can specify which Zserio types need JSON schemas, allowing selective activation/deactivation within YAML configurations.
Proposal:
Develop a Zserio extension to achieve the above functionality. This will greatly enhance our project's ability to support YAML and integrate seamlessly with popular development tools like VS Code.
Tasks:
- Research existing tools and libraries for Zserio schema parsing and JSON schema generation.
- Design and implement the Zserio to JSON schema conversion tool within a Zserio extension.
- Allow users to specify a list of Zserio types for which JSON schemas should be generated.
- Test the tool with various Zserio schemas, including those with imports and complex types.
- Document the usage and integrate the tool into the project workflow.
References: