-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: validating parameterized paths on the openapi is now supported * fix: lazy loading the validation modules #203 (#206) * feat: state helper (#207)
- Loading branch information
1 parent
b2aa306
commit c57810f
Showing
8 changed files
with
161 additions
and
19 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,4 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
|
||
{ "id": 1, "name": "Rabbit" } |
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,41 @@ | ||
/** | ||
* Defines and registers custom handlebar helper - state | ||
*/ | ||
export class StateHelper { | ||
private Handlebars: any; | ||
constructor(Handlebars: any) { | ||
this.Handlebars = Handlebars; | ||
} | ||
/** | ||
* Registers code helper | ||
* | ||
* This helper gets the mocked state value using a key send within the cookie header. | ||
* If no value is found it will use the default context within the block. | ||
* | ||
* For example: | ||
* ```json | ||
* { | ||
* "has_pending_order": {{#state key='has-pending-order'}}false{{/state}} | ||
* } | ||
* ``` | ||
* | ||
* To set a value just send cookie with a specific prefix . | ||
* | ||
* ```js | ||
* const prefix = "mocked-state"; | ||
* const key = "has-pending-order"; | ||
* setCookie(`${prefix}-${key}`, "true"); | ||
* ``` | ||
* | ||
* WARNING: the limit of cookie values in most browsers is 4KB | ||
* @returns {void} | ||
*/ | ||
register = () => { | ||
this.Handlebars.registerHelper("state", (context: any) => { | ||
const cookie = context.data.root.request.headers.cookie; | ||
const key = context.hash.key; | ||
const value = new RegExp(`mocked-state-${key}=([^;]+)`).exec(cookie); | ||
return value ? value[1] : context.fn(this); | ||
}); | ||
}; | ||
} |
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