-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
path templates matched incorrectly #214
- Loading branch information
Carmine DiMascio
committed
Jan 11, 2020
1 parent
f15565e
commit e000aa2
Showing
4 changed files
with
130 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as path from 'path'; | ||
import * as express from 'express'; | ||
import * as request from 'supertest'; | ||
import { createApp } from './common/app'; | ||
import * as packageJson from '../package.json'; | ||
|
||
describe(packageJson.name, () => { | ||
let app = null; | ||
|
||
before(async () => { | ||
// Set up the express app | ||
const apiSpec = path.join('test', 'resources', 'path.order.yaml'); | ||
app = await createApp({ apiSpec }, 3005, app => | ||
app.use( | ||
`${app.basePath}`, | ||
express | ||
.Router() | ||
.get(`/users/:id`, (req, res) => res.json({ path: req.path })) | ||
.post(`/users/jimmy`, (req, res) => | ||
res.json({ ...req.body, path: req.path }), | ||
), | ||
), | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it('should match on users test', async () => | ||
request(app) | ||
.get(`${app.basePath}/users/test`) | ||
.expect(200)); | ||
|
||
it('static routes should be matched before dynamic routes', async () => | ||
request(app) | ||
.post(`${app.basePath}/users/jimmy`) | ||
.send({ | ||
id: 'some_id', | ||
name: 'sally', | ||
}) | ||
.expect(200)); | ||
}); |
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,61 @@ | ||
openapi: "3.0.0" | ||
info: | ||
version: 1.0.0 | ||
title: Swagger Petstore | ||
description: A sample API | ||
termsOfService: http://swagger.io/terms/ | ||
license: | ||
name: Apache 2.0 | ||
url: https://www.apache.org/licenses/LICENSE-2.0.html | ||
servers: | ||
- url: /v1 | ||
|
||
paths: | ||
/users/{id}: | ||
get: | ||
description: get user | ||
operationId: getUser | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
"200": | ||
description: user response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/User" | ||
|
||
/users/jimmy: | ||
post: | ||
description: get user | ||
operationId: modifyUser | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/User" | ||
responses: | ||
"200": | ||
description: user response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/User" | ||
|
||
components: | ||
schemas: | ||
User: | ||
description: default | ||
type: object | ||
required: | ||
- id | ||
properties: | ||
id: | ||
type: string | ||
name: | ||
type: string |