This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct handling of parameters in URI templates
* Resolve #165 - incorrect handling of parameters in URL * Added sorting of resourceURLs for better matching
- Loading branch information
Showing
3 changed files
with
87 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
FORMAT: 1A | ||
HOST: http://example.com | ||
|
||
# API blueprint | ||
|
||
# Data Structures | ||
|
||
## User (object) | ||
+ id: `1` (number) | ||
+ username: `example` (string) | ||
|
||
## Post (object) | ||
+ id: `1` (number) | ||
+ user_id: `1` (number) | ||
+ text: `Post text` (string) | ||
|
||
# Group User | ||
|
||
## User details [/users/{user}/] | ||
|
||
### Get user details [GET] | ||
|
||
+ Parameters | ||
+ user: `example` (string) | ||
|
||
+ Response 200 (application/json) | ||
+ Attributes (User) | ||
|
||
## User posts [/users/{user}/posts/] | ||
|
||
### Get user's posts [GET] | ||
|
||
+ Parameters | ||
+ user: `example` (string) | ||
|
||
+ Response 200 (application/json) | ||
+ Attributes (array[Post]) |
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,32 @@ | ||
import fs from 'fs'; | ||
import hippie from 'hippie'; | ||
import apish from '../dist/apish.js'; | ||
|
||
describe('Mock APIB with parameters in URL', () => { | ||
let mockResult = {}; | ||
before(() => { | ||
const apib = fs.readFileSync(__dirname + '/fixtures/apib-url-parameters.apib'); | ||
return mockResult = apish(apib.toString()); | ||
}); | ||
|
||
after(() => { | ||
mockResult.value().restore(); | ||
}); | ||
|
||
it('should mock the GET /users/example/posts/ request including body', (done) => { | ||
hippie() | ||
.json() | ||
.base('http://example.com') | ||
.get('/users/example/posts/') | ||
.expectStatus(200) | ||
.expectHeader('Content-Type', 'application/json') | ||
.expectBody([ | ||
{ | ||
id: 1, | ||
user_id: 1, | ||
text: 'Post text' | ||
} | ||
]) | ||
.end(done); | ||
}); | ||
}); |