mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-22 14:21:55 -05:00
fix(open-api): correct get-session nullable schema for OAS 3.1 (#8389)
Co-authored-by: Maxwell <145994855+ping-maxwell@users.noreply.github.com> Co-authored-by: ping-maxwell <maxwell.multinite@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6ce30cf138
commit
f6428d02fc
5
.changeset/honest-regions-jam.md
Normal file
5
.changeset/honest-regions-jam.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"better-auth": patch
|
||||
---
|
||||
|
||||
fix(open-api): correct get-session nullable schema for OAS 3.1
|
||||
@@ -46,8 +46,8 @@ export const getSession = <Option extends BetterAuthOptions>() =>
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
nullable: true,
|
||||
// better-call's OpenAPI schema type doesn't yet model OAS 3.1 union `type`.
|
||||
type: ["object", "null"] as unknown as "object",
|
||||
properties: {
|
||||
session: {
|
||||
$ref: "#/components/schemas/Session",
|
||||
|
||||
@@ -1591,7 +1591,6 @@ exports[`open-api > should generate OpenAPI schema > openAPISchema 1`] = `
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"nullable": true,
|
||||
"properties": {
|
||||
"session": {
|
||||
"$ref": "#/components/schemas/Session",
|
||||
@@ -1604,7 +1603,10 @@ exports[`open-api > should generate OpenAPI schema > openAPISchema 1`] = `
|
||||
"session",
|
||||
"user",
|
||||
],
|
||||
"type": "object",
|
||||
"type": [
|
||||
"object",
|
||||
"null",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1735,7 +1737,6 @@ exports[`open-api > should generate OpenAPI schema > openAPISchema 1`] = `
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"nullable": true,
|
||||
"properties": {
|
||||
"session": {
|
||||
"$ref": "#/components/schemas/Session",
|
||||
@@ -1748,7 +1749,10 @@ exports[`open-api > should generate OpenAPI schema > openAPISchema 1`] = `
|
||||
"session",
|
||||
"user",
|
||||
],
|
||||
"type": "object",
|
||||
"type": [
|
||||
"object",
|
||||
"null",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -125,6 +125,20 @@ describe("open-api", async () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("should use OpenAPI 3.1 nullable format for get-session response", async () => {
|
||||
const schema = await auth.api.generateOpenAPISchema();
|
||||
const paths = schema.paths as Record<string, any>;
|
||||
|
||||
const getSessionSchema =
|
||||
paths["/get-session"].post.responses["200"].content["application/json"]
|
||||
.schema;
|
||||
|
||||
expect(Array.isArray(getSessionSchema.type)).toBe(true);
|
||||
expect(getSessionSchema.type).toContain("object");
|
||||
expect(getSessionSchema.type).toContain("null");
|
||||
expect(getSessionSchema.nullable).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should use anyOf format for optional object types in OpenAPI 3.1", async () => {
|
||||
const schema = await auth.api.generateOpenAPISchema();
|
||||
const paths = schema.paths as Record<string, any>;
|
||||
|
||||
Reference in New Issue
Block a user