Skip to content

Commit 1b9b260

Browse files
chore: generate
1 parent a8983bd commit 1b9b260

8 files changed

Lines changed: 1121 additions & 4358 deletions

File tree

packages/codemode/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ const api = OpenAPI.fromSpec({
165165
spec: await Bun.file("openapi.json").json(), // parsed document (no YAML)
166166
auth: {
167167
resolve: ({ name, scopes, operation }) =>
168-
name === "BearerAuth"
169-
? Effect.succeed({ type: "bearer", token })
170-
: Effect.succeed(undefined),
168+
name === "BearerAuth" ? Effect.succeed({ type: "bearer", token }) : Effect.succeed(undefined),
171169
},
172170
})
173171

packages/codemode/src/openapi/runtime.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ export const invoke = (plan: Plan, input: unknown): Effect.Effect<unknown, unkno
4646
)
4747
}
4848
if (json && Option.isNone(decoded)) {
49-
return yield* Effect.fail(
50-
toolError(`${plan.operation.method} ${plan.operation.path} returned malformed JSON.`),
51-
)
49+
return yield* Effect.fail(toolError(`${plan.operation.method} ${plan.operation.path} returned malformed JSON.`))
5250
}
5351
return parsed
5452
})
@@ -208,8 +206,9 @@ const buildUrl = (plan: Plan, input: Readonly<Record<string, unknown>>): string
208206
return toolError(`Missing required path parameter '${field.inputName}'.`)
209207
}
210208
const fieldValue = serializeSimple(field, item, (value) =>
211-
encodeURIComponent(value).replace(/[!'()*]/g, (character) =>
212-
`%${character.charCodeAt(0).toString(16).toUpperCase()}`,
209+
encodeURIComponent(value).replace(
210+
/[!'()*]/g,
211+
(character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`,
213212
),
214213
)
215214
if (fieldValue instanceof ToolError) return fieldValue
@@ -271,10 +270,7 @@ const serializeQuery = (
271270
if (value.some((item) => item === undefined || (item !== null && typeof item === "object"))) {
272271
return toolError(`Query parameter '${field.inputName}' contains an unsupported nested value.`)
273272
}
274-
return value.reduce(
275-
(current, item) => HttpClientRequest.appendUrlParam(current, field.name, String(item)),
276-
request,
277-
)
273+
return value.reduce((current, item) => HttpClientRequest.appendUrlParam(current, field.name, String(item)), request)
278274
}
279275
if (isRecord(value) && field.explode) {
280276
return Object.entries(value).reduce<HttpClientRequest.HttpClientRequest | ToolError>((current, [name, item]) => {
@@ -289,11 +285,15 @@ const serializeQuery = (
289285
return rendered instanceof ToolError ? rendered : HttpClientRequest.appendUrlParam(request, field.name, rendered)
290286
}
291287

292-
const readResponseBody = (response: HttpClientResponse.HttpClientResponse, plan: Plan): Effect.Effect<string, ToolError> =>
288+
const readResponseBody = (
289+
response: HttpClientResponse.HttpClientResponse,
290+
plan: Plan,
291+
): Effect.Effect<string, ToolError> =>
293292
Effect.gen(function* () {
294293
const contentLength = response.headers["content-length"]
295294
const parsedSize = contentLength === undefined ? undefined : Number.parseInt(contentLength, 10)
296-
const declaredSize = parsedSize !== undefined && Number.isSafeInteger(parsedSize) && parsedSize >= 0 ? parsedSize : undefined
295+
const declaredSize =
296+
parsedSize !== undefined && Number.isSafeInteger(parsedSize) && parsedSize >= 0 ? parsedSize : undefined
297297
if (declaredSize !== undefined && declaredSize > maxResponseBodyBytes) {
298298
return yield* Effect.fail(toolError(`${plan.operation.method} ${plan.operation.path} response exceeds 50 MiB.`))
299299
}
@@ -304,7 +304,9 @@ const readResponseBody = (response: HttpClientResponse.HttpClientResponse, plan:
304304
return Effect.fail(toolError(`${plan.operation.method} ${plan.operation.path} response exceeds 50 MiB.`))
305305
}
306306
if (size + chunk.byteLength > body.byteLength) {
307-
const grown = Buffer.allocUnsafe(Math.min(maxResponseBodyBytes, Math.max(size + chunk.byteLength, body.byteLength * 2)))
307+
const grown = Buffer.allocUnsafe(
308+
Math.min(maxResponseBodyBytes, Math.max(size + chunk.byteLength, body.byteLength * 2)),
309+
)
308310
body.copy(grown, 0, 0, size)
309311
body = grown
310312
}

packages/codemode/src/openapi/spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ const isBinaryMediaType = (document: Document, mediaType: string, value: unknown
7878
return isRecord(schema) && schema.format === "binary"
7979
}
8080

81-
const jsonContent = (content: Record<string, unknown>): { readonly mediaType: string; readonly schema: unknown } | undefined => {
81+
const jsonContent = (
82+
content: Record<string, unknown>,
83+
): { readonly mediaType: string; readonly schema: unknown } | undefined => {
8284
const entry = Object.entries(content).find(([mediaType]) => isJsonMediaType(mediaType))
8385
return entry !== undefined && isRecord(entry[1]) ? { mediaType: entry[0], schema: entry[1].schema } : undefined
8486
}
@@ -344,7 +346,7 @@ export const operationOutput = (
344346
if (outcomes.length === 0) return { ok: true, value: undefined }
345347
return {
346348
ok: true,
347-
value: withDefinitions(outcomes.length === 1 ? outcomes[0] ?? {} : { anyOf: outcomes }, definitions),
349+
value: withDefinitions(outcomes.length === 1 ? (outcomes[0] ?? {}) : { anyOf: outcomes }, definitions),
348350
}
349351
}
350352

@@ -380,7 +382,9 @@ export const operationPath = (
380382
namespaces: ReadonlySet<string>,
381383
): ReadonlyArray<string> => {
382384
const raw = nonEmptyString(operation.operationId)
383-
const segments = (raw === undefined ? [fallbackOperationId(method, path)] : raw.split(".")).map(sanitizeOperationSegment)
385+
const segments = (raw === undefined ? [fallbackOperationId(method, path)] : raw.split(".")).map(
386+
sanitizeOperationSegment,
387+
)
384388
if (isOperationPathAvailable(segments, used, namespaces)) return segments
385389
const conflict = segments.slice(0, -1).findIndex((_, index) => used.has(segments.slice(0, index + 1).join(".")))
386390
if (conflict >= 0 && conflict + 1 < segments.length) {

packages/codemode/test/fixtures/openapi-happy-path.json

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,10 @@
9393
},
9494
"role": {
9595
"type": "string",
96-
"enum": [
97-
"admin",
98-
"member"
99-
]
96+
"enum": ["admin", "member"]
10097
}
10198
},
102-
"required": [
103-
"name",
104-
"email"
105-
],
99+
"required": ["name", "email"],
106100
"additionalProperties": false
107101
}
108102
}
@@ -143,9 +137,7 @@
143137
"type": "integer"
144138
}
145139
},
146-
"required": [
147-
"query"
148-
],
140+
"required": ["query"],
149141
"additionalProperties": false
150142
}
151143
},
@@ -216,17 +208,10 @@
216208
},
217209
"role": {
218210
"type": "string",
219-
"enum": [
220-
"admin",
221-
"member"
222-
]
211+
"enum": ["admin", "member"]
223212
}
224213
},
225-
"required": [
226-
"id",
227-
"name",
228-
"email"
229-
],
214+
"required": ["id", "name", "email"],
230215
"additionalProperties": false
231216
}
232217
},

0 commit comments

Comments
 (0)