@@ -31,8 +31,11 @@ async function main(): Promise<void> {
31
31
] )
32
32
}
33
33
34
+ const openapiResponseKeyProp = 'x-fern-sdk-return-value'
35
+
34
36
const routePaths = [
35
37
'/access_codes' ,
38
+ '/access_codes/simulate' ,
36
39
'/access_codes/unmanaged' ,
37
40
'/acs' ,
38
41
'/acs/access_groups' ,
@@ -54,6 +57,7 @@ const routePaths = [
54
57
'/networks' ,
55
58
'/noise_sensors' ,
56
59
'/noise_sensors/noise_thresholds' ,
60
+ '/noise_sensors/simulate' ,
57
61
'/phones' ,
58
62
'/phones/simulate' ,
59
63
'/thermostats' ,
@@ -67,7 +71,7 @@ const routePaths = [
67
71
const routePathSubresources : Partial <
68
72
Record < ( typeof routePaths ) [ number ] , string [ ] >
69
73
> = {
70
- '/access_codes' : [ 'unmanaged' ] ,
74
+ '/access_codes' : [ 'unmanaged' , 'simulate' ] ,
71
75
'/acs' : [
72
76
'access_groups' ,
73
77
'credential_pools' ,
@@ -79,41 +83,11 @@ const routePathSubresources: Partial<
79
83
] ,
80
84
'/phones' : [ 'simulate' ] ,
81
85
'/devices' : [ 'unmanaged' , 'simulate' ] ,
82
- '/noise_sensors' : [ 'noise_thresholds' ] ,
86
+ '/noise_sensors' : [ 'noise_thresholds' , 'simulate' ] ,
83
87
'/thermostats' : [ 'climate_setting_schedules' ] ,
84
88
'/user_identities' : [ 'enrollment_automations' ] ,
85
89
}
86
90
87
- const ignoredEndpointPaths = [
88
- '/access_codes/simulate/create_unmanaged_access_code' ,
89
- '/connect_webviews/view' ,
90
- '/health' ,
91
- '/health/get_health' ,
92
- '/health/get_service_health' ,
93
- '/health/service/[service_name]' ,
94
- '/noise_sensors/simulate/trigger_noise_threshold' ,
95
- '/workspaces/reset_sandbox' ,
96
- ] as const
97
-
98
- const endpointResources : Partial <
99
- Record <
100
- keyof typeof openapi . paths ,
101
- null | 'action_attempt' | 'noise_threshold'
102
- >
103
- > = {
104
- // Set all ignored endpoints null to simplify code generation.
105
- ...ignoredEndpointPaths . reduce ( ( acc , cur ) => ( { ...acc , [ cur ] : null } ) , { } ) ,
106
-
107
- // These endpoints return a deprecated action attempt or resource.
108
- '/access_codes/delete' : null ,
109
- '/access_codes/unmanaged/delete' : null ,
110
- '/access_codes/update' : null ,
111
- '/noise_sensors/noise_thresholds/create' : 'noise_threshold' ,
112
- '/noise_sensors/noise_thresholds/delete' : null ,
113
- '/noise_sensors/noise_thresholds/update' : null ,
114
- '/thermostats/climate_setting_schedules/update' : null ,
115
- } as const
116
-
117
91
interface Route {
118
92
namespace : string
119
93
endpoints : Endpoint [ ]
@@ -139,14 +113,10 @@ interface ClassMeta {
139
113
const createRoutes = ( ) : Route [ ] => {
140
114
const paths = Object . keys ( openapi . paths )
141
115
142
- const unmatchedEndpointPaths = paths
143
- . filter (
144
- ( path ) =>
145
- ! routePaths . some ( ( routePath ) => isEndpointUnderRoute ( path , routePath ) ) ,
146
- )
147
- . filter (
148
- ( path ) => ! ( ignoredEndpointPaths as unknown as string [ ] ) . includes ( path ) ,
149
- )
116
+ const unmatchedEndpointPaths = paths . filter (
117
+ ( path ) =>
118
+ ! routePaths . some ( ( routePath ) => isEndpointUnderRoute ( path , routePath ) ) ,
119
+ )
150
120
151
121
if ( unmatchedEndpointPaths . length > 0 ) {
152
122
throw new Error (
@@ -206,28 +176,28 @@ const deriveResource = (
206
176
endpointPath : string ,
207
177
method : Method ,
208
178
) : string | null => {
209
- if ( isEndpointResource ( endpointPath ) ) {
210
- return endpointResources [ endpointPath ] ?? null
211
- }
212
-
213
179
if ( isOpenapiPath ( endpointPath ) ) {
214
180
const spec = openapi . paths [ endpointPath ]
215
181
const methodKey = method . toLowerCase ( )
216
182
217
183
if ( methodKey === 'post' && 'post' in spec ) {
218
- const response = spec . post . responses [ 200 ]
219
- if ( ! ( 'content' in response ) ) return null
220
- return deriveResourceFromSchema (
221
- response . content [ 'application/json' ] ?. schema ?. properties ?? { } ,
222
- )
184
+ const postSpec = spec . post
185
+ const openapiEndpointResource =
186
+ openapiResponseKeyProp in postSpec
187
+ ? postSpec [ openapiResponseKeyProp ]
188
+ : null
189
+
190
+ return openapiEndpointResource
223
191
}
224
192
225
193
if ( methodKey === 'get' && 'get' in spec ) {
226
194
const response = spec . get . responses [ 200 ]
195
+
227
196
if ( ! ( 'content' in response ) ) {
228
197
throw new Error ( `Missing resource for ${ method } ${ endpointPath } ` )
229
198
}
230
- return deriveResourceFromSchema (
199
+
200
+ return deriveResourceFromSchemaForGetRequest (
231
201
response . content [ 'application/json' ] ?. schema ?. properties ?? { } ,
232
202
)
233
203
}
@@ -236,7 +206,9 @@ const deriveResource = (
236
206
throw new Error ( `Could not derive resource for ${ method } ${ endpointPath } ` )
237
207
}
238
208
239
- const deriveResourceFromSchema = ( properties : object ) : string | null =>
209
+ const deriveResourceFromSchemaForGetRequest = (
210
+ properties : object ,
211
+ ) : string | null =>
240
212
Object . keys ( properties ) . filter ( ( key ) => key !== 'ok' ) [ 0 ] ?? null
241
213
242
214
const deriveSemanticMethod = ( methods : string [ ] ) : Method => {
@@ -248,10 +220,6 @@ const deriveSemanticMethod = (methods: string[]): Method => {
248
220
throw new Error ( `Could not find valid method in ${ methods . join ( ', ' ) } ` )
249
221
}
250
222
251
- const isEndpointResource = (
252
- key : string ,
253
- ) : key is keyof typeof endpointResources => key in endpointResources
254
-
255
223
const isOpenapiPath = ( key : string ) : key is keyof typeof openapi . paths =>
256
224
key in openapi . paths
257
225
0 commit comments