-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ns-openapi-3-1): add idempotence to parameter examples refractor…
- Loading branch information
Showing
7 changed files
with
247 additions
and
12 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
28 changes: 28 additions & 0 deletions
28
...3-1/test/refractor/plugins/normalize-parameter-examples/__snapshots__/idempotence.ts.snap
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,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor plugins normalize-parameter-examples should have idempotent characteristics 1`] = ` | ||
Object { | ||
openapi: 3.1.0, | ||
paths: Object { | ||
/: Object { | ||
get: Object { | ||
parameters: Array [ | ||
Object { | ||
examples: Object { | ||
example1: Object { | ||
value: 2, | ||
}, | ||
}, | ||
in: query, | ||
name: idempotent, | ||
schema: Object { | ||
example: 1, | ||
type: number, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
60 changes: 60 additions & 0 deletions
60
.../apidom-ns-openapi-3-1/test/refractor/plugins/normalize-parameter-examples/idempotence.ts
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,60 @@ | ||
import { expect } from 'chai'; | ||
import dedent from 'dedent'; | ||
import { toValue, dispatchRefractorPlugins } from '@swagger-api/apidom-core'; | ||
import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; | ||
|
||
import { | ||
createToolbox, | ||
OpenApi3_1Element, | ||
refractorPluginNormalizeParameterExamples, | ||
keyMap, | ||
getNodeType, | ||
} from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('plugins', function () { | ||
context('normalize-parameter-examples', function () { | ||
specify('should have idempotent characteristics', async function () { | ||
const yamlDefinition = dedent` | ||
openapi: 3.1.0 | ||
paths: | ||
/: | ||
get: | ||
parameters: | ||
- in: query | ||
name: idempotent | ||
schema: | ||
type: number | ||
example: 1 | ||
examples: | ||
example1: | ||
value: 2 | ||
`; | ||
const apiDOM = await parse(yamlDefinition); | ||
const openApiElement = OpenApi3_1Element.refract(apiDOM.result) as OpenApi3_1Element; | ||
const options = { | ||
toolboxCreator: createToolbox, | ||
visitorOptions: { keyMap, nodeTypeGetter: getNodeType }, | ||
}; | ||
|
||
dispatchRefractorPlugins( | ||
openApiElement, | ||
[refractorPluginNormalizeParameterExamples()], | ||
options, | ||
); | ||
dispatchRefractorPlugins( | ||
openApiElement, | ||
[refractorPluginNormalizeParameterExamples()], | ||
options, | ||
); | ||
dispatchRefractorPlugins( | ||
openApiElement, | ||
[refractorPluginNormalizeParameterExamples()], | ||
options, | ||
); | ||
|
||
expect(toValue(apiDOM.result)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
70 changes: 70 additions & 0 deletions
70
...pidom-ns-openapi-3-1/test/refractor/plugins/normalize-parameter-examples/storage-field.ts
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,70 @@ | ||
import { assert } from 'chai'; | ||
import dedent from 'dedent'; | ||
import { toValue } from '@swagger-api/apidom-core'; | ||
import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; | ||
|
||
import { OpenApi3_1Element, refractorPluginNormalizeParameterExamples } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('plugins', function () { | ||
context('normalize-parameter-examples', function () { | ||
specify('should use sub-field to store normalized scopes', async function () { | ||
const yamlDefinition = dedent` | ||
openapi: 3.1.0 | ||
paths: | ||
/: | ||
get: | ||
parameters: | ||
- in: query | ||
name: idempotent | ||
schema: | ||
type: number | ||
example: 1 | ||
examples: | ||
example1: | ||
value: 2 | ||
`; | ||
const apiDOM = await parse(yamlDefinition); | ||
const openApiElement = OpenApi3_1Element.refract(apiDOM.result, { | ||
plugins: [refractorPluginNormalizeParameterExamples()], | ||
}) as OpenApi3_1Element; | ||
|
||
assert.deepEqual(toValue(openApiElement.get('x-normalized')), { | ||
'parameter-examples': ['/paths/~1/get/parameters/0'], | ||
}); | ||
}); | ||
|
||
context('given custom storage field', function () { | ||
specify('should use custom storage field to store normalized scopes', async function () { | ||
const yamlDefinition = dedent` | ||
openapi: 3.1.0 | ||
paths: | ||
/: | ||
get: | ||
parameters: | ||
- in: query | ||
name: idempotent | ||
schema: | ||
type: number | ||
example: 1 | ||
examples: | ||
example1: | ||
value: 2 | ||
`; | ||
const apiDOM = await parse(yamlDefinition); | ||
const openApiElement = OpenApi3_1Element.refract(apiDOM.result, { | ||
plugins: [ | ||
refractorPluginNormalizeParameterExamples({ | ||
storageField: '$$normalized', | ||
}), | ||
], | ||
}) as OpenApi3_1Element; | ||
|
||
assert.deepEqual(toValue(openApiElement.get('$$normalized')), { | ||
'parameter-examples': ['/paths/~1/get/parameters/0'], | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |