diff --git a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/message.proto b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/message.proto index fa9f6f0f..5e31596f 100644 --- a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/message.proto +++ b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/message.proto @@ -75,6 +75,37 @@ service Messaging1 { ] }; } + + rpc StreamMessages(Message) returns(stream Message) { + option(google.api.http) = { + get: "/v1/stream/{message_id}" + body: "*" + }; + option (openapi.v3.operation) = { + responses: { + response_or_reference: { + name: "200" + value: { + response : { + description: "OK" + content: { + additional_properties: { + name: "text/event-stream" + value: { + schema: { + reference: { + _ref: "Message" + } + } + } + } + } + } + } + } + } + }; + } } service Messaging2 { diff --git a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi.yaml b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi.yaml index b1e31f0f..c2df1a2e 100644 --- a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi.yaml @@ -46,6 +46,36 @@ paths: $ref: '#/components/schemas/Status' security: - BasicAuth: [] + /v1/stream/{message_id}: + get: + tags: + - Messaging1 + operationId: Messaging1_StreamMessages + parameters: + - name: message_id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Message' + required: true + responses: + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/Status' + "200": + description: OK + content: + text/event-stream: + schema: + $ref: '#/components/schemas/Message' components: schemas: GoogleProtobufAny: diff --git a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_default_response.yaml b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_default_response.yaml index b1e31f0f..c2df1a2e 100644 --- a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_default_response.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_default_response.yaml @@ -46,6 +46,36 @@ paths: $ref: '#/components/schemas/Status' security: - BasicAuth: [] + /v1/stream/{message_id}: + get: + tags: + - Messaging1 + operationId: Messaging1_StreamMessages + parameters: + - name: message_id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Message' + required: true + responses: + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/Status' + "200": + description: OK + content: + text/event-stream: + schema: + $ref: '#/components/schemas/Message' components: schemas: GoogleProtobufAny: diff --git a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_fq_schema_naming.yaml b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_fq_schema_naming.yaml index 5dbbceca..2b25cb23 100644 --- a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_fq_schema_naming.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_fq_schema_naming.yaml @@ -46,6 +46,36 @@ paths: $ref: '#/components/schemas/google.rpc.Status' security: - BasicAuth: [] + /v1/stream/{message_id}: + get: + tags: + - Messaging1 + operationId: Messaging1_StreamMessages + parameters: + - name: message_id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/tests.openapiv3annotations.message.v1.Message' + required: true + responses: + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/google.rpc.Status' + "200": + description: OK + content: + text/event-stream: + schema: + $ref: '#/components/schemas/tests.openapiv3annotations.message.v1.Message' components: schemas: google.protobuf.Any: diff --git a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_json.yaml b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_json.yaml index b1e31f0f..c2df1a2e 100644 --- a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_json.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_json.yaml @@ -46,6 +46,36 @@ paths: $ref: '#/components/schemas/Status' security: - BasicAuth: [] + /v1/stream/{message_id}: + get: + tags: + - Messaging1 + operationId: Messaging1_StreamMessages + parameters: + - name: message_id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Message' + required: true + responses: + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/Status' + "200": + description: OK + content: + text/event-stream: + schema: + $ref: '#/components/schemas/Message' components: schemas: GoogleProtobufAny: diff --git a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_string_enum.yaml b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_string_enum.yaml index b1e31f0f..c2df1a2e 100644 --- a/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_string_enum.yaml +++ b/cmd/protoc-gen-openapi/examples/tests/openapiv3annotations/openapi_string_enum.yaml @@ -46,6 +46,36 @@ paths: $ref: '#/components/schemas/Status' security: - BasicAuth: [] + /v1/stream/{message_id}: + get: + tags: + - Messaging1 + operationId: Messaging1_StreamMessages + parameters: + - name: message_id + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Message' + required: true + responses: + default: + description: Default error response + content: + application/json: + schema: + $ref: '#/components/schemas/Status' + "200": + description: OK + content: + text/event-stream: + schema: + $ref: '#/components/schemas/Message' components: schemas: GoogleProtobufAny: diff --git a/cmd/protoc-gen-openapi/plugin_test.go b/cmd/protoc-gen-openapi/plugin_test.go index 767e9742..2eaf3e42 100644 --- a/cmd/protoc-gen-openapi/plugin_test.go +++ b/cmd/protoc-gen-openapi/plugin_test.go @@ -105,9 +105,9 @@ func TestOpenAPIProtobufNaming(t *testing.T) { } } else { // Verify that the generated spec matches our expected version. - err = exec.Command("diff", TEMP_FILE, fixture).Run() + output, err := exec.Command("diff", TEMP_FILE, fixture).CombinedOutput() if err != nil { - t.Fatalf("Diff failed: %+v", err) + t.Fatalf("Diff failed: %s", output) } } // if the test succeeded, clean up @@ -163,9 +163,9 @@ func TestOpenAPIFQSchemaNaming(t *testing.T) { } } else { // Verify that the generated spec matches our expected version. - err = exec.Command("diff", TEMP_FILE, fixture).Run() + output, err := exec.Command("diff", TEMP_FILE, fixture).CombinedOutput() if err != nil { - t.Fatalf("Diff failed: %+v", err) + t.Fatalf("Diff failed: %s", output) } // Verify that the generated spec matches the source_relative version sourceRelativeFile := strings.TrimSuffix(tt.protofile, filepath.Ext(tt.protofile)) + ".openapi.yaml" @@ -207,9 +207,9 @@ func TestOpenAPIJSONNaming(t *testing.T) { } } else { // Verify that the generated spec matches our expected version. - err = exec.Command("diff", TEMP_FILE, fixture).Run() + output, err := exec.Command("diff", TEMP_FILE, fixture).CombinedOutput() if err != nil { - t.Fatalf("Diff failed: %+v", err) + t.Fatalf("Diff failed: %s", output) } } // if the test succeeded, clean up @@ -244,9 +244,9 @@ func TestOpenAPIStringEnums(t *testing.T) { } } else { // Verify that the generated spec matches our expected version. - err = exec.Command("diff", TEMP_FILE, fixture).Run() + output, err := exec.Command("diff", TEMP_FILE, fixture).CombinedOutput() if err != nil { - t.Fatalf("diff failed: %+v", err) + t.Fatalf("diff failed: %s", output) } } // if the test succeeded, clean up @@ -281,9 +281,9 @@ func TestOpenAPIDefaultResponse(t *testing.T) { } } else { // Verify that the generated spec matches our expected version. - err = exec.Command("diff", TEMP_FILE, fixture).Run() + output, err := exec.Command("diff", TEMP_FILE, fixture).CombinedOutput() if err != nil { - t.Fatalf("diff failed: %+v", err) + t.Fatalf("diff failed: %s", output) } } // if the test succeeded, clean up