fix(client): loosen opaque promise outputs
This commit is contained in:
parent
2a7e32c416
commit
1956497f42
3 changed files with 135 additions and 114 deletions
|
|
@ -827,7 +827,7 @@ function structuralTypes(schemas: ReadonlyArray<Schema.Top>, mutable: boolean, r
|
|||
const output = type
|
||||
.replaceAll(/ & Brand\.Brand<"[^"]+">/g, "")
|
||||
.replaceAll("Schema.Json", "JsonValue")
|
||||
.replaceAll(/(?<!["'])\bunknown\b(?!["'])/g, "JsonValue")
|
||||
.replaceAll(/(?<!["'])\bunknown\b(?!["'])/g, "any")
|
||||
return mutable ? mutableType(output) : output
|
||||
}
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1097,6 +1097,27 @@ describe("HttpApiCodegen.generate", () => {
|
|||
expect(output.operations[0]?.success).toBe("stream")
|
||||
})
|
||||
|
||||
test("emits opaque Promise SSE fields as any", () => {
|
||||
const output = emitPromise(
|
||||
compileContract(
|
||||
api(
|
||||
HttpApiEndpoint.get("subscribe", "/event", {
|
||||
success: HttpApiSchema.StreamSse({
|
||||
data: Schema.Struct({
|
||||
metadata: Schema.Record(Schema.String, Schema.Unknown),
|
||||
label: Schema.Literal("unknown"),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
const types = output.files.find((file) => file.path === "types.ts")?.content
|
||||
|
||||
expect(types).toContain('readonly "metadata": { readonly [x: string]: any }')
|
||||
expect(types).toContain('readonly "label": "unknown"')
|
||||
})
|
||||
|
||||
test("preserves annotated stream response statuses", () => {
|
||||
const output = compile(
|
||||
api(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue