UNPKG

@redocly/openapi-core

Version:

See https://github.com/Redocly/redocly-cli

65 lines 2.57 kB
function countQuerystring(parameters) { return parameters.filter((p) => !('$ref' in p) && p.in === 'querystring').length; } function reportIfMultipleQuerystring(querystringCount, ctx) { const parametersLocation = ctx.location.child('parameters'); if (querystringCount > 1) { ctx.report({ message: 'Parameters with `in: querystring` should be defined only once per path/operation parameter set.', location: parametersLocation, }); } } function checkMixedUsage(parameter, parameterLocation, state, ctx) { if (parameter.in === 'query') { if (state.querystringLocation) { ctx.report({ message: 'Parameters with `in: query` cannot be used together with `in: querystring` in the same operation/path parameter set.', location: parameterLocation, }); } state.queryLocation ??= parameterLocation; return; } if (parameter.in === 'querystring') { if (state.queryLocation) { ctx.report({ message: 'Parameters with `in: querystring` cannot be used together with `in: query` in the same operation/path parameter set.', location: parameterLocation, }); } state.querystringLocation ??= parameterLocation; } } export const SpecQuerystringParameters = () => { let pathState = {}; let operationState = {}; let pathQuerystringCount = 0; return { PathItem: { enter(pathItem, ctx) { pathState = {}; operationState = {}; pathQuerystringCount = 0; reportIfMultipleQuerystring(countQuerystring(pathItem.parameters || []), ctx); }, Parameter(parameter, ctx) { checkMixedUsage(parameter, ctx.location, pathState, ctx); if (parameter.in === 'querystring') { pathQuerystringCount += 1; } }, Operation: { enter(operation, ctx) { operationState = { ...pathState }; const totalQuerystring = pathQuerystringCount + countQuerystring(operation.parameters || []); reportIfMultipleQuerystring(totalQuerystring, ctx); }, Parameter(parameter, ctx) { checkMixedUsage(parameter, ctx.location, operationState, ctx); }, }, }, }; }; //# sourceMappingURL=spec-querystring-parameters.js.map