-
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 header example plugin
Refs #4134
- Loading branch information
Showing
9 changed files
with
268 additions
and
328 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
43 changes: 0 additions & 43 deletions
43
...1/test/refractor/plugins/normalize-header-examples/components/__snapshots__/index.ts.snap
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
...s/apidom-ns-openapi-3-1/test/refractor/plugins/normalize-header-examples/options/scope.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,81 @@ | ||
import { expect } from 'chai'; | ||
import dedent from 'dedent'; | ||
import { ObjectElement, toValue } from '@swagger-api/apidom-core'; | ||
import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; | ||
|
||
import { OpenApi3_1Element, refractorPluginNormalizeHeaderExamples } from '../../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('plugins', function () { | ||
context('normalize-header-examples', function () { | ||
context('given scope to limit the normalization', function () { | ||
specify('should limit the scope of normalization', async function () { | ||
const yamlDefinition = dedent` | ||
openapi: 3.1.0 | ||
paths: | ||
/: | ||
get: | ||
responses: | ||
"200": | ||
headers: | ||
content-type: | ||
schema: | ||
type: number | ||
example: 1 | ||
examples: | ||
example1: | ||
value: 2 | ||
"400": | ||
headers: | ||
content-type: | ||
schema: | ||
type: number | ||
example: 1 | ||
examples: | ||
example1: | ||
value: 2 | ||
`; | ||
const apiDOM = await parse(yamlDefinition); | ||
const openApiElement = OpenApi3_1Element.refract(apiDOM.result, { | ||
plugins: [ | ||
refractorPluginNormalizeHeaderExamples({ scope: '/paths/~1/get/responses/200' }), | ||
], | ||
}) as OpenApi3_1Element; | ||
|
||
expect(toValue(openApiElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
context('given scope and running normalization multiple times', function () { | ||
specify('should avoid normalizing the same scope multiple times', async function () { | ||
const yamlDefinition = dedent` | ||
openapi: 3.1.0 | ||
paths: | ||
/: | ||
get: | ||
responses: | ||
"200": | ||
headers: | ||
content-type: | ||
schema: | ||
type: number | ||
example: 1 | ||
examples: | ||
example1: | ||
value: 2 | ||
`; | ||
const apiDOM = await parse(yamlDefinition); | ||
const result = apiDOM.result as ObjectElement; | ||
result.set('x-normalized', ['/paths/~1/get/responses/200']); | ||
const openApiElement = OpenApi3_1Element.refract(apiDOM.result, { | ||
plugins: [ | ||
refractorPluginNormalizeHeaderExamples({ scope: '/paths/~1/get/responses/200' }), | ||
], | ||
}) as OpenApi3_1Element; | ||
|
||
expect(toValue(openApiElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.