Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zserio Extension for JSON Schema Generation #2

Open
MisterGC opened this issue Jun 6, 2024 · 0 comments
Open

Zserio Extension for JSON Schema Generation #2

MisterGC opened this issue Jun 6, 2024 · 0 comments
Assignees
Milestone

Comments

@MisterGC
Copy link
Contributor

MisterGC commented Jun 6, 2024

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:

  1. Parse Zserio Schema: The extension should parse Zserio schema files, including resolving any imports.
  2. Type Mapping: Map Zserio types to corresponding JSON schema types (e.g., string to "type": "string", int32 to "type": "integer").
  3. Generate JSON Schema: For each specified Zserio type, generate a corresponding JSON schema definition.
  4. 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:

  1. Research existing tools and libraries for Zserio schema parsing and JSON schema generation.
  2. Design and implement the Zserio to JSON schema conversion tool within a Zserio extension.
  3. Allow users to specify a list of Zserio types for which JSON schemas should be generated.
  4. Test the tool with various Zserio schemas, including those with imports and complex types.
  5. Document the usage and integrate the tool into the project workflow.

References:

@MisterGC MisterGC added this to the First Release milestone Jun 19, 2024
@MisterGC MisterGC self-assigned this Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant