Skip to content

Commit

Permalink
Add better validation for buf.gen.yaml input fields (#4196)
Browse files Browse the repository at this point in the history
* Add better validation for buf.gen.yaml input fields

* Add description, switch to anyOf, drop required

* Fix invalid v2 buf.gen.yaml fields

* Remove `format` from comment
  • Loading branch information
stefanvanburen authored Nov 6, 2024
1 parent 5d8cd28 commit 3235aa2
Show file tree
Hide file tree
Showing 2 changed files with 304 additions and 69 deletions.
368 changes: 302 additions & 66 deletions src/schemas/json/buf.gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://json.schemastore.org/buf.gen.json",
"$comment": "https://buf.build/docs/configuration/v2/buf-gen-yaml",
"$defs": {
"types": {
"description": "Include only the specified types when generating.",
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
},
"paths": {
"description": "Include only the specified paths when generating.",
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
},
"exclude_paths": {
"description": "Exclude the specified paths when generating.",
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
}
},
"title": "buf.gen.yaml",
"description": "buf.gen.yaml is a configuration file used by the buf generate command to generate integration code for the languages of your choice.",
"type": "object",
Expand Down Expand Up @@ -526,85 +552,295 @@
"description": "Optional. A list of inputs to generate code for.",
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"git_repo": {
"type": "string"
},
"branch": {
"type": "string"
},
"subdir": {
"type": "string"
},
"depth": {
"type": "integer",
"minimum": 1
},
"module": {
"type": "string"
},
"directory": {
"type": "string"
},
"tarball": {
"type": "string"
},
"compression": {
"type": "string"
},
"strip_components": {
"type": "integer"
},
"zip_archive": {
"type": "string"
},
"format": {
"type": "string"
"anyOf": [
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"directory": {
"description": "Specifies a local directory path as the input, with the location as the value. The path should be a valid module or workspace root, or a directory of Protobuf files. The path can be relative to the workspace or absolute.",
"type": "string"
}
}
},
"proto_file": {
"type": "string"
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"module": {
"description": "Specifies a remote BSR module as the input, with the location as the value. A commit or label can also be specified.",
"type": "string",
"examples": [
"buf.build/acme/weather",
"buf.build/acme/weather:main",
"buf.build/acme/weather:7abdb7802c8f4737a1a23a35ca8266ef"
]
}
}
},
"include_package_files": {
"type": "boolean",
"default": false
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"git_repo": {
"description": "Specifies a Git repo as the input, with the location as the key value. The path to the Git repository can be either a local .git directory or a remote location (http/https/ssh/git). Note that remote http://, https://, ssh://, and git:// locations must be prefixed with their scheme.",
"type": "string"
},
"branch": {
"description": "Use a specific branch of the repo as the input.",
"type": "string"
},
"tag": {
"description": "Use a specific commit or tag in the repo as the input.",
"type": "string"
},
"ref": {
"description": "Use an explicit reference in the repo as the input. Any valid input to git checkout is accepted, but most Git hosts (including GitHub) only allow fetching by reference and not commits by sha. Use git ls-remote --refs to get a list of available references and their corresponding commits.",
"type": "string"
},
"subdir": {
"description": "Use a specific subdirectory of the repo as the base directory of the input",
"type": "string"
},
"depth": {
"description": "Specifies how deep within the repo to generate. Defaults to 50 if ref is specified.",
"type": "integer",
"minimum": 1
},
"recurse_subdirectories": {
"description": "Controls whether to generate for modules recursively.",
"type": "boolean"
}
}
},
"binary_image": {
"type": "string"
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"tarball": {
"description": "Specifies a local or remote (http/https) tarball, with the location as the value. When generating, strip_components is applied before subdir.",
"type": "string"
},
"strip_components": {
"description": "Reads at the relative path and strips some number of components.",
"type": "integer"
},
"subdir": {
"description": "Reads at the relative path and uses the subdirectory specified within the archive as the base directory.",
"type": "string"
},
"compression": {
"description": "Compression is automatically detected if the file extension is .tgz, .tar.gz, or .tar.zst but can be manually specified here.",
"type": "string",
"enum": ["gzip", "zstd"]
}
}
},
"json_image": {
"type": "string"
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"zip_archive": {
"description": "Specifies a local or remote (http/https) zip archive, with the location as the value. When generating, strip_components is applied before subdir.",
"type": "string"
},
"strip_components": {
"description": "Reads at the relative path and strips some number of components.",
"type": "integer"
},
"subdir": {
"description": "Reads at the relative path and uses the subdirectory specified within the archive as the base directory.",
"type": "string"
}
}
},
"txt_image": {
"type": "string"
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
},
"paths": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
},
"exclude_paths": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
},
"proto_file": {
"description": "Specifies a single .proto file as the input, with the location as the value. The path can be relative to the workspace or absolute.",
"type": "string"
},
"include_package_files": {
"description": "Include all other files in the package and their imports for the specified .proto file.",
"type": "boolean"
}
}
},
"yaml_image": {
"type": "string"
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"binary_image": {
"description": "Specifies a Buf image in binary format as the input, with the location as the value.",
"type": "string"
},
"compression": {
"description": "Compression is automatically detected if the file extension is .gz or .zst but can be manually specified here.",
"type": "string",
"enum": ["gzip", "zstd"]
}
}
},
"types": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"json_image": {
"description": "Specifies a Buf image in JSON format as the input, with the location as the value.",
"type": "string"
},
"compression": {
"description": "Compression is automatically detected if the file extension is .gz or .zst but can be manually specified here.",
"type": "string",
"enum": ["gzip", "zstd"]
}
}
},
"paths": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"yaml_image": {
"description": "Specifies a Buf image in YAML format as the input, with the location as the value.",
"type": "string"
},
"compression": {
"description": "Compression is automatically detected if the file extension is .gz or .zst but can be manually specified here.",
"type": "string",
"enum": ["gzip", "zstd"]
}
}
},
"exclude_paths": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
{
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"types": {
"$ref": "#/$defs/types"
},
"paths": {
"$ref": "#/$defs/paths"
},
"exclude_paths": {
"$ref": "#/$defs/exclude_paths"
},
"txt_image": {
"description": "Specifies a Buf image in text format as the input, with the location as the value.",
"type": "string"
},
"compression": {
"description": "Compression is automatically detected if the file extension is .gz or .zst but can be manually specified here.",
"type": "string",
"enum": ["gzip", "zstd"]
}
}
}
}
]
}
}
}
Expand Down
Loading

0 comments on commit 3235aa2

Please sign in to comment.