diff --git a/src/services/includers/batteries/openapi/generators/endpoint.ts b/src/services/includers/batteries/openapi/generators/endpoint.ts
index 6848fa88..7128b807 100644
--- a/src/services/includers/batteries/openapi/generators/endpoint.ts
+++ b/src/services/includers/batteries/openapi/generators/endpoint.ts
@@ -83,7 +83,7 @@ function parameters(params?: Parameters) {
}
function parameterRow(param: Parameter) {
- const row = prepareTableRowData({}, param.name, param.schema);
+ const row = prepareTableRowData({}, param.schema, param.name);
let description = param.description;
if (row.description.length) {
description += `
${row.description}`;
@@ -118,6 +118,7 @@ function openapiBody(allRefs: Refs, pagePrintedRefs: Set, obj?: Schema)
const schemaTable = tableFromSchema(allRefs, ref);
result.push(block([
title(3)(tableRef),
+ ref.description,
schemaTable.content,
]));
tableRefs.push(...schemaTable.tableRefs);
diff --git a/src/services/includers/batteries/openapi/generators/traverse.ts b/src/services/includers/batteries/openapi/generators/traverse.ts
index 2dd0b4ee..186cf327 100644
--- a/src/services/includers/batteries/openapi/generators/traverse.ts
+++ b/src/services/includers/batteries/openapi/generators/traverse.ts
@@ -14,7 +14,15 @@ export function tableParameterName(key: string, required?: boolean) {
}
export function tableFromSchema(allRefs: Refs, schema: JSONSchema6): {content: string; tableRefs: string[]} {
- const {rows, refs} = prepareSchemaTable(allRefs, schema);
+ if (schema.enum) {
+ const {type, description} = prepareTableRowData(allRefs, schema);
+ const content = table([
+ ['Type', 'Description'],
+ [type, description],
+ ]);
+ return {content, tableRefs: []};
+ }
+ const {rows, refs} = prepareObjectSchemaTable(allRefs, schema);
const content = table([
['Name', 'Type', 'Description'],
...rows,
@@ -22,18 +30,18 @@ export function tableFromSchema(allRefs: Refs, schema: JSONSchema6): {content: s
return {content, tableRefs: refs};
}
-type PrepareSchemaTableResult = {
+type PrepareObjectSchemaTableResult = {
rows: TableRow[];
refs: string[];
};
-function prepareSchemaTable(refs: Refs, schema: JSONSchema6): PrepareSchemaTableResult {
- const result: PrepareSchemaTableResult = {rows: [], refs: []};
+function prepareObjectSchemaTable(refs: Refs, schema: JSONSchema6): PrepareObjectSchemaTableResult {
+ const result: PrepareObjectSchemaTableResult = {rows: [], refs: []};
const merged = merge(schema);
Object.entries(merged.properties || {}).forEach(([key, v]) => {
const value = merge(v);
const name = tableParameterName(key, schema.required?.includes(key) ?? false);
- const {type, description, ref} = prepareTableRowData(refs, key, value);
+ const {type, description, ref} = prepareTableRowData(refs, value, key);
result.rows.push([name, type, description]);
if (ref) {
result.refs.push(ref);
@@ -48,7 +56,7 @@ type PrepareRowResult = {
ref?: string;
};
-export function prepareTableRowData(allRefs: Refs, key: string, value: JSONSchema6): PrepareRowResult {
+export function prepareTableRowData(allRefs: Refs, value: JSONSchema6, key?: string): PrepareRowResult {
let description = value.description || '';
if (value.type === 'object') {
const ref = findRef(allRefs, value);
@@ -88,6 +96,9 @@ function findRef(allRefs: Refs, value: JSONSchema6): string | undefined {
if (v.allOf && v.allOf === value.allOf) {
return k;
}
+ if (v.enum && v.enum === value.enum) {
+ return k;
+ }
}
return undefined;
}