-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(resolver): apply propertyMacro, parameterMacro and allOf plugins …
…for OpenAPI 3.1.0 (#3521) Refs #3520 --------- Co-authored-by: Vladimir Gorej <[email protected]>
- Loading branch information
Showing
13 changed files
with
1,997 additions
and
2,306 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ module.exports = { | |
'/__fixtures__/', | ||
'/__utils__/', | ||
], | ||
silent: false, | ||
silent: true, | ||
}; |
Large diffs are not rendered by default.
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
39 changes: 39 additions & 0 deletions
39
...olver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/root.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { mergeAllVisitors } from '@swagger-api/apidom-core'; | ||
import { getNodeType } from '@swagger-api/apidom-ns-openapi-3-1'; | ||
|
||
import ModelPropertyMacroVisitor from './properties.js'; | ||
import AllOfVisitor from './all-of.js'; | ||
import ParameterMacroVisitor from './parameters.js'; | ||
import OpenAPI3_1SwaggerClientDereferenceVisitor from './dereference.js'; // eslint-disable-line camelcase | ||
|
||
const mergeAllVisitorsAsync = mergeAllVisitors[Symbol.for('nodejs.util.promisify.custom')]; | ||
|
||
class RootVisitor { | ||
constructor({ parameterMacro, modelPropertyMacro, mode, options, ...rest }) { | ||
const visitors = []; | ||
|
||
visitors.push( | ||
new OpenAPI3_1SwaggerClientDereferenceVisitor({ | ||
...rest, | ||
options, | ||
}) | ||
); | ||
|
||
if (typeof modelPropertyMacro === 'function') { | ||
visitors.push(new ModelPropertyMacroVisitor({ modelPropertyMacro, options })); | ||
} | ||
|
||
if (mode !== 'strict') { | ||
visitors.push(new AllOfVisitor({ options })); | ||
} | ||
|
||
if (typeof parameterMacro === 'function') { | ||
visitors.push(new ParameterMacroVisitor({ parameterMacro, options })); | ||
} | ||
|
||
const mergedVisitor = mergeAllVisitorsAsync(visitors, { nodeTypeGetter: getNodeType }); | ||
Object.assign(this, mergedVisitor); | ||
} | ||
} | ||
|
||
export default RootVisitor; |
95 changes: 95 additions & 0 deletions
95
...nce/dereference/strategies/openapi-3-1-swagger-client/parameter-object/parameter-macro.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* eslint-disable camelcase */ | ||
import { toValue } from '@swagger-api/apidom-core'; | ||
import { mediaTypes, OpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1'; | ||
import { dereferenceApiDOM } from '@swagger-api/apidom-reference/configuration/empty'; | ||
|
||
import * as jestSetup from '../__utils__/jest.local.setup.js'; | ||
import OpenAPI3_1SwaggerClientDereferenceStrategy from '../../../../../../../../src/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js'; | ||
|
||
describe('dereference', () => { | ||
beforeAll(() => { | ||
jestSetup.beforeAll(); | ||
}); | ||
|
||
afterAll(() => { | ||
jestSetup.afterAll(); | ||
}); | ||
|
||
describe('strategies', () => { | ||
describe('openapi-3-1-swagger-client', () => { | ||
describe('Parametr Object', () => { | ||
test('should resolve reference and apply modelPropertyMacro function', async () => { | ||
const spec = OpenApi3_1Element.refract({ | ||
openapi: '3.1.0', | ||
paths: { | ||
'/': { | ||
get: { | ||
operationId: 'test', | ||
parameters: [ | ||
{ | ||
$ref: '#/components/parameters/Baz', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
components: { | ||
parameters: { | ||
Baz: { | ||
name: 'baz', | ||
in: 'query', | ||
schema: { | ||
type: 'object', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const dereferenced = await dereferenceApiDOM(spec, { | ||
parse: { mediaType: mediaTypes.latest('json') }, | ||
dereference: { | ||
strategies: [ | ||
new OpenAPI3_1SwaggerClientDereferenceStrategy({ | ||
parameterMacro: (operation, parameter) => | ||
`${operation.operationId}-${parameter.name}`, | ||
}), | ||
], | ||
}, | ||
}); | ||
|
||
expect(toValue(dereferenced)).toEqual({ | ||
openapi: '3.1.0', | ||
paths: { | ||
'/': { | ||
get: { | ||
operationId: 'test', | ||
parameters: [ | ||
{ | ||
name: 'baz', | ||
in: 'query', | ||
schema: { type: 'object' }, | ||
default: 'test-baz', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
components: { | ||
parameters: { | ||
Baz: { | ||
name: 'baz', | ||
in: 'query', | ||
schema: { | ||
type: 'object', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
/* eslint-enable camelcase */ |
Oops, something went wrong.