sudorandom / protoc-gen-connect-openapi

Plugin for generating OpenAPIv3 from protobufs matching the Connect RPC interface
MIT License
102 stars 7 forks source link

panic in generate #21

Closed iamnoah closed 3 months ago

iamnoah commented 3 months ago

This proto:

syntax = "proto3";
package foo;
option go_package = "foo/bar";

import "google/api/annotations.proto";
import "buf/validate/validate.proto";

message Rew {
  string t = 1 [(buf.validate.field).required = true];
}

message Res {
}

service Foo {
  rpc Status(Rew) returns (Res) {
    option (google.api.http) = {
      get: "/a"
    };
  }
}

buf.yaml

version: v2
modules:
  - path: proto
deps:
  - buf.build/googleapis/googleapis
  - buf.build/grpc-ecosystem/grpc-gateway
  - buf.build/bufbuild/protovalidate
lint:
  use:
    - FIELD_NO_DESCRIPTOR
  except:
    - ENUM_FIRST_VALUE_ZERO
    - FIELD_NOT_REQUIRED
    - IMPORT_USED
    - PACKAGE_NO_IMPORT_CYCLE
    - PROTOVALIDATE
    - SYNTAX_SPECIFIED
  disallow_comment_ignores: true
breaking:
  except:
    - EXTENSION_NO_DELETE
    - FIELD_SAME_DEFAULT

buf.gen.yaml:

version: v2
plugins:
  - local: protoc-gen-connect-openapi
    out: gen/OpenAPI

v0.8.6 in the path:

buf generate

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x1c8 pc=0x1032b4378]

goroutine 1 [running]:
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter/protovalidate.SchemaWithFieldAnnotations(0x14000252788, {0x1035ad328, 0x140003e7600})
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/protovalidate/schema.go:34 +0xa8
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter/util.ScalarFieldToSchema(0x0, {0x1035ad328, 0x140003e7600})
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/util/schema.go:120 +0x674
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter/util.FieldToSchema(0x0, {0x1035ad328, 0x140003e7600})
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/util/schema.go:81 +0x4a4
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter/googleapi.httpRuleToPathMap({{0x0, 0x0}, {0x1033014f3, 0x4}, {0x0, 0x0}, 0x0, 0x0, 0x14000104bd0, 0x0, ...}, ...)
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/googleapi/paths.go:87 +0x9d8
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter/googleapi.MakePathItems({{0x0, 0x0}, {0x1033014f3, 0x4}, {0x0, 0x0}, 0x0, 0x0, 0x14000104bd0, 0x0, ...}, ...)
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/googleapi/paths.go:28 +0xe4
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter.fileToPathItems({{0x0, 0x0}, {0x1033014f3, 0x4}, {0x0, 0x0}, 0x0, 0x0, 0x14000104bd0, 0x0, ...}, ...)
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/paths.go:24 +0x1f0
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter.appendToSpec({{0x0, 0x0}, {0x1033014f3, 0x4}, {0x0, 0x0}, 0x0, 0x0, 0x14000104bd0, 0x0, ...}, ...)
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/converter.go:282 +0xb08
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter.Convert(0x1400019b080)
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/converter.go:197 +0x93c
github.com/sudorandom/protoc-gen-connect-openapi/internal/converter.ConvertFrom({0x103595358?, 0x140000a0048?})
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/internal/converter/converter.go:108 +0xfc
main.main()
        /Users/noah/go/pkg/mod/github.com/sudorandom/protoc-gen-connect-openapi@v0.8.6/main.go:15 +0x30
Failure: plugin protoc-gen-connect-openapi: exit status 2

Doesn't trigger without required = true, and other random edits seem to sometimes get through... removing the option (google.api.http) keeps it from triggering consistently.

sudorandom commented 3 months ago

Thanks so much. I can probably get this fixed quickly. Thank you SO MUCH for the minimal reproduction steps. That helps so much.

sudorandom commented 3 months ago

@iamnoah this should be fixed now. I released a patch including this fix as v0.8.7.

iamnoah commented 3 months ago

@sudorandom thanks, it works!