-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#464): Fix conversion of paths with multiple parameters
- Loading branch information
1 parent
b94fb46
commit 60ed812
Showing
8 changed files
with
235 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/plugin-openapi/test/fixtures/api-multiple-params/collections.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = [ | ||
{ | ||
id: "base", | ||
routes: [ | ||
"get-users:200-json-one-user", | ||
"post-users:201-status", | ||
"get-users-id:200-json-success", | ||
"get-users-id-books-bookId:200-json-success", | ||
"get-users-id-books-bookId-pages-pageNumber:200-text-success", | ||
], | ||
}, | ||
]; |
105 changes: 105 additions & 0 deletions
105
packages/plugin-openapi/test/fixtures/api-multiple-params/openapi/api.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
const openApiDocument = require("../../../openapi/users"); | ||
|
||
module.exports = [ | ||
{ | ||
basePath: "/api", | ||
document: { | ||
...openApiDocument, | ||
paths: { | ||
...openApiDocument.paths, | ||
"/users/{id}/books/{bookId}": { | ||
get: { | ||
parameters: [ | ||
{ | ||
name: "id", | ||
in: "path", | ||
description: "ID of the user", | ||
required: true, | ||
schema: { | ||
type: "string", | ||
}, | ||
}, | ||
{ | ||
name: "bookId", | ||
in: "path", | ||
description: "ID the user book", | ||
required: true, | ||
schema: { | ||
type: "string", | ||
}, | ||
}, | ||
], | ||
summary: "Return books of one user", | ||
responses: { | ||
"200": { | ||
description: "successful operation", | ||
content: { | ||
"application/json": { | ||
examples: { | ||
success: { | ||
summary: "One book", | ||
value: { | ||
id: 1, | ||
title: "1984", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"/users/{id}/books/{bookId}/pages/{pageNumber}": { | ||
get: { | ||
parameters: [ | ||
{ | ||
name: "id", | ||
in: "path", | ||
description: "ID of the user", | ||
required: true, | ||
schema: { | ||
type: "string", | ||
}, | ||
}, | ||
{ | ||
name: "bookId", | ||
in: "path", | ||
description: "ID the user book", | ||
required: true, | ||
schema: { | ||
type: "string", | ||
}, | ||
}, | ||
{ | ||
name: "pageNumber", | ||
in: "path", | ||
description: "Book page number", | ||
required: true, | ||
schema: { | ||
type: "number", | ||
}, | ||
}, | ||
], | ||
summary: "Return a page of a book of one user", | ||
responses: { | ||
"200": { | ||
description: "successful operation", | ||
content: { | ||
"text/plain": { | ||
examples: { | ||
success: { | ||
summary: "Example page", | ||
value: "Page of the book 1984 by George Orwell.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { startServer, fetchJson, fetchText, waitForServer } from "./support/helpers"; | ||
|
||
describe("generated routes", () => { | ||
let server; | ||
|
||
beforeAll(async () => { | ||
server = await startServer("api-multiple-params"); | ||
await waitForServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await server.stop(); | ||
}); | ||
|
||
describe("routes", () => { | ||
it("should have created routes from openapi document defined in files", async () => { | ||
expect(server.mock.routes.plain).toEqual([ | ||
{ | ||
id: "get-users", | ||
url: "/api/users", | ||
method: "get", | ||
delay: null, | ||
variants: ["get-users:200-json-one-user", "get-users:200-json-two-users"], | ||
}, | ||
{ | ||
id: "post-users", | ||
url: "/api/users", | ||
method: "post", | ||
delay: null, | ||
variants: ["post-users:201-status", "post-users:400-text-error-message"], | ||
}, | ||
{ | ||
id: "get-users-id", | ||
url: "/api/users/:id", | ||
method: "get", | ||
delay: null, | ||
variants: ["get-users-id:200-json-success", "get-users-id:404-json-not-found"], | ||
}, | ||
{ | ||
id: "get-users-id-books-bookId", | ||
url: "/api/users/:id/books/:bookId", | ||
method: "get", | ||
delay: null, | ||
variants: ["get-users-id-books-bookId:200-json-success"], | ||
}, | ||
{ | ||
id: "get-users-id-books-bookId-pages-pageNumber", | ||
url: "/api/users/:id/books/:bookId/pages/:pageNumber", | ||
method: "get", | ||
delay: null, | ||
variants: ["get-users-id-books-bookId-pages-pageNumber:200-text-success"], | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
describe("get-users route", () => { | ||
it("should have 200-json-one-user variant available in base collection", async () => { | ||
const response = await fetchJson("/api/users"); | ||
expect(response.body).toEqual([ | ||
{ | ||
id: 1, | ||
name: "John Doe", | ||
}, | ||
]); | ||
expect(response.status).toEqual(200); | ||
}); | ||
}); | ||
|
||
describe("post-users route", () => { | ||
it("should have 201-status variant available in base collection", async () => { | ||
const response = await fetchJson("/api/users", { | ||
method: "POST", | ||
}); | ||
expect(response.body).toBe(undefined); | ||
expect(response.status).toEqual(201); | ||
}); | ||
}); | ||
|
||
describe("get-users-id route", () => { | ||
it("should have 200-json-success variant available in base collection", async () => { | ||
const response = await fetchJson("/api/users/2"); | ||
expect(response.body).toEqual({ | ||
id: 1, | ||
name: "John Doe", | ||
}); | ||
expect(response.status).toEqual(200); | ||
}); | ||
}); | ||
|
||
describe("get-users-id-books-bookId route", () => { | ||
it("should have 200-json-success variant available in base collection", async () => { | ||
const response = await fetchJson("/api/users/2/books/3"); | ||
expect(response.body).toEqual({ | ||
id: 1, | ||
title: "1984", | ||
}); | ||
expect(response.status).toEqual(200); | ||
}); | ||
}); | ||
|
||
describe("get-users-id-books-bookId-pages-pageNumber route", () => { | ||
it("should have 200-text-success variant available in base collection", async () => { | ||
const response = await fetchText("/api/users/2/books/3/pages/4"); | ||
expect(response.body).toEqual("Page of the book 1984 by George Orwell."); | ||
expect(response.status).toEqual(200); | ||
}); | ||
}); | ||
}); |