Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPetricola authored and astahmer committed Nov 22, 2023
1 parent 23f3dc3 commit 60bc8fc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/typed-openapi/tests/map-openapi-endpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2612,4 +2612,56 @@ describe("map-openapi-endpoints", () => {
}
`);
});

test("path and operation parameters", async ({ expect }) => {
const openApiDoc = (await SwaggerParser.parse("./tests/samples/parameters.yaml")) as OpenAPIObject;
expect(mapOpenApiEndpoints(openApiDoc).endpointList).toMatchInlineSnapshot(`
[
{
"meta": {
"alias": "get_UsersId",
"areParametersRequired": true,
"hasParameters": true,
},
"method": "get",
"operation": {
"parameters": [
{
"description": "If true, the endpoint returns only the user metadata.",
"in": "query",
"name": "metadata",
"required": false,
"schema": {
"type": "boolean",
},
},
],
"responses": {
"200": {
"description": "OK",
},
},
"summary": "Gets a user by ID",
},
"parameters": {
"path": {
"id": {
"type": "keyword",
"value": "number",
},
},
"query": {
"type": "ref",
"value": "Partial<{ metadata: boolean }>",
},
},
"path": "/users/{id}",
"response": {
"type": "keyword",
"value": "unknown",
},
},
]
`);
});
});
27 changes: 27 additions & 0 deletions packages/typed-openapi/tests/samples/parameters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://swagger.io/docs/specification/describing-parameters/#common-for-path
openapi: 3.0.3
info:
title: Spec with both path-level and operation-level parameters
paths:
/users/{id}:
parameters:
- in: path
name: id
schema:
type: integer
required: true
description: The user ID.
# GET/users/{id}?metadata=true
get:
summary: Gets a user by ID
# Note we only define the query parameter, because the {id} is defined at the path level.
parameters:
- in: query
name: metadata
schema:
type: boolean
required: false
description: If true, the endpoint returns only the user metadata.
responses:
'200':
description: OK

0 comments on commit 60bc8fc

Please sign in to comment.