From 79bd849112182dacfc3406569f9237877b29a13b Mon Sep 17 00:00:00 2001 From: Andrii Balitskyi <10balian10@gmail.com> Date: Fri, 12 Jul 2024 14:52:24 +0200 Subject: [PATCH] Test that schema property description is correctly parsed --- apps/example-todo-app/pages/api/todo/add.ts | 1 + .../openapi-generation.test.ts | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/example-todo-app/pages/api/todo/add.ts b/apps/example-todo-app/pages/api/todo/add.ts index 1474c748d..1dbf549c3 100644 --- a/apps/example-todo-app/pages/api/todo/add.ts +++ b/apps/example-todo-app/pages/api/todo/add.ts @@ -17,6 +17,7 @@ export const jsonBody = z.object({ --- title: Unused deprecated: yes, because it's deprecated. + snake_case: Snake case property --- This is an unused, deprecated field. `), diff --git a/apps/example-todo-app/tests/openapi-generation/openapi-generation.test.ts b/apps/example-todo-app/tests/openapi-generation/openapi-generation.test.ts index adfe10697..00c5540c3 100644 --- a/apps/example-todo-app/tests/openapi-generation/openapi-generation.test.ts +++ b/apps/example-todo-app/tests/openapi-generation/openapi-generation.test.ts @@ -64,7 +64,7 @@ test("generateOpenAPI marks null params with nullable flag", async (t) => { t.true(testNullParam.nullable) }) -test("generateOpenAPI correctly parses description with front matter", async (t) => { +test("generateOpenAPI correctly parses endpoint description with front matter and prefixes custom properties with 'x-'", async (t) => { const openapiJson = JSON.parse( await generateOpenAPI({ packageDir: ".", @@ -75,10 +75,28 @@ test("generateOpenAPI correctly parses description with front matter", async (t) t.truthy(routeSpec.description) t.is( - routeSpec.description.trim(), + routeSpec.description, "This endpoint allows you to add a new todo item to the list. Deprecated." ) t.is(routeSpec["x-deprecated"], "Use foobar instead.") t.is(routeSpec["x-fern-sdk-return-value"], "foobar") t.is(routeSpec["x-response-key"], "foobar") }) + +test("generateOpenAPI correctly parses property description with front matter and prefixes custom properties with 'x-'", async (t) => { + const openapiJson = JSON.parse( + await generateOpenAPI({ + packageDir: ".", + }) + ) + + const routeSpec = openapiJson.paths["/api/todo/add"].post + const testUnusedParam = + routeSpec.requestBody.content["application/json"].schema.properties.unused + + t.true(testUnusedParam.deprecated) + t.is(testUnusedParam["x-title"], "Unused") + t.is(testUnusedParam["x-deprecated"], "yes, because it's deprecated.") + // snake case is correctly dashified + t.is(testUnusedParam["x-snake-case"], "Snake case property") +})