The xsd2proto command-line tool provides an easy way to convert XSD files to Protocol Buffer definitions.
xsd2proto [options] <input.xsd>
| Flag | Long Form | Description | Default |
|---|---|---|---|
-o |
--output |
Output file path | Input filename with .proto extension |
-p |
--package |
Go package option for generated proto file | None |
-v |
--verbose |
Enable verbose output | false |
-h |
--help |
Show help message | - |
--version |
Show version information | - | |
--no-header |
Disable auto-generation header comment | false | |
--camel-case |
Use camelCase for field names instead of snake_case | false | |
--pascal-case |
Use PascalCase for field names instead of snake_case | false |
Convert an XSD file to a protobuf file with the same base name:
xsd2proto schema.xsd
# Output: schema.protoSpecify a custom output file path:
xsd2proto -o /path/to/output.proto schema.xsdGenerate protobuf with a specific Go package option:
xsd2proto -p "github.com/example/proto" schema.xsdThis will add the following option to the generated proto file:
option go_package = "github.com/example/proto";Enable detailed logging during conversion:
xsd2proto -v schema.xsdExample verbose output:
Converting schema.xsd to protobuf...
Successfully parsed XSD schema with 3 elements, 5 complex types, 2 simple types
Successfully generated schema.proto
By default, generated proto files include a header comment indicating they were auto-generated:
To disable the header comment:
xsd2proto --no-header schema.xsdBy default, field names are converted to snake_case (e.g., firstName → first_name). You can choose alternative naming styles:
xsd2proto --camel-case schema.xsdThis will use camelCase formatting (e.g., firstName → firstName, postalCode → postalCode).
xsd2proto --pascal-case schema.xsdThis will use PascalCase formatting (e.g., firstName → FirstName, postalCode → PostalCode).
Note: You cannot use both --camel-case and --pascal-case options simultaneously.