Skip to content

Commit

Permalink
Test that schema property description is correctly parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Jul 12, 2024
1 parent 2a6ada5 commit 79bd849
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/example-todo-app/pages/api/todo/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ".",
Expand All @@ -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")
})

0 comments on commit 79bd849

Please sign in to comment.