persona-community-5/.pnpm-store/v3/files/d8/620c12db78fde6df7d87e84f029cd17765b9f51be6f3f62253ee61c5fe5fbc143d11e5e1a7edb8b9a895ad8a0752db8a20e615aca95c032a0d44a527e7e0d1
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

37 lines
1.3 KiB
Plaintext

import { getMatchingStatusCodeRange } from '../../utils';
import type { Oas2Rule, Oas3Rule } from '../../visitors';
import type { UserContext } from '../../walk';
import type { Oas3Response } from '../../typings/openapi';
import type { Oas2Response } from '../../typings/swagger';
export const ResponseContainsHeader: Oas3Rule | Oas2Rule = (options) => {
const names: Record<string, string[]> = options.names || {};
return {
Operation: {
Response: {
enter: (response: Oas2Response | Oas3Response, { report, location, key }: UserContext) => {
const expectedHeaders =
names[key] ||
names[getMatchingStatusCodeRange(key)] ||
names[getMatchingStatusCodeRange(key).toLowerCase()] ||
[];
for (const expectedHeader of expectedHeaders) {
if (
!response?.headers ||
!Object.keys(response?.headers).some(
(header) => header.toLowerCase() === expectedHeader.toLowerCase()
)
) {
report({
message: `Response object must contain a "${expectedHeader}" header.`,
location: location.child('headers').key(),
});
}
}
},
},
},
};
};