-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for extracting expression from embedded form (#10)
Closes #8
- Loading branch information
Showing
9 changed files
with
161 additions
and
89 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,18 @@ | ||
/** | ||
* This function is used for extracting the expression from OpenAPI Runtime Expression notation. | ||
* | ||
* @example | ||
* | ||
* extract('{$url}'); // => '$url' | ||
*/ | ||
|
||
const extract = (openapiRuntimeExpression) => { | ||
if (typeof openapiRuntimeExpression !== 'string') { | ||
return null; | ||
} | ||
|
||
const match = openapiRuntimeExpression.match(/^{(?<expression>.+)}$/); | ||
return match?.groups?.expression || null; | ||
}; | ||
|
||
export default extract; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as Grammar } from './runtime-expression.cjs'; | ||
export { default as extract } from './extract.js'; | ||
export { default as test } from './test.js'; | ||
export { default as parse } from './parse/index.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
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,42 @@ | ||
import { assert } from 'chai'; | ||
|
||
import {extract, test} from '../src/index.js'; | ||
|
||
describe('extract', function () { | ||
it('should extract expression from OpenAPI runtime expression', function () { | ||
assert.strictEqual(extract('{$url}'), '$url'); | ||
assert.strictEqual(extract('{$method}'), '$method'); | ||
assert.strictEqual(extract('{$request.path.eventType}'), '$request.path.eventType'); | ||
assert.strictEqual(extract('{$request.path.id}'), '$request.path.id'); | ||
assert.strictEqual(extract('{$request.query.queryUrl}'), '$request.query.queryUrl'); | ||
assert.strictEqual(extract('{$request.header.content-Type}'), '$request.header.content-Type'); | ||
assert.strictEqual(extract('{$request.header.accept}'), '$request.header.accept'); | ||
assert.strictEqual(extract('{$response.header.Location}'), '$response.header.Location'); | ||
assert.strictEqual(extract('{$response.header.Server}'), '$response.header.Server'); | ||
assert.strictEqual(extract('{$request.body#/url}'), '$request.body#/url'); | ||
assert.strictEqual(extract('{$request.body#/failedUrl}'), '$request.body#/failedUrl'); | ||
assert.strictEqual(extract('{$request.body#/successUrls/2}'), '$request.body#/successUrls/2'); | ||
assert.strictEqual(extract('{$request.body#/id}'), '$request.body#/id'); | ||
assert.strictEqual(extract('{$request.body#/email}'), '$request.body#/email'); | ||
assert.strictEqual(extract('{$request.body#/user/uuid}'), '$request.body#/user/uuid'); | ||
assert.strictEqual(extract('{$response.body#/uuid}'), '$response.body#/uuid'); | ||
assert.strictEqual(extract('{$response.body#/username}'), '$response.body#/username'); | ||
assert.strictEqual(extract('{$response.body#/status}'), '$response.body#/status'); | ||
|
||
assert.strictEqual(extract('{$url $method}'), '$url $method'); | ||
assert.strictEqual(extract('{$request.path.eventType}}'), '$request.path.eventType}'); | ||
assert.strictEqual(extract('{$request.path.id}}'), '$request.path.id}'); | ||
assert.strictEqual(extract('{$request.query.queryUrl}}'), '$request.query.queryUrl}'); | ||
assert.strictEqual(extract('{$request.body#/url}}'), '$request.body#/url}'); | ||
assert.strictEqual(extract('{$request.body#/user/uuid}}'), '$request.body#/user/uuid}'); | ||
}); | ||
|
||
it('should return null on no match', function () { | ||
assert.isNull(extract('nonsensical string')); | ||
}); | ||
|
||
it('should return null on invalid input', function () { | ||
assert.isNull(extract(null)); | ||
assert.isNull(extract(1)); | ||
}); | ||
}); |
Oops, something went wrong.