Skip to content

Commit

Permalink
fix: relax schema for void responses
Browse files Browse the repository at this point in the history
  • Loading branch information
mnahkies committed Dec 22, 2024
1 parent 4189b62 commit 780ab21
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion e2e/src/generated/client/axios/client.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/src/generated/client/fetch/client.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions e2e/src/index.axios.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ describe("e2e - typescript-axios client", () => {

describe("GET /responses/empty", () => {
it("returns undefined", async () => {
const {data} = await client.getResponsesEmpty()
expect(data).toBeUndefined()
const {status, data} = await client.getResponsesEmpty()

expect(status).toBe(204)
expect(data).toEqual("")
})
})
})
4 changes: 2 additions & 2 deletions e2e/src/index.fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ describe("e2e - typescript-fetch client", () => {
it("returns undefined", async () => {
const res = await client.getResponsesEmpty()

const body = await res.json()
expect(body).toBeUndefined()
expect(res.status).toBe(204)
await expect(res.json()).rejects.toThrow("Unexpected end of JSON input")
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class ClientOperationBuilder {
acc.defaultResponse = {
schema: content
? schemaBuilder.fromModel(content.schema, true, true)
: schemaBuilder.void(),
: schemaBuilder.any(),
type: content ? models.schemaObjectToType(content.schema) : "void",
}
} else {
Expand All @@ -138,7 +138,7 @@ export class ClientOperationBuilder {
type: content ? models.schemaObjectToType(content.schema) : "void",
schema: content
? schemaBuilder.fromModel(content.schema, true, true)
: schemaBuilder.void(),
: schemaBuilder.any(),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export abstract class AbstractSchemaBuilder<

protected abstract boolean(): string

protected abstract any(): string
public abstract any(): string

protected abstract unknown(): string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class JoiBuilder extends AbstractSchemaBuilder<
.join(".")
}

protected any(): string {
public any(): string {
return [joi, "any()"].filter(isDefined).join(".")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class ZodBuilder extends AbstractSchemaBuilder<
return this.addStaticSchema("PermissiveBoolean")
}

protected any(): string {
public any(): string {
return [zod, "any()"].filter(isDefined).join(".")
}

Expand Down

0 comments on commit 780ab21

Please sign in to comment.