Skip to content

Commit b49f53d

Browse files
author
Josh
committed
Fix adding servers without existing servers
1 parent 971b96a commit b49f53d

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

internal/generator/path.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ func (g *Generator) addPathsToDoc(doc *openapi3.T, services []*protogen.Service)
8787
}
8888

8989
if len(serviceOptions.AddServers) > 0 {
90+
if len(servers) == 0 {
91+
// If there are no servers defined on the service level, but we
92+
// have servers being added, we need to ensure both are on each
93+
// method.
94+
for _, s := range doc.Servers {
95+
servers = append(servers, s)
96+
}
97+
}
98+
9099
for _, addServer := range serviceOptions.AddServers {
91100
server, err := NewServer(addServer.Url)
92101
if err != nil {

test/service_test.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ service TestService {
5555
}
5656
}
5757

58+
service Test2Service {
59+
option (oapi.v1.service) = {
60+
add_servers {
61+
url: "api.added.io"
62+
}
63+
x_display_name: "Test 2 Service"
64+
x_tag_group: "Test 2 Group"
65+
};
66+
67+
rpc TestGet(TestGetRequest) returns (TestGetResponse) {
68+
option (oapi.v1.method) = {
69+
get: "Test2Get"
70+
};
71+
};
72+
}
73+
5874
message TestGetRequest{
5975
string value = 1;
6076
}

test/service_test_openapi.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ paths:
4848
tags:
4949
- TestService
5050
security: [ ]
51+
/v1/Test2Get:
52+
get:
53+
operationId: Test2Service_TestGet
54+
responses:
55+
'200':
56+
content:
57+
application/json:
58+
schema:
59+
properties:
60+
value:
61+
type: string
62+
description: ''
63+
default:
64+
$ref: '#/components/responses/default'
65+
servers:
66+
- url: https://swagger.io
67+
- url: https://api.added.io
68+
tags:
69+
- Test2Service
5170

5271
components:
5372
responses:
@@ -76,11 +95,17 @@ servers:
7695
tags:
7796
- name: TestService
7897
x-displayName: Test Service
98+
- name: Test2Service
99+
x-displayName: Test 2 Service
100+
79101

80102
x-tagGroups:
81103
- name: Test Group
82104
tags:
83105
- TestService
106+
- name: Test 2 Group
107+
tags:
108+
- Test2Service
84109

85110
security:
86111
- bearer_auth:

0 commit comments

Comments
 (0)