persona-community-5/.pnpm-store/v3/files/f4/15aba97fc797ed1d194a34402eab46d407da93027b64469f233abed8d5c0e7eee717af532cd56386b8a47831dcf6126127466b1830db95b219868915e42f23
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

40 lines
1.2 KiB
Plaintext

import { getMatchingStatusCodeRange } from '../../utils';
import type { Oas3Rule } from '../../visitors';
import type { UserContext } from '../../walk';
export const ResponseContainsProperty: Oas3Rule = (options) => {
const names: Record<string, string[]> = options.names || {};
let key: string | number;
return {
Operation: {
Response: {
skip: (_response, key) => {
return `${key}` === '204';
},
enter: (_response, ctx: UserContext) => {
key = ctx.key;
},
MediaType: {
Schema(schema, { report, location }) {
if (schema.type !== 'object') return;
const expectedProperties =
names[key] ||
names[getMatchingStatusCodeRange(key)] ||
names[getMatchingStatusCodeRange(key).toLowerCase()] ||
[];
for (const expectedProperty of expectedProperties) {
if (!schema.properties?.[expectedProperty]) {
report({
message: `Response object must contain a top-level "${expectedProperty}" property.`,
location: location.child('properties').key(),
});
}
}
},
},
},
},
};
};