Skip to content

Commit 6e4bbb5

Browse files
author
Josh Newman
committed
docs: Update features
1 parent be01695 commit 6e4bbb5

File tree

1 file changed

+55
-5
lines changed

1 file changed

+55
-5
lines changed

README.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,23 @@ service MyService {
9494
display_name: "My Service"
9595
};
9696

97-
rpc CreateSomething (CreateSomethingRequest) returns (GetSomethingResponse) {
97+
rpc CreateSomething (CreateSomethingRequest) returns (CreateSomethingResponse) {
9898
option (oapi.v1.method) = {
9999
post: "create-something"
100100
summary: "Create Something"
101+
status: 201
101102
};
102103
}
103104
}
104105

105106
message CreateSomethingRequest {
106-
// The name of something
107+
// The name of something.
107108
// Example: something-awesome
108109
string name = 1 [(oapi.v1.required) = true];
109110
}
110111

111112
message CreateSomethingResponse {
113+
// The ID of something.
112114
string id = 1;
113115
string name = 2;
114116
}
@@ -121,8 +123,8 @@ message CreateSomethingResponse {
121123
> Defining features is a work in progress. I aim to explain all that's possible
122124
> the best I can.
123125
124-
### Host definitions
125-
126+
<details>
127+
<summary><h3>Host definitions</h3></summary>
126128
You can define hosts at the file, service, or method level. Each one overrides
127129
the previous. This allows for more advanced composition.
128130

@@ -131,9 +133,11 @@ the previous. This allows for more advanced composition.
131133
```protobuf
132134
syntax = "proto3";
133135
136+
import "google/protobuf/empty.proto";
134137
import "oapi/v1/file.proto";
135-
import "oapi/v1/service.proto";
136138
import "oapi/v1/method.proto";
139+
import "oapi/v1/service.proto";
140+
137141
138142
option (oapi.v1.file) = {
139143
host: "myawesomeapi.com" // file-defined for all services and methods
@@ -152,6 +156,52 @@ service MyService {
152156
}
153157
```
154158

159+
</details>
160+
161+
<details>
162+
<summary><h3>Service Prefixes</h3></summary>
163+
Each service can set a path prefix for all methods to inherit. This is useful
164+
when versioning your API or if you have a parameter that is defined for each
165+
method route.
166+
167+
_**You can override the entire path in the method by starting the path out with
168+
a `/`.**_
169+
170+
**Example:**
171+
172+
```protobuf
173+
syntax = "proto3";
174+
175+
import "google/protobuf/empty.proto";
176+
import "oapi/v1/file.proto";
177+
import "oapi/v1/method.proto";
178+
import "oapi/v1/service.proto";
179+
180+
option (oapi.v1.file) = {
181+
host: "myawesomeapi.com"
182+
};
183+
184+
service MyService {
185+
option (oapi.v1.service) = {
186+
prefix: "/v1"
187+
};
188+
189+
rpc CreateSomething (google.protobuf.Empty) returns (google.protobuf.Empty) {
190+
option (oapi.v1.method) = {
191+
post: "create" // becomes /v1/create
192+
};
193+
}
194+
195+
rpc OverrideSomething (google.protobuf.Empty) returns (google.protobuf.Empty) {
196+
option (oapi.v1.method) = {
197+
get: "/create" // becomes /create
198+
};
199+
}
200+
}
201+
```
202+
203+
</details>
204+
155205
## Features In Progress
156206

157207
- Query Parameters

0 commit comments

Comments
 (0)