-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resolver): collect errors in ParameterMacroVisitor visitor hooks (…
…#2813) This change in specific to OpenAPI 3.1.0 resolution strategy. Errors are now collected, instead of thrown and visitor traversal is not interrupted. Refs #2812
- Loading branch information
Showing
5 changed files
with
268 additions
and
14 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
37 changes: 26 additions & 11 deletions
37
...apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.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 |
---|---|---|
@@ -1,27 +1,42 @@ | ||
import { toValue } from '@swagger-api/apidom-core'; | ||
|
||
const ParameterMacroVisitor = ({ parameterMacro }) => { | ||
let macroOperation = null; | ||
import compose from '../utils/compose.js'; | ||
import toPath from '../utils/to-path.js'; | ||
|
||
const ParameterMacroVisitor = compose({ | ||
init({ parameterMacro, options }) { | ||
this.parameterMacro = parameterMacro; | ||
this.options = options; | ||
}, | ||
props: { | ||
parameterMacro: null, | ||
options: null, | ||
macroOperation: null, | ||
|
||
return { | ||
OperationElement: { | ||
enter(operationElement) { | ||
macroOperation = operationElement; | ||
this.macroOperation = operationElement; | ||
}, | ||
leave() { | ||
macroOperation = null; | ||
this.macroOperation = null; | ||
}, | ||
}, | ||
ParameterElement: { | ||
leave(parameterElement) { | ||
const pojoOperation = macroOperation === null ? null : toValue(macroOperation); | ||
leave(parameterElement, key, parent, path, ancestors) { | ||
const pojoOperation = this.macroOperation === null ? null : toValue(this.macroOperation); | ||
const pojoParameter = toValue(parameterElement); | ||
const defaultValue = parameterMacro(pojoOperation, pojoParameter); | ||
|
||
parameterElement.set('default', defaultValue); | ||
try { | ||
const macroValue = this.parameterMacro(pojoOperation, pojoParameter); | ||
parameterElement.set('default', macroValue); | ||
} catch (error) { | ||
const macroError = new Error(error, { cause: error }); | ||
macroError.fullPath = toPath([...ancestors, parent]); | ||
this.options.dereference.dereferenceOpts?.errors?.push?.(macroError); | ||
} | ||
}, | ||
}, | ||
}; | ||
}; | ||
}, | ||
}); | ||
|
||
export default ParameterMacroVisitor; |
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