-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomprehensive-weather.smithy
More file actions
280 lines (228 loc) · 4.65 KB
/
comprehensive-weather.smithy
File metadata and controls
280 lines (228 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
$version: "2"
namespace smithy.example.weather
/// A comprehensive weather service demonstrating Smithy 2.0 features
@protocols([{name: "smithy.protocols#restJson1"}])
service WeatherService {
version: "2024-01-01"
operations: [GetWeather, CreateForecast]
resources: [Forecast]
errors: [WeatherServiceError]
}
/// Get current weather for a location
@readonly
@http(method: "GET", uri: "/weather/{locationId}")
operation GetWeather {
input := {
@httpLabel
@required
locationId: LocationId
@httpQuery("units")
units: TemperatureUnit = "celsius"
@httpHeader("x-api-key")
apiKey: String
}
output := {
@required
temperature: Temperature
@required
conditions: WeatherConditions
humidity: Integer
@httpResponseCode
statusCode: Integer
}
errors: [LocationNotFound, InvalidApiKey]
}
/// Create a weather forecast
@idempotent
@http(method: "PUT", uri: "/forecasts/{forecastId}")
operation CreateForecast {
input := {
@httpLabel
@required
forecastId: ForecastId
@httpPayload
@required
forecast: ForecastData
}
output := {
@required
forecastId: ForecastId
@required
createdAt: Timestamp
}
errors: [InvalidForecastData]
}
/// Weather forecast resource
resource Forecast {
identifiers: { forecastId: ForecastId }
properties: {
temperature: Temperature
conditions: WeatherConditions
validUntil: Timestamp
}
read: GetForecast
create: CreateForecast
delete: DeleteForecast
}
@readonly
@http(method: "GET", uri: "/forecasts/{forecastId}")
operation GetForecast {
input := {
@httpLabel
@required
forecastId: ForecastId
}
output := for Forecast {
$forecastId
$temperature
$conditions
$validUntil
}
}
@idempotent
@http(method: "DELETE", uri: "/forecasts/{forecastId}")
operation DeleteForecast {
input := {
@httpLabel
@required
forecastId: ForecastId
}
}
// Simple types
@pattern("^[A-Z]{2}-[0-9]{4}$")
string LocationId
@pattern("^forecast-[0-9]+$")
string ForecastId
@range(min: -100, max: 100)
integer Temperature
// Enum with explicit values
enum TemperatureUnit {
@enumValue("C")
CELSIUS = "celsius"
@enumValue("F")
FAHRENHEIT = "fahrenheit"
@enumValue("K")
KELVIN = "kelvin"
}
// String enum
enum WeatherConditions {
SUNNY
CLOUDY
RAINY
SNOWY
STORMY
}
// IntEnum
intEnum AlertLevel {
LOW = 1
MEDIUM = 2
HIGH = 3
CRITICAL = 4
}
// Structure with various members
structure ForecastData {
@required
temperature: Temperature
@required
conditions: WeatherConditions
@default(0)
humidity: Integer
@sensitive
internalNotes: String
@deprecated(message: "Use alerts instead")
severity: AlertLevel
alerts: AlertList
}
// List with constraints
@length(min: 0, max: 10)
list AlertList {
member: Alert
}
// Map example
map WeatherData {
key: String
value: Temperature
}
// Union type
union Alert {
temperature: TemperatureAlert
wind: WindAlert
precipitation: PrecipitationAlert
}
structure TemperatureAlert {
@required
threshold: Temperature
@required
type: AlertType
}
structure WindAlert {
@required
@range(min: 0, max: 200)
speedKmh: Integer
direction: WindDirection
}
structure PrecipitationAlert {
@required
@range(min: 0, max: 100)
probabilityPercent: Integer
type: PrecipitationType
}
enum AlertType {
HEAT_WARNING
FREEZE_WARNING
EXTREME_TEMPERATURE
}
enum WindDirection {
NORTH
SOUTH
EAST
WEST
NORTHEAST
NORTHWEST
SOUTHEAST
SOUTHWEST
}
enum PrecipitationType {
RAIN
SNOW
SLEET
HAIL
}
// Error structures
@error("client")
structure LocationNotFound {
@required
message: String
@required
locationId: LocationId
}
@error("client")
structure InvalidApiKey {
@required
message: String
}
@error("client")
structure InvalidForecastData {
@required
message: String
validationErrors: ValidationErrorList
}
@error("server")
structure WeatherServiceError {
@required
message: String
@required
code: String
retryAfterSeconds: Integer
}
list ValidationErrorList {
member: ValidationError
}
structure ValidationError {
@required
field: String
@required
message: String
@required
code: String
}