contractdiff 0.0.0-stage → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +228 -2
- package/dist/bin.js +4 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +24 -0
- package/dist/command-diff.js +310 -0
- package/dist/command-explain-cap.js +36 -0
- package/dist/command-explain-inline.js +17 -0
- package/dist/command-explain-name.js +31 -0
- package/dist/command-explain-operation.js +85 -0
- package/dist/command-explain-text.js +21 -0
- package/dist/command-explain.js +54 -0
- package/dist/command-lint.js +280 -0
- package/dist/command-migrate.js +70 -0
- package/dist/command-plugin.js +32 -0
- package/dist/command-props.js +116 -0
- package/dist/commands.js +7 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +2 -0
- package/dist/core/model.d.ts +46 -0
- package/dist/core/model.js +1 -0
- package/dist/core/resolve.d.ts +22 -0
- package/dist/core/resolve.js +71 -0
- package/dist/diff-classify.js +30 -0
- package/dist/diff-contract.js +176 -0
- package/dist/diff-decisions.js +446 -0
- package/dist/diff-normalise.js +143 -0
- package/dist/diff-rules.js +109 -0
- package/dist/diff-schema.js +335 -0
- package/dist/diff-security.js +33 -0
- package/dist/diff-transitive.js +26 -0
- package/dist/diff-usage.js +59 -0
- package/dist/extract-normalise.js +85 -0
- package/dist/extract-roundtrip.js +28 -0
- package/dist/extract-standard.js +79 -0
- package/dist/gen-ts-ast.d.ts +135 -0
- package/dist/gen-ts-ast.js +52 -0
- package/dist/gen-ts-bundle.js +233 -0
- package/dist/gen-ts-comment.js +48 -0
- package/dist/gen-ts-context.d.ts +83 -0
- package/dist/gen-ts-context.js +45 -0
- package/dist/gen-ts-dict.d.ts +14 -0
- package/dist/gen-ts-dict.js +14 -0
- package/dist/gen-ts-discriminators.d.ts +7 -0
- package/dist/gen-ts-discriminators.js +117 -0
- package/dist/gen-ts-document.d.ts +12 -0
- package/dist/gen-ts-document.js +82 -0
- package/dist/gen-ts-enums.js +139 -0
- package/dist/gen-ts-helpers.js +30 -0
- package/dist/gen-ts-index.d.ts +49 -0
- package/dist/gen-ts-index.js +110 -0
- package/dist/gen-ts-operations.js +277 -0
- package/dist/gen-ts-print.js +113 -0
- package/dist/gen-ts-ref.d.ts +30 -0
- package/dist/gen-ts-ref.js +75 -0
- package/dist/gen-ts-schema.js +283 -0
- package/dist/gen-ts-text.d.ts +24 -0
- package/dist/gen-ts-text.js +98 -0
- package/dist/host.d.ts +145 -0
- package/dist/host.js +273 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/input-asyncapi.js +167 -0
- package/dist/input-buf.js +58 -0
- package/dist/input-jsonschema.js +165 -0
- package/dist/input-mcp.js +111 -0
- package/dist/input-overlay-jsonpath.js +265 -0
- package/dist/input-overlay.js +138 -0
- package/dist/input-protobuf.js +212 -0
- package/dist/input-swagger2.js +331 -0
- package/dist/inputs.js +8 -0
- package/dist/lint-code-read.js +129 -0
- package/dist/lint-code.d.ts +56 -0
- package/dist/lint-code.js +64 -0
- package/dist/lint-engine.d.ts +93 -0
- package/dist/lint-engine.js +87 -0
- package/dist/lint-functions.js +95 -0
- package/dist/lint-history.js +133 -0
- package/dist/lint-jsonpath.js +92 -0
- package/dist/lint-names.d.ts +11 -0
- package/dist/lint-names.js +2 -0
- package/dist/lint-redocly.js +141 -0
- package/dist/lint-rules.js +189 -0
- package/dist/lint-select.d.ts +33 -0
- package/dist/lint-select.js +129 -0
- package/dist/lint-since.js +20 -0
- package/dist/lint-spectral.js +167 -0
- package/dist/lint-stats.js +58 -0
- package/dist/migrate-hey-api.js +144 -0
- package/dist/migrate-literal.js +139 -0
- package/dist/migrate-openapi-fetch.js +62 -0
- package/dist/migrate-openapi-typescript.js +159 -0
- package/dist/migrate-orval.js +119 -0
- package/dist/migrate-shared.js +31 -0
- package/dist/openapi-typescript.d.ts +9 -0
- package/dist/openapi-typescript.js +36 -0
- package/dist/openapi.d.ts +20 -0
- package/dist/openapi.js +94 -0
- package/dist/plugin-express.js +66 -0
- package/dist/plugin-extract-hono.js +1 -0
- package/dist/plugin-extract-nest.js +1 -0
- package/dist/plugin-extract-openapi.js +246 -0
- package/dist/plugin-extract-standard-schema.js +42 -0
- package/dist/plugin-extract-trpc.js +1 -0
- package/dist/plugin-extract-ts-rest.js +77 -0
- package/dist/plugin-fastify.js +68 -0
- package/dist/plugin-fetch-client.js +172 -0
- package/dist/plugin-fetch-routes.js +110 -0
- package/dist/plugin-fetch-sample.js +155 -0
- package/dist/plugin-fetch-text.js +5 -0
- package/dist/plugin-fetch.js +19 -0
- package/dist/plugin-hono.js +42 -0
- package/dist/plugin-json-schema-build.js +289 -0
- package/dist/plugin-json-schema-dialect-anthropic.js +41 -0
- package/dist/plugin-json-schema-dialect-gemini.js +29 -0
- package/dist/plugin-json-schema-dialect-mcp-elicitation.js +32 -0
- package/dist/plugin-json-schema-dialect-mcp.js +13 -0
- package/dist/plugin-json-schema-dialect-openai.js +37 -0
- package/dist/plugin-json-schema-dialect.js +180 -0
- package/dist/plugin-json-schema.js +125 -0
- package/dist/plugin-markdown.js +114 -0
- package/dist/plugin-mcp-code.js +28 -0
- package/dist/plugin-mcp-tools.js +152 -0
- package/dist/plugin-mcp.js +107 -0
- package/dist/plugin-msw-files.js +50 -0
- package/dist/plugin-msw-sample.js +45 -0
- package/dist/plugin-msw-synth.js +116 -0
- package/dist/plugin-msw.js +30 -0
- package/dist/plugin-nest-code.js +68 -0
- package/dist/plugin-nest-contract.js +23 -0
- package/dist/plugin-nest.js +44 -0
- package/dist/plugin-server-code.js +61 -0
- package/dist/plugin-server-contract.js +48 -0
- package/dist/plugin-server-example.js +62 -0
- package/dist/plugin-server-router.js +77 -0
- package/dist/plugin-server-routes.js +155 -0
- package/dist/plugin-server-runtime.js +3 -0
- package/dist/plugin-server-sample.js +40 -0
- package/dist/plugin-swr-sample.js +21 -0
- package/dist/plugin-swr.js +40 -0
- package/dist/plugin-tanstack-query-sample.js +21 -0
- package/dist/plugin-tanstack-query.js +59 -0
- package/dist/plugin-types.js +80 -0
- package/dist/plugin-validator-code.js +41 -0
- package/dist/plugin-validator-names.js +27 -0
- package/dist/plugin-validator.js +103 -0
- package/dist/plugins.js +21 -0
- package/dist/props-emit.js +194 -0
- package/dist/props-generate.js +409 -0
- package/dist/props-judge.js +61 -0
- package/dist/props-mutate.js +144 -0
- package/dist/props-random.js +25 -0
- package/dist/props-run.js +176 -0
- package/dist/props-shrink.js +75 -0
- package/dist/run-apply.js +25 -0
- package/dist/run-command.js +31 -0
- package/dist/run-commit.d.ts +51 -0
- package/dist/run-commit.js +48 -0
- package/dist/run-config.d.ts +193 -0
- package/dist/run-config.js +256 -0
- package/dist/run-diff.js +24 -0
- package/dist/run-extract.d.ts +13 -0
- package/dist/run-extract.js +21 -0
- package/dist/run-gen.d.ts +15 -0
- package/dist/run-gen.js +43 -0
- package/dist/run-header.js +37 -0
- package/dist/run-input.js +31 -0
- package/dist/run-load.js +32 -0
- package/dist/run-map.d.ts +41 -0
- package/dist/run-map.js +52 -0
- package/dist/run-plan.d.ts +31 -0
- package/dist/run-plan.js +35 -0
- package/dist/scaffold-seed.js +43 -0
- package/dist/scaffold-write.js +17 -0
- package/dist/scaffold.js +196 -0
- package/dist/testing-lint.js +43 -0
- package/dist/testing-owner.js +17 -0
- package/dist/testing-probe.js +25 -0
- package/dist/testing-rules.d.ts +65 -0
- package/dist/testing-rules.js +115 -0
- package/dist/testing.d.ts +32 -0
- package/dist/testing.js +79 -0
- package/package.json +108 -4
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { pair } from './diff-contract.js';
|
|
2
|
+
import { isDict } from './diff-normalise.js';
|
|
3
|
+
export const MARKERS = ['x-change', 'x-sunset', 'x-replaced-by'];
|
|
4
|
+
export const keyOf = (operation, payload, pointer) => `${operation}\n${payload}\n${pointer}`;
|
|
5
|
+
const token = (key) => key.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
6
|
+
const arrayOf = (value) => (Array.isArray(value) ? value : []);
|
|
7
|
+
export const wordsFor = (...parts) => parts.filter((part) => part !== undefined && part !== '').join(' ');
|
|
8
|
+
export const decisionFinding = (level, rule, place, detail) => ({
|
|
9
|
+
id: `ac-decision-${rule}`,
|
|
10
|
+
scheme: 'contractdiff',
|
|
11
|
+
verdict: level === 'error' ? 'breaking' : 'unknown',
|
|
12
|
+
effect: 'neutral',
|
|
13
|
+
operation: place.operation,
|
|
14
|
+
source: place.source,
|
|
15
|
+
document: place.document,
|
|
16
|
+
...(place.payload === undefined ? {} : { payload: place.payload }),
|
|
17
|
+
direction: place.direction,
|
|
18
|
+
pointer: place.pointer,
|
|
19
|
+
before: detail.before,
|
|
20
|
+
after: detail.after,
|
|
21
|
+
fix: detail.fix,
|
|
22
|
+
});
|
|
23
|
+
const DATE = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
|
|
24
|
+
export const isDate = (value) => {
|
|
25
|
+
const parts = DATE.exec(String(value))?.groups;
|
|
26
|
+
if (parts === undefined)
|
|
27
|
+
return false;
|
|
28
|
+
const day = new Date(Date.UTC(Number(parts.year), Number(parts.month) - 1, Number(parts.day)));
|
|
29
|
+
return day.toISOString().slice(0, 'YYYY-MM-DD'.length) === value;
|
|
30
|
+
};
|
|
31
|
+
const POINTER = /^(?:\/(?:[^~/]|~[01])*)*$/;
|
|
32
|
+
export const isReplacement = (value) => {
|
|
33
|
+
if (typeof value !== 'string' || value === '')
|
|
34
|
+
return false;
|
|
35
|
+
return value.startsWith('/') ? POINTER.test(value) : !value.includes('/');
|
|
36
|
+
};
|
|
37
|
+
export const isText = (value) => typeof value === 'string' && value.trim() !== '';
|
|
38
|
+
const FORMS = {
|
|
39
|
+
'x-change': [isText, 'write `x-change: <the decision>`: an ADR id, a ticket or a URL, as non-empty text'],
|
|
40
|
+
'x-sunset': [isDate, 'write `x-sunset: 2027-03-01`: a real date as YYYY-MM-DD'],
|
|
41
|
+
'x-replaced-by': [isReplacement, "write `x-replaced-by:` as a sibling member's name (`amountCents`) or a JSON Pointer to one (`/properties/amountCents`)"],
|
|
42
|
+
};
|
|
43
|
+
const markersOf = (holder, invalid) => {
|
|
44
|
+
const valid = (marker) => {
|
|
45
|
+
const value = holder[marker];
|
|
46
|
+
if (value === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
const [accepts, fix] = FORMS[marker];
|
|
49
|
+
if (accepts(value))
|
|
50
|
+
return value;
|
|
51
|
+
invalid(marker, value, fix);
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
54
|
+
const change = valid('x-change');
|
|
55
|
+
const sunset = valid('x-sunset');
|
|
56
|
+
const replacedBy = valid('x-replaced-by');
|
|
57
|
+
return {
|
|
58
|
+
...(change === undefined ? {} : { change }),
|
|
59
|
+
...(sunset === undefined ? {} : { sunset }),
|
|
60
|
+
...(replacedBy === undefined ? {} : { replacedBy }),
|
|
61
|
+
...(holder.deprecated === true ? { deprecated: true } : {}),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export const distance = (a, b) => {
|
|
65
|
+
const last = [...a].reduce((row, left, i) => [...b].reduce((next, right, j) => [...next, Math.min(row[j + 1] + 1, next[j] + 1, row[j] + (left === right ? 0 : 1))], [i + 1]), Array.from({ length: b.length + 1 }, (_, j) => j));
|
|
66
|
+
return last.at(-1);
|
|
67
|
+
};
|
|
68
|
+
export const meant = (key) => {
|
|
69
|
+
if (!key.startsWith('x-') || MARKERS.includes(key))
|
|
70
|
+
return undefined;
|
|
71
|
+
return MARKERS.find((marker) => distance(key, marker) <= 2);
|
|
72
|
+
};
|
|
73
|
+
const place = (at, pointer) => ({
|
|
74
|
+
operation: at.operation.id,
|
|
75
|
+
source: at.operation.source,
|
|
76
|
+
document: 'new',
|
|
77
|
+
...(at.payload === '' ? {} : { payload: at.payload }),
|
|
78
|
+
direction: at.direction,
|
|
79
|
+
pointer,
|
|
80
|
+
});
|
|
81
|
+
const BAD_ESCAPE = /%(?![\dA-Fa-f]{2})/;
|
|
82
|
+
export const lookup = (document, ref) => {
|
|
83
|
+
const fragment = ref.slice(1);
|
|
84
|
+
if (!ref.startsWith('#') || BAD_ESCAPE.test(fragment))
|
|
85
|
+
return undefined;
|
|
86
|
+
if (fragment === '')
|
|
87
|
+
return document;
|
|
88
|
+
if (!fragment.startsWith('/'))
|
|
89
|
+
return undefined;
|
|
90
|
+
return decodeURIComponent(fragment)
|
|
91
|
+
.slice(1)
|
|
92
|
+
.split('/')
|
|
93
|
+
.reduce((node, part) => {
|
|
94
|
+
const key = part.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
95
|
+
return (isDict(node) || Array.isArray(node)) && Object.hasOwn(node, key) ? node[key] : undefined;
|
|
96
|
+
}, document);
|
|
97
|
+
};
|
|
98
|
+
const deref = (document, value) => {
|
|
99
|
+
let node = value;
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
while (isDict(node) && typeof node.$ref === 'string' && !seen.has(node.$ref)) {
|
|
102
|
+
seen.add(node.$ref);
|
|
103
|
+
node = lookup(document, node.$ref);
|
|
104
|
+
}
|
|
105
|
+
return isDict(node) ? node : undefined;
|
|
106
|
+
};
|
|
107
|
+
const record = (scan, at, pointer, holder) => {
|
|
108
|
+
const fields = markersOf(holder, (marker, value, fix) => {
|
|
109
|
+
scan.problems.push(decisionFinding(scan.level, 'invalid', place(at, pointer), {
|
|
110
|
+
before: value,
|
|
111
|
+
after: undefined,
|
|
112
|
+
fix: `${wordsFor(at.operation.id, at.payload, pointer)} has a bad \`${marker}\`. fix: ${fix}`,
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
if (Object.keys(fields).length === 0)
|
|
116
|
+
return;
|
|
117
|
+
const key = keyOf(at.operation.id, at.payload, pointer);
|
|
118
|
+
scan.decisions.set(key, {
|
|
119
|
+
...fields,
|
|
120
|
+
...scan.decisions.get(key),
|
|
121
|
+
operation: at.operation.id,
|
|
122
|
+
payload: at.payload,
|
|
123
|
+
pointer,
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
const COMPOSITIONS = ['oneOf', 'anyOf', 'allOf'];
|
|
127
|
+
const childrenOf = (schema, pointer) => [
|
|
128
|
+
...Object.entries(isDict(schema.properties) ? schema.properties : {}).map(([name, child]) => [child, `${pointer}/properties/${token(name)}`]),
|
|
129
|
+
[schema.additionalProperties, `${pointer}/additionalProperties`],
|
|
130
|
+
[schema.items, `${pointer}/items`],
|
|
131
|
+
...arrayOf(schema.prefixItems).map((child, index) => [child, `${pointer}/prefixItems/${String(index)}`]),
|
|
132
|
+
...COMPOSITIONS.flatMap((keyword) => arrayOf(schema[keyword]).map((child, index) => [child, `${pointer}/${keyword}/${String(index)}`])),
|
|
133
|
+
];
|
|
134
|
+
const localRef = (schema) => (typeof schema.$ref === 'string' ? schema.$ref : undefined);
|
|
135
|
+
const follow = (scan, at, schema, pointer) => {
|
|
136
|
+
const ref = localRef(schema);
|
|
137
|
+
if (ref === undefined)
|
|
138
|
+
return;
|
|
139
|
+
if (!at.open.has(ref) && !isMarkerFree(scan, ref))
|
|
140
|
+
walk(scan, { ...at, open: new Set([...at.open, ref]) }, lookup(scan.contract.document, ref), pointer);
|
|
141
|
+
};
|
|
142
|
+
const holdsMarker = (node) => {
|
|
143
|
+
if (Array.isArray(node))
|
|
144
|
+
return node.some((item) => holdsMarker(item));
|
|
145
|
+
if (!isDict(node))
|
|
146
|
+
return false;
|
|
147
|
+
return Object.entries(node).some(([key, child]) => MARKERS.includes(key) || holdsMarker(child));
|
|
148
|
+
};
|
|
149
|
+
const isMarkerFree = (scan, ref) => {
|
|
150
|
+
const known = scan.markerFree.get(ref);
|
|
151
|
+
if (known !== undefined)
|
|
152
|
+
return known;
|
|
153
|
+
const seen = new Set([ref]);
|
|
154
|
+
const queue = [ref];
|
|
155
|
+
let free = true;
|
|
156
|
+
while (free && queue.length > 0) {
|
|
157
|
+
const target = lookup(scan.contract.document, queue.pop());
|
|
158
|
+
if (holdsMarker(target))
|
|
159
|
+
free = false;
|
|
160
|
+
for (const next of refsIn(target)) {
|
|
161
|
+
if (!seen.has(next)) {
|
|
162
|
+
seen.add(next);
|
|
163
|
+
queue.push(next);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
scan.markerFree.set(ref, free);
|
|
168
|
+
return free;
|
|
169
|
+
};
|
|
170
|
+
const refsIn = (node, into = []) => {
|
|
171
|
+
if (Array.isArray(node))
|
|
172
|
+
for (const item of node)
|
|
173
|
+
refsIn(item, into);
|
|
174
|
+
else if (isDict(node)) {
|
|
175
|
+
const ref = localRef(node);
|
|
176
|
+
if (ref !== undefined)
|
|
177
|
+
into.push(ref);
|
|
178
|
+
for (const child of Object.values(node))
|
|
179
|
+
refsIn(child, into);
|
|
180
|
+
}
|
|
181
|
+
return into;
|
|
182
|
+
};
|
|
183
|
+
const facesOf = (document, schema, seen = new Set()) => {
|
|
184
|
+
if (!isDict(schema) || seen.has(schema))
|
|
185
|
+
return [];
|
|
186
|
+
seen.add(schema);
|
|
187
|
+
const ref = localRef(schema);
|
|
188
|
+
return [schema, ...(ref === undefined ? [] : facesOf(document, lookup(document, ref), seen)), ...arrayOf(schema.allOf).flatMap((branch) => facesOf(document, branch, seen))];
|
|
189
|
+
};
|
|
190
|
+
const memberIn = (document, schema, pointer) => {
|
|
191
|
+
if (pointer === '')
|
|
192
|
+
return isDict(schema);
|
|
193
|
+
return facesOf(document, schema).some((face) => childrenOf(face, '').some(([child, where]) => (pointer === where || pointer.startsWith(`${where}/`)) && memberIn(document, child, pointer.slice(where.length))));
|
|
194
|
+
};
|
|
195
|
+
const walk = (scan, at, schema, pointer) => {
|
|
196
|
+
if (!isDict(schema))
|
|
197
|
+
return;
|
|
198
|
+
scan.members.add(keyOf(at.operation.id, at.payload, pointer));
|
|
199
|
+
record(scan, at, pointer, schema);
|
|
200
|
+
follow(scan, at, schema, pointer);
|
|
201
|
+
for (const [child, where] of childrenOf(schema, pointer))
|
|
202
|
+
walk(scan, at, child, where);
|
|
203
|
+
for (const branch of arrayOf(schema.allOf))
|
|
204
|
+
walk(scan, at, branch, pointer);
|
|
205
|
+
};
|
|
206
|
+
const memberOf = (contract, key) => {
|
|
207
|
+
const [id, payload, pointer] = key.split('\n');
|
|
208
|
+
const schema = contract.operations.find((operation) => operation.id === id)?.payloads.find((candidate) => candidate.name === payload)?.schema;
|
|
209
|
+
return memberIn(contract.document, schema, pointer);
|
|
210
|
+
};
|
|
211
|
+
const parametersOf = (document, operation, declared) => {
|
|
212
|
+
const parent = lookup(document, operation.source.slice(0, operation.source.lastIndexOf('/')));
|
|
213
|
+
const entries = [...arrayOf(isDict(parent) ? parent.parameters : undefined), ...arrayOf(declared.parameters)];
|
|
214
|
+
return new Map(entries.flatMap((entry) => {
|
|
215
|
+
const parameter = deref(document, entry);
|
|
216
|
+
return parameter === undefined ? [] : [[`param:${String(parameter.in)}:${String(parameter.name)}`, parameter]];
|
|
217
|
+
}));
|
|
218
|
+
};
|
|
219
|
+
const markSubtree = (document, node, marked) => {
|
|
220
|
+
if (!(isDict(node) || Array.isArray(node)))
|
|
221
|
+
return;
|
|
222
|
+
if (marked.has(node))
|
|
223
|
+
return;
|
|
224
|
+
marked.add(node);
|
|
225
|
+
const ref = isDict(node) ? localRef(node) : undefined;
|
|
226
|
+
if (ref !== undefined)
|
|
227
|
+
markSubtree(document, lookup(document, ref), marked);
|
|
228
|
+
for (const child of Object.values(node))
|
|
229
|
+
markSubtree(document, child, marked);
|
|
230
|
+
};
|
|
231
|
+
const DATA = new Set(['example', 'examples', 'default', 'enum', 'const']);
|
|
232
|
+
const audit = (scan, holders, node, pointer) => {
|
|
233
|
+
const here = `#${pointer}`;
|
|
234
|
+
const where = () => ({
|
|
235
|
+
operation: scan.contract.operations.find((operation) => here === operation.source || here.startsWith(`${operation.source}/`))?.id ?? '(document)',
|
|
236
|
+
source: here,
|
|
237
|
+
document: 'new',
|
|
238
|
+
direction: 'request',
|
|
239
|
+
pointer: '',
|
|
240
|
+
});
|
|
241
|
+
const allowed = holders.objects.has(node) || holders.schemas.has(node);
|
|
242
|
+
for (const key of Object.keys(node)) {
|
|
243
|
+
const right = meant(key);
|
|
244
|
+
if (right !== undefined) {
|
|
245
|
+
scan.problems.push(decisionFinding(scan.level, 'misspelled', where(), {
|
|
246
|
+
before: key,
|
|
247
|
+
after: right,
|
|
248
|
+
fix: `\`${key}\` at ${here} is not a marker. fix: rename it \`${right}\``,
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
else if (!allowed && MARKERS.includes(key)) {
|
|
252
|
+
scan.problems.push(decisionFinding(scan.level, 'misplaced', where(), {
|
|
253
|
+
before: key,
|
|
254
|
+
after: node[key],
|
|
255
|
+
fix: `\`${key}\` at ${here} is not on a schema member, an operation or a parameter. fix: move it onto the member it describes, or remove it`,
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const scanDocument = (scan, holders, node, pointer) => {
|
|
261
|
+
if (typeof node !== 'object' || node === null)
|
|
262
|
+
return;
|
|
263
|
+
audit(scan, holders, node, pointer);
|
|
264
|
+
for (const [key, child] of Object.entries(node)) {
|
|
265
|
+
if (!DATA.has(key))
|
|
266
|
+
scanDocument(scan, holders, child, `${pointer}/${token(key)}`);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
const unique = (findings) => [
|
|
270
|
+
...new Map(findings.map((finding) => [JSON.stringify([finding.id, finding.operation, finding.source, finding.payload, finding.pointer, finding.before]), finding])).values(),
|
|
271
|
+
];
|
|
272
|
+
export const readDecisions = (contract, level) => {
|
|
273
|
+
const scan = {
|
|
274
|
+
contract,
|
|
275
|
+
level,
|
|
276
|
+
decisions: new Map(),
|
|
277
|
+
members: new Set(),
|
|
278
|
+
problems: [],
|
|
279
|
+
markerFree: new Map(),
|
|
280
|
+
};
|
|
281
|
+
const holders = { objects: new Set(), schemas: new Set() };
|
|
282
|
+
for (const operation of contract.operations) {
|
|
283
|
+
const declared = lookup(contract.document, operation.source);
|
|
284
|
+
const parameters = isDict(declared) ? parametersOf(contract.document, operation, declared) : new Map();
|
|
285
|
+
scan.members.add(keyOf(operation.id, '', ''));
|
|
286
|
+
if (isDict(declared)) {
|
|
287
|
+
holders.objects.add(declared);
|
|
288
|
+
record(scan, { operation, payload: '', direction: 'request', open: new Set() }, '', declared);
|
|
289
|
+
}
|
|
290
|
+
for (const payload of operation.payloads) {
|
|
291
|
+
const at = {
|
|
292
|
+
operation,
|
|
293
|
+
payload: payload.name,
|
|
294
|
+
direction: payload.direction,
|
|
295
|
+
open: new Set(),
|
|
296
|
+
};
|
|
297
|
+
const parameter = parameters.get(payload.name);
|
|
298
|
+
scan.members.add(keyOf(operation.id, payload.name, ''));
|
|
299
|
+
if (parameter !== undefined) {
|
|
300
|
+
holders.objects.add(parameter);
|
|
301
|
+
record(scan, at, '', parameter);
|
|
302
|
+
}
|
|
303
|
+
walk(scan, at, payload.schema, '');
|
|
304
|
+
markSubtree(contract.document, payload.schema, holders.schemas);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
scanDocument(scan, holders, contract.document, '');
|
|
308
|
+
return {
|
|
309
|
+
decisions: scan.decisions,
|
|
310
|
+
members: { has: (key) => scan.members.has(key) || memberOf(contract, key) },
|
|
311
|
+
problems: unique(scan.problems),
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
export const decisionsOf = (contract) => readDecisions(contract).decisions;
|
|
315
|
+
export const prefixes = (pointer) => {
|
|
316
|
+
const parts = pointer.split('/');
|
|
317
|
+
return parts.map((_, index) => parts.slice(0, parts.length - index).join('/'));
|
|
318
|
+
};
|
|
319
|
+
const inForce = (side, member, wanted) => {
|
|
320
|
+
const own = member.payload === undefined ? [] : prefixes(member.pointer).map((pointer) => keyOf(member.operation, member.payload, pointer));
|
|
321
|
+
const keys = [...own, keyOf(member.operation, '', '')];
|
|
322
|
+
return keys.map((key) => side.decisions.get(key)).find((decision) => decision !== undefined && wanted(decision));
|
|
323
|
+
};
|
|
324
|
+
const carriedOut = (today) => (decision) => decision.deprecated === true && decision.sunset !== undefined && decision.sunset <= today;
|
|
325
|
+
const hasChange = (decision) => decision.change !== undefined;
|
|
326
|
+
const placeOf = (finding) => ({
|
|
327
|
+
operation: finding.operation,
|
|
328
|
+
source: finding.source,
|
|
329
|
+
document: finding.document,
|
|
330
|
+
payload: finding.payload,
|
|
331
|
+
direction: finding.direction,
|
|
332
|
+
pointer: finding.pointer,
|
|
333
|
+
});
|
|
334
|
+
const operationOf = (sides, decision) => sides.newContract.operations.find((candidate) => candidate.id === decision.operation);
|
|
335
|
+
const placeOfDecision = (sides, decision) => {
|
|
336
|
+
const operation = operationOf(sides, decision);
|
|
337
|
+
return {
|
|
338
|
+
operation: operation.id,
|
|
339
|
+
source: operation.source,
|
|
340
|
+
document: 'new',
|
|
341
|
+
...(decision.payload === '' ? {} : { payload: decision.payload }),
|
|
342
|
+
direction: operation.payloads.find((payload) => payload.name === decision.payload)?.direction ?? 'request',
|
|
343
|
+
pointer: decision.pointer,
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
const wordsOfDecision = (decision) => wordsFor(decision.operation, decision.payload, decision.pointer);
|
|
347
|
+
const holdBreaking = (sides, comparison) => {
|
|
348
|
+
const held = { findings: [], decidedBy: new Map() };
|
|
349
|
+
for (const finding of comparison.findings.filter((candidate) => candidate.verdict === 'breaking')) {
|
|
350
|
+
const oldMember = { ...finding, operation: sides.oldOf.get(finding.operation).id };
|
|
351
|
+
if (inForce(sides.old, oldMember, carriedOut(sides.options.today)) !== undefined)
|
|
352
|
+
continue;
|
|
353
|
+
const decision = inForce(sides.nu, finding, hasChange);
|
|
354
|
+
if (decision !== undefined) {
|
|
355
|
+
held.decidedBy.set(keyOf(decision.operation, decision.payload, decision.pointer), decision);
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const where = wordsFor(finding.operation, finding.payload, finding.pointer);
|
|
359
|
+
held.findings.push(decisionFinding(sides.options.level, 'missing', placeOf(finding), {
|
|
360
|
+
before: finding.before,
|
|
361
|
+
after: finding.after,
|
|
362
|
+
fix: `breaking change (\`${finding.id}\`) at ${where} with no decision. fix: add \`x-change: <the decision>\` to ${where}, or an ancestor or its operation, naming who decided it; or revert the change`,
|
|
363
|
+
}));
|
|
364
|
+
}
|
|
365
|
+
return held;
|
|
366
|
+
};
|
|
367
|
+
export const covers = (decision, finding) => {
|
|
368
|
+
if (finding.operation !== decision.operation)
|
|
369
|
+
return false;
|
|
370
|
+
if (decision.payload === '' || finding.payload === undefined)
|
|
371
|
+
return true;
|
|
372
|
+
return finding.payload === decision.payload && (finding.pointer === decision.pointer || finding.pointer.startsWith(`${decision.pointer}/`));
|
|
373
|
+
};
|
|
374
|
+
const holdStale = (sides, comparison) => [...sides.nu.decisions.values()]
|
|
375
|
+
.filter((decision) => decision.change !== undefined && !comparison.findings.some((finding) => covers(decision, finding)))
|
|
376
|
+
.filter((decision) => sides.old.decisions.get(keyOf(sides.oldOf.get(decision.operation).id, decision.payload, decision.pointer))?.change !== decision.change)
|
|
377
|
+
.map((decision) => decisionFinding(sides.options.level, 'stale', placeOfDecision(sides, decision), {
|
|
378
|
+
before: undefined,
|
|
379
|
+
after: decision.change,
|
|
380
|
+
fix: `\`x-change: ${decision.change}\` at ${wordsOfDecision(decision)} records a change that is not in this diff. fix: remove the marker, or make the change it records`,
|
|
381
|
+
}));
|
|
382
|
+
const holdOverdue = (sides) => [...sides.nu.decisions.values()]
|
|
383
|
+
.filter((decision) => decision.sunset !== undefined && decision.sunset < sides.options.today)
|
|
384
|
+
.map((decision) => decisionFinding(sides.options.level, 'overdue', placeOfDecision(sides, decision), {
|
|
385
|
+
before: decision.sunset,
|
|
386
|
+
after: sides.options.today,
|
|
387
|
+
fix: `${wordsOfDecision(decision)} was to go after ${decision.sunset} and is still here. fix: remove it as decided, or move \`x-sunset\` to a date that still holds`,
|
|
388
|
+
}));
|
|
389
|
+
export const replacementKey = (decision) => {
|
|
390
|
+
const value = decision.replacedBy;
|
|
391
|
+
if (decision.payload === '')
|
|
392
|
+
return keyOf(value, '', '');
|
|
393
|
+
if (decision.pointer === '')
|
|
394
|
+
return keyOf(decision.operation, decision.payload.startsWith('param:') ? `${decision.payload.slice(0, decision.payload.lastIndexOf(':') + 1)}${value}` : value, '');
|
|
395
|
+
const tokens = decision.pointer.split('/');
|
|
396
|
+
const parent = tokens.slice(0, tokens.at(-2) === 'properties' ? -2 : -1).join('/');
|
|
397
|
+
return keyOf(decision.operation, decision.payload, value.startsWith('/') ? `${parent}${value}` : `${parent}/properties/${token(value)}`);
|
|
398
|
+
};
|
|
399
|
+
const holdReplacements = (sides) => [...sides.nu.decisions.values()]
|
|
400
|
+
.filter((decision) => decision.replacedBy !== undefined && !sides.nu.members.has(replacementKey(decision)))
|
|
401
|
+
.map((decision) => decisionFinding(sides.options.level, 'replacement-missing', placeOfDecision(sides, decision), {
|
|
402
|
+
before: decision.replacedBy,
|
|
403
|
+
after: undefined,
|
|
404
|
+
fix: `${wordsOfDecision(decision)} is replaced by \`${decision.replacedBy}\`, which is not in the new contract. fix: add that member, or point \`x-replaced-by\` at one that exists`,
|
|
405
|
+
}));
|
|
406
|
+
export const segmentOf = (operation) => {
|
|
407
|
+
const { major } = (/^#\/(?:paths|webhooks)\/[^/]*?~1v(?<major>\d+)(?=~1|\/|$)/.exec(operation.source)?.groups ?? {});
|
|
408
|
+
return major;
|
|
409
|
+
};
|
|
410
|
+
const infoVersion = (contract) => (isDict(contract.document) && isDict(contract.document.info) ? contract.document.info.version : undefined);
|
|
411
|
+
export const majorOf = (version) => {
|
|
412
|
+
const { major } = (/^v?(?<major>\d+)/.exec(String(version))?.groups ?? {});
|
|
413
|
+
return major;
|
|
414
|
+
};
|
|
415
|
+
const versionMoved = (sides, decision) => {
|
|
416
|
+
if (sides.options.changeset)
|
|
417
|
+
return true;
|
|
418
|
+
const [was, is] = [segmentOf(sides.oldOf.get(decision.operation)), segmentOf(operationOf(sides, decision))];
|
|
419
|
+
const [oldMajor, newMajor] = [majorOf(infoVersion(sides.oldContract)), majorOf(infoVersion(sides.newContract))];
|
|
420
|
+
return (is !== undefined && is !== was) || (oldMajor !== undefined && newMajor !== undefined && oldMajor !== newMajor);
|
|
421
|
+
};
|
|
422
|
+
const holdVersions = (sides, decidedBy) => [...decidedBy.values()]
|
|
423
|
+
.filter((decision) => !versionMoved(sides, decision))
|
|
424
|
+
.map((decision) => decisionFinding(sides.options.level, 'unversioned', placeOfDecision(sides, decision), {
|
|
425
|
+
before: infoVersion(sides.oldContract),
|
|
426
|
+
after: infoVersion(sides.newContract),
|
|
427
|
+
fix: `\`x-change: ${decision.change}\` at ${wordsOfDecision(decision)} decides a breaking change, and the major version did not move. fix: move the path to a new major segment (/v3/ to /v4/), raise the major of \`info.version\`, or pass \`--changeset\` to write a major bump`,
|
|
428
|
+
}));
|
|
429
|
+
export const checkDecisions = (old, nu, comparison, options) => {
|
|
430
|
+
const oldOf = new Map(pair(old.operations, nu.operations).map(([before, after]) => [(after ?? before).id, (before ?? after)]));
|
|
431
|
+
const sides = { old: readDecisions(old, options.level), nu: readDecisions(nu, options.level), oldContract: old, newContract: nu, oldOf, options };
|
|
432
|
+
const held = holdBreaking(sides, comparison);
|
|
433
|
+
return unique([
|
|
434
|
+
...sides.nu.problems,
|
|
435
|
+
...held.findings,
|
|
436
|
+
...holdStale(sides, comparison),
|
|
437
|
+
...holdOverdue(sides),
|
|
438
|
+
...holdReplacements(sides),
|
|
439
|
+
...holdVersions(sides, held.decidedBy),
|
|
440
|
+
]);
|
|
441
|
+
};
|
|
442
|
+
export const withDecisions = (comparison, decisions, level) => ({
|
|
443
|
+
...comparison,
|
|
444
|
+
decisions,
|
|
445
|
+
verdict: level === 'error' && decisions.length > 0 ? 'breaking' : comparison.verdict,
|
|
446
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { date, datetime, duration, email, hostname, ipv4, ipv6, time, uuid } from 'truefit/formats';
|
|
2
|
+
export const isDict = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
export const has = (value, key) => Object.hasOwn(value, key);
|
|
4
|
+
export const canonical = (value) => JSON.stringify(value, (_key, node) => (isDict(node) ? Object.fromEntries(Object.keys(node).sort().map((key) => [key, node[key]])) : node));
|
|
5
|
+
const arrayOf = (value) => (Array.isArray(value) ? value : []);
|
|
6
|
+
const without = (schema, keys) => Object.fromEntries(Object.entries(schema).filter(([key]) => !keys.includes(key)));
|
|
7
|
+
const only = (schema, keyword) => isDict(schema) && Object.keys(schema).join() === keyword;
|
|
8
|
+
export const typeOfValue = (value) => {
|
|
9
|
+
if (value === null)
|
|
10
|
+
return 'null';
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return 'array';
|
|
13
|
+
if (Number.isInteger(value))
|
|
14
|
+
return 'integer';
|
|
15
|
+
return typeof value;
|
|
16
|
+
};
|
|
17
|
+
const FINITE = { null: [null], boolean: [false, true] };
|
|
18
|
+
export const valuesOfTypes = (types) => types.every((type) => has(FINITE, type)) ? types.flatMap((type) => FINITE[type]) : undefined;
|
|
19
|
+
const typeList = (type) => (Array.isArray(type) ? type.map(String) : [String(type)]);
|
|
20
|
+
const asTypes = (values) => {
|
|
21
|
+
const types = [...new Set(values.map((value) => typeOfValue(value)))];
|
|
22
|
+
const listed = valuesOfTypes(types);
|
|
23
|
+
if (values.length === 0 || listed === undefined)
|
|
24
|
+
return undefined;
|
|
25
|
+
const had = new Set(values.map((value) => canonical(value)));
|
|
26
|
+
return listed.every((value) => had.has(canonical(value))) ? types : undefined;
|
|
27
|
+
};
|
|
28
|
+
const spell = (types) => (types.length === 1 ? types[0] : types);
|
|
29
|
+
const valuesAsType = (schema) => {
|
|
30
|
+
if (has(schema, 'const') && has(schema, 'enum'))
|
|
31
|
+
return schema;
|
|
32
|
+
const values = has(schema, 'const') ? [schema.const] : schema.enum;
|
|
33
|
+
const types = Array.isArray(values) ? asTypes(values) : undefined;
|
|
34
|
+
if (types === undefined)
|
|
35
|
+
return schema;
|
|
36
|
+
if (schema.type !== undefined && !types.every((type) => typeList(schema.type).includes(type)))
|
|
37
|
+
return schema;
|
|
38
|
+
return { ...without(schema, ['const', 'enum']), type: spell(types) };
|
|
39
|
+
};
|
|
40
|
+
const FORMATS = new Map([date, datetime, duration, email, hostname, ipv4, ipv6, time, uuid].map((format) => [format.pattern.source, format.name]));
|
|
41
|
+
const patternAsFormat = (schema) => {
|
|
42
|
+
const name = FORMATS.get(String(schema.pattern));
|
|
43
|
+
if (name === undefined || (schema.format !== undefined && schema.format !== name))
|
|
44
|
+
return schema;
|
|
45
|
+
return { ...without(schema, ['pattern']), format: name };
|
|
46
|
+
};
|
|
47
|
+
const branchValues = (branch) => {
|
|
48
|
+
if (only(branch, 'const'))
|
|
49
|
+
return [branch.const];
|
|
50
|
+
if (only(branch, 'enum'))
|
|
51
|
+
return arrayOf(branch.enum);
|
|
52
|
+
return only(branch, 'type') ? valuesOfTypes(typeList(branch.type)) : undefined;
|
|
53
|
+
};
|
|
54
|
+
const distinct = (texts) => new Set(texts).size === texts.length;
|
|
55
|
+
const unionOfTypes = (branches, exclusive) => {
|
|
56
|
+
if (!branches.every((branch) => only(branch, 'type')))
|
|
57
|
+
return undefined;
|
|
58
|
+
const types = branches.flatMap((branch) => typeList(branch.type));
|
|
59
|
+
if (exclusive && (!distinct(types) || (types.includes('integer') && types.includes('number'))))
|
|
60
|
+
return undefined;
|
|
61
|
+
return { type: spell([...new Set(types)]) };
|
|
62
|
+
};
|
|
63
|
+
const unionOfValues = (branches, exclusive) => {
|
|
64
|
+
const lists = branches.map((branch) => branchValues(branch));
|
|
65
|
+
if (lists.includes(undefined))
|
|
66
|
+
return undefined;
|
|
67
|
+
const values = lists.flat();
|
|
68
|
+
if (exclusive && !distinct(values.map((value) => canonical(value))))
|
|
69
|
+
return undefined;
|
|
70
|
+
return valuesAsType({ enum: values });
|
|
71
|
+
};
|
|
72
|
+
const TUPLE = new Set(['type', 'prefixItems', 'items', 'minItems', 'maxItems']);
|
|
73
|
+
const exactTuple = (branch) => {
|
|
74
|
+
if (!isDict(branch) || !Object.keys(branch).every((key) => TUPLE.has(key)) || canonical(typeList(branch.type)) !== '["array"]')
|
|
75
|
+
return undefined;
|
|
76
|
+
const prefix = arrayOf(branch.prefixItems);
|
|
77
|
+
const min = branch.minItems ?? 0;
|
|
78
|
+
const max = branch.maxItems ?? (branch.items === false ? prefix.length : undefined);
|
|
79
|
+
if (typeof min !== 'number' || min !== max || min > prefix.length)
|
|
80
|
+
return undefined;
|
|
81
|
+
return { length: min, items: prefix.slice(0, min) };
|
|
82
|
+
};
|
|
83
|
+
const unionOfTuples = (branches) => {
|
|
84
|
+
const tuples = branches.map((branch) => exactTuple(branch));
|
|
85
|
+
if (tuples.includes(undefined))
|
|
86
|
+
return undefined;
|
|
87
|
+
const sorted = tuples.toSorted((x, y) => x.length - y.length);
|
|
88
|
+
const lowest = sorted[0].length;
|
|
89
|
+
const longest = sorted.at(-1).items;
|
|
90
|
+
const contiguous = sorted.every(({ length, items }, index) => length === lowest + index && canonical(items) === canonical(longest.slice(0, length)));
|
|
91
|
+
if (!contiguous)
|
|
92
|
+
return undefined;
|
|
93
|
+
return { type: 'array', prefixItems: longest, items: false, ...(lowest > 0 && { minItems: lowest }) };
|
|
94
|
+
};
|
|
95
|
+
const collapse = (schema) => ['anyOf', 'oneOf'].reduce((node, keyword) => {
|
|
96
|
+
const branches = arrayOf(node[keyword]);
|
|
97
|
+
if (branches.length < 2)
|
|
98
|
+
return node;
|
|
99
|
+
const exclusive = keyword === 'oneOf';
|
|
100
|
+
const union = unionOfTypes(branches, exclusive) ?? unionOfValues(branches, exclusive) ?? unionOfTuples(branches);
|
|
101
|
+
const rest = without(node, [keyword]);
|
|
102
|
+
if (union === undefined || Object.keys(union).some((key) => has(rest, key)))
|
|
103
|
+
return node;
|
|
104
|
+
return { ...rest, ...union };
|
|
105
|
+
}, schema);
|
|
106
|
+
const GROUPS = [
|
|
107
|
+
['properties', 'patternProperties', 'additionalProperties', 'unevaluatedProperties'],
|
|
108
|
+
['prefixItems', 'items', 'unevaluatedItems'],
|
|
109
|
+
['contains', 'minContains', 'maxContains'],
|
|
110
|
+
['if', 'then', 'else'],
|
|
111
|
+
];
|
|
112
|
+
const ANNOTATIONS = new Set(['title', 'description', 'examples', 'example', 'default', 'deprecated', '$comment']);
|
|
113
|
+
const mergeable = (parts) => {
|
|
114
|
+
const keys = parts.flatMap((part) => Object.keys(part));
|
|
115
|
+
if (keys.includes('$ref'))
|
|
116
|
+
return false;
|
|
117
|
+
const clash = keys.some((key) => !ANNOTATIONS.has(key) && new Set(parts.filter((part) => has(part, key)).map((part) => canonical(part[key]))).size > 1);
|
|
118
|
+
const split = GROUPS.some((group) => parts.filter((part) => group.some((key) => has(part, key))).length > 1);
|
|
119
|
+
return !clash && !split;
|
|
120
|
+
};
|
|
121
|
+
const merge = (schema) => {
|
|
122
|
+
const keywords = ['allOf', ...['anyOf', 'oneOf'].filter((keyword) => arrayOf(schema[keyword]).length === 1)];
|
|
123
|
+
const branches = keywords.flatMap((keyword) => arrayOf(schema[keyword]));
|
|
124
|
+
if (branches.length === 0 || !branches.every((branch) => branch === true || isDict(branch)))
|
|
125
|
+
return schema;
|
|
126
|
+
const parts = [without(schema, keywords), ...branches.map((branch) => (isDict(branch) ? branch : {}))];
|
|
127
|
+
return mergeable(parts) ? Object.assign({}, ...parts) : schema;
|
|
128
|
+
};
|
|
129
|
+
const SINGLE = ['items', 'additionalProperties'];
|
|
130
|
+
const LISTS = ['prefixItems', 'allOf', 'anyOf', 'oneOf'];
|
|
131
|
+
const children = (schema) => ({
|
|
132
|
+
...schema,
|
|
133
|
+
...(isDict(schema.properties) && { properties: Object.fromEntries(Object.entries(schema.properties).map(([name, child]) => [name, normalise(child)])) }),
|
|
134
|
+
...Object.fromEntries(SINGLE.filter((keyword) => schema[keyword] !== undefined).map((keyword) => [keyword, normalise(schema[keyword])])),
|
|
135
|
+
...Object.fromEntries(LISTS.filter((keyword) => Array.isArray(schema[keyword])).map((keyword) => [keyword, arrayOf(schema[keyword]).map((child) => normalise(child))])),
|
|
136
|
+
});
|
|
137
|
+
export function normalise(schema) {
|
|
138
|
+
if (!isDict(schema))
|
|
139
|
+
return schema;
|
|
140
|
+
if (only(schema, 'not') && (schema.not === true || only(schema.not, '')))
|
|
141
|
+
return false;
|
|
142
|
+
return patternAsFormat(valuesAsType(merge(collapse(children(schema)))));
|
|
143
|
+
}
|