THIS EXTENSION IS INTENDED FOR INTERNAL USE BY AUSTRIAN POST AG ONLY
Generate C# from Avro Schema (VS Code Extension)
📄 Overview
This Visual Studio Code extension provides a quick way for schema authors to validate and generate C# code from Avro schema files (.avsc). By using the events-cli tool, this extension automates the process of converting Avro schema definitions into C# classes, making it easier to author and verify schemas.
✨ Features
Automatic C# Code Generation: Generates C# code from .avsc files using the events-cli tool.
Real-time Feedback: Displays generated code in a new preview window within VS Code.
Error Handling: Shows error messages in case of invalid Avro schema definitions or generation issues.
⚙️ Installation
Prerequisites
Install events-cli: Make sure the events-cli tool is installed on your system and available in your PATH.
Call the context-menu with Right-Click on .avsc file and choose Generate C# from Avro Schema.
By using Keybindings:
Open any Avro schema file (.avsc) in your VS Code editor.
Activate the command using Keybindings (Ctrl+Alt+W or Cmd+Alt+W/Cmd+Option+W on macOS).
In case the keybinding doesn't work properly for you - make sure you don't have any other command for that key-binding:
Ctrl+Shift+P or Cmd+Shift+P on macOS, Type Preferences: Open Keyboard Shortcuts and select it, in search bar enter Ctrl+Alt+W or Cmd+Alt+W/Cmd+Option+E on macOS
If the keybinding is already taken - you can either set up another available keybinding or also set the WHEN clause to "resourceFilename =~ /\\.avsc$/"/"resourceExtname == '.avsc'"
By using Command Palette of VS Code:
Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on macOS).
Search for or start typing in Command Palette >Generate C# from Avro Schema and select the command.
View the Generated C# Code:
The extension will execute the events-cli generate-types command and display the generated C# code for a selected .avsc file in a new preview window.
If there are any errors during the code generation, they will be shown in a VS Code error message.
🔧 Troubleshooting
events-cli is not installed or not available in the PATH. Please install it before proceeding. - If you see an error indicating events-cli is not found, ensure it is installed and in your system's PATH. Run events-cli --version to make sure it's installed.
No active editor or document found! - Ensure that a .avsc file is open in the editor when running the command using Keybinding or Command Palette.
Invalid Avro Schema: / Failed to generate code. Ensure your schema is correct. - If you encounter schema errors, manually validate your .avsc file to ensure it conforms to the Avro schema specification.
Sometimes the extension does not recognise the .avsc file even if it is open in an active Editor, in that case choose (click on) another file in your project and return again to the .avsc file, that will fix the issue.
The same issue can appear when trying to execute the command using keybindings.