grpc-ecosystem/grpc-gateway

Example and pattern annotations are not respect for query and path parameters

Chiusa

#4130 aperta il 22 mar 2024

 (9 commenti) (0 reazioni) (0 assegnatari)Go (2250 fork)batch import
bughelp wantedopenapi

Metriche repository

Star
 (16.971 stelle)
Metriche merge PR
 (Merge medio 8g 23h) (147 PR mergiate in 30 g)

Descrizione

🐛 Bug Report

Using the sample proto below, only default appears in the output json - example and pattern do not.

To Reproduce

message GetTileForImageRequest {
	// The unique reference number of the image.
	string image_urn = 1 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
		example: "urn:eagleview.com:v4:spatial-data:raster:visual:ated:QIgDbfZw-kqKfTxbMQXwhw:0",
		default: "urn:eagleview.com:v4:spatial-data:raster:visual:ated:QIgDbfZw-kqKfTxbMQXwhw:0",
		pattern: "^(urn:eagleview\\.com:v\\d+:spatial-data:\\w+:\\w+:\\w+:[A-Za-z0-9-_]+):(\\d+)$",
	}];
}

I'm using buf to generate the swagger using the following template:

buf.gen.swagger.yaml:

version: v1
plugins:
  - name: openapiv2
    out: build/go
    opt:
      - json_names_for_fields=false
      - visibility_restriction_selectors=LATEST
$ buf generate --template buf.gen.swagger.yaml --path proto/evt/iw/service

Expected behaviour

{
  "name": "image_urn",
  "description": "The unique reference number of the image.",
  "in": "path",
  "required": true,
  "type": "string",
  "example": "urn:eagleview.com:v4:spatial-data:raster:visual:ated:QIgDbfZw-kqKfTxbMQXwhw:0",
  "default": "urn:eagleview.com:v4:spatial-data:raster:visual:ated:QIgDbfZw-kqKfTxbMQXwhw:0",
  "pattern": "^(urn:eagleview\\.com:v\\d+:spatial-data:\\w+:\\w+:\\w+:[A-Za-z0-9-_]+):(\\d+)$"
}

Actual Behavior

{
  "name": "image_urn",
  "description": "The unique reference number of the image.",
  "in": "path",
  "required": true,
  "type": "string",
  "default": "urn:eagleview.com:v4:spatial-data:raster:visual:ated:QIgDbfZw-kqKfTxbMQXwhw:0"
}

Your Environment

$ uname -a
Linux 0664eeb787b5 5.14.0-1049-oem #56-Ubuntu SMP Fri Aug 12 10:23:08 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ protoc --version
libprotoc 25.3
Package Version
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway v2.19.1
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 v2.19.1
google.golang.org/protobuf/cmd/protoc-gen-go v1.32.0

Guida contributor