Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): drop malformed Better Auth schema fields from OpenAPI output

Andreje986f58173a0
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 1d2c7c8f5..91c07e53d 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -68,6 +68,7 @@ import {
normalizeApiServerUrl,
normalizeEmptyAndEnumSchemas,
normalizeEmptyRequiredArrays,
+ normalizeMalformedPropertySchemas,
normalizeNullableSchemasForOpenApi30,
normalizeOrganizationAuthOperations,
} from "./utils/openapi-spec";
@@ -365,7 +366,9 @@ export function createApp() {
normalizeNullableSchemasForOpenApi30(
normalizeEmptyAndEnumSchemas(
normalizeEmptyRequiredArrays(
- mergeOpenApiSpecs(honoSpec, normalizedAuthSpec),
+ normalizeMalformedPropertySchemas(
+ mergeOpenApiSpecs(honoSpec, normalizedAuthSpec),
+ ),
),
),
),
diff --git a/apps/api/src/utils/openapi-spec.ts b/apps/api/src/utils/openapi-spec.ts
index e66db1969..f04f408ef 100644
--- a/apps/api/src/utils/openapi-spec.ts
+++ b/apps/api/src/utils/openapi-spec.ts
@@ -410,6 +410,44 @@ export const normalizeEmptyRequiredArrays = (spec: Record<string, unknown>) => {
return spec;
};
+// Better Auth's generateOpenAPISchema sometimes emits a `properties` entry whose
+// value is a primitive instead of a schema object — e.g. the organization
+// `create-role` `additionalFields` field comes through as
+// `properties: { type: "object" }`. OpenAPI validators (Mintlify) reject the
+// invalid sub-schema, so drop any property whose schema is not an object.
+export const normalizeMalformedPropertySchemas = (
+ spec: Record<string, unknown>,
+) => {
+ const visit = (node: unknown): void => {
+ if (Array.isArray(node)) {
+ for (const item of node) {
+ visit(item);
+ }
+ return;
+ }
+
+ if (!isPlainObject(node)) {
+ return;
+ }
+
+ if (isPlainObject(node.properties)) {
+ const properties = node.properties as Record<string, unknown>;
+ for (const [key, value] of Object.entries(properties)) {
+ if (!isPlainObject(value)) {
+ delete properties[key];
+ }
+ }
+ }
+
+ for (const value of Object.values(node)) {
+ visit(value);
+ }
+ };
+
+ visit(spec);
+ return spec;
+};
+
export const markOptionalSchemaFieldsNullable = (
spec: Record<string, unknown>,
) => {