From 3eed555ef7a2f791af09c27382448f6ad209b498 Mon Sep 17 00:00:00 2001 From: Pham Tuan Date: Wed, 2 Oct 2024 13:17:44 +0700 Subject: [PATCH] Support enum descriptions in schema object --- demo/examples/tests/enumDescriptions.yaml | 84 +++++++++++++++++++ .../src/markdown/createParamsDetails.ts | 4 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 demo/examples/tests/enumDescriptions.yaml diff --git a/demo/examples/tests/enumDescriptions.yaml b/demo/examples/tests/enumDescriptions.yaml new file mode 100644 index 000000000..0d09eaaa6 --- /dev/null +++ b/demo/examples/tests/enumDescriptions.yaml @@ -0,0 +1,84 @@ +openapi: 3.0.1 +info: + title: Enum descriptions test + description: Demonstrates of enum descriptions. + version: 1.0.0 +tags: + - name: enumDescriptions + description: enumDescriptions tests +paths: + /filter-one-status: + get: + tags: + - enumDescriptions + summary: Get entities by status + description: Get all entities or search by status + parameters: + - name: status + in: query + required: true + schema: + type: string + enum: + - active + - inactive + - pending + x-enumDescriptions: + active: The entity is active + inactive: The entity is inactive + pending: The entity is pending approval + responses: + "200": + description: Successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/EnumDescriptionsEntity" + /filter-multiple-status: + get: + tags: + - enumDescriptions + summary: Get entities by multiple status + description: Get all entities or search by multiple status + parameters: + - name: status + in: query + required: true + schema: + type: array + items: + type: string + enum: + - active + - inactive + - pending + x-enumDescriptions: + active: The entity is active + inactive: The entity is inactive + pending: The entity is pending approval + responses: + "200": + description: Successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/EnumDescriptionsEntity" +components: + schemas: + EnumDescriptionsEntity: + type: object + properties: + id: + type: string + name: + type: string + status: + type: string + enum: + - active + - inactive + - pending + x-enumDescriptions: + active: The entity is active + inactive: The entity is inactive + pending: The entity is pending approval diff --git a/packages/docusaurus-plugin-openapi-docs/src/markdown/createParamsDetails.ts b/packages/docusaurus-plugin-openapi-docs/src/markdown/createParamsDetails.ts index ace6dc5ae..f0f89af1e 100644 --- a/packages/docusaurus-plugin-openapi-docs/src/markdown/createParamsDetails.ts +++ b/packages/docusaurus-plugin-openapi-docs/src/markdown/createParamsDetails.ts @@ -49,7 +49,9 @@ export function createParamsDetails({ parameters, type }: Props) { param: { ...param, enumDescriptions: Object.entries( - param?.schema?.items?.["x-enumDescriptions"] ?? {} + param?.schema?.["x-enumDescriptions"] ?? + param?.schema?.items?.["x-enumDescriptions"] ?? + {} ), }, });