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.

feat(api): add normalizeEmptyAndEnumSchemas function for OpenAPI spec processing

Andrej13c544d1a5e2
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 9f1794dbb..571fc9320 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -59,6 +59,7 @@ import {
markOptionalSchemaFieldsNullable,
mergeOpenApiSpecs,
normalizeApiServerUrl,
+ normalizeEmptyAndEnumSchemas,
normalizeEmptyRequiredArrays,
normalizeNullableSchemasForOpenApi30,
normalizeOrganizationAuthOperations,
@@ -309,8 +310,10 @@ export function createApp() {
dedupeOperationIds(
markOptionalSchemaFieldsNullable(
normalizeNullableSchemasForOpenApi30(
- normalizeEmptyRequiredArrays(
- mergeOpenApiSpecs(honoSpec, normalizedAuthSpec),
+ normalizeEmptyAndEnumSchemas(
+ normalizeEmptyRequiredArrays(
+ mergeOpenApiSpecs(honoSpec, normalizedAuthSpec),
+ ),
),
),
),
diff --git a/apps/api/src/utils/openapi-spec.ts b/apps/api/src/utils/openapi-spec.ts
index fa88f8df0..11c921c4f 100644
--- a/apps/api/src/utils/openapi-spec.ts
+++ b/apps/api/src/utils/openapi-spec.ts
@@ -437,6 +437,65 @@ export const markOptionalSchemaFieldsNullable = (
return spec;
};
+export const normalizeEmptyAndEnumSchemas = (spec: Record<string, unknown>) => {
+ const visit = (node: unknown, parentIsProperties?: boolean): void => {
+ if (Array.isArray(node)) {
+ for (const item of node) {
+ visit(item, false);
+ }
+ return;
+ }
+
+ if (!isPlainObject(node)) {
+ return;
+ }
+
+ // propertyNames is not valid in OpenAPI 3.0.x — remove it
+ if ("propertyNames" in node) {
+ delete node.propertyNames;
+ }
+
+ // Schema with enum but no type → add type: "string"
+ if (Array.isArray(node.enum) && !node.type && !node.$ref) {
+ node.type = "string";
+ }
+
+ // $ref with siblings is invalid in 3.0.x → wrap in allOf
+ if (typeof node.$ref === "string" && Object.keys(node).length > 1) {
+ const ref = node.$ref as string;
+ delete node.$ref;
+ const rest = { ...node };
+ for (const k of Object.keys(node)) {
+ delete node[k];
+ }
+ Object.assign(node, { allOf: [{ $ref: ref }], ...rest });
+ }
+
+ // For "properties" maps, check children for empty schemas (v.date() → {})
+ if (isPlainObject(node.properties)) {
+ const props = node.properties as Record<string, unknown>;
+ for (const [name, schema] of Object.entries(props)) {
+ if (isPlainObject(schema) && Object.keys(schema).length === 0) {
+ props[name] = { type: "string", format: "date-time" };
+ }
+ }
+ }
+
+ for (const [k, value] of Object.entries(node)) {
+ // Replace remaining empty schemas {} (e.g. v.any() or v.unknown()).
+ if (isPlainObject(value) && Object.keys(value).length === 0) {
+ // additionalProperties: {} → true (means "any additional properties")
+ node[k] = k === "additionalProperties" ? true : { type: "object" };
+ continue;
+ }
+ visit(value, k === "properties");
+ }
+ };
+
+ visit(spec, false);
+ return spec;
+};
+
export const ensureOperationSummaries = (spec: Record<string, unknown>) => {
const paths = ((spec as { paths?: unknown }).paths || {}) as Record<
string,
diff --git a/apps/docs/docs.json b/apps/docs/docs.json
index cdf1b34a9..9ccb0ad91 100644
--- a/apps/docs/docs.json
+++ b/apps/docs/docs.json
@@ -115,7 +115,7 @@
},
{
"tab": "API Reference",
- "openapi": "https://cloud.kaneo.app/api/openapi"
+ "openapi": "http://localhost:1337/api/openapi"
}
],
"global": {