@mitre/hdf-openapi 3.8.0-next.42721483174.1 → 3.8.0-next.42873372864.1
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/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -73,11 +73,14 @@ interface ExampleFault {
|
|
|
73
73
|
errors: string;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
*
|
|
76
|
+
* A checker for many schemas against one set of references. The engine and the
|
|
77
|
+
* references are set up once, so a whole document costs one setup, not one per schema.
|
|
77
78
|
*
|
|
78
79
|
* `references` supplies the components an example's schema may `$ref` — the ingest request
|
|
79
80
|
* points at the eight document roots, so without them it cannot compile.
|
|
80
81
|
*/
|
|
82
|
+
export declare function createExampleValidator(references?: Record<string, unknown>): (schema: Record<string, unknown>) => ExampleFault[];
|
|
83
|
+
/** Faults in a schema's own examples. An empty array means every example validates. */
|
|
81
84
|
export declare function validateExample(schema: Record<string, unknown>, references?: Record<string, unknown>): ExampleFault[];
|
|
82
85
|
export type { ComponentsDocument, ExampleFault, JsonSchema, ProblemDoc, ProblemOwner };
|
|
83
86
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/components.ts","../src/extract.ts","../src/problems.ts","../src/validate-example.ts"],"mappings":"A,UAAiB;GACd;;UAGc;EACf;EACA;IACE;IACA;IACA;IACA;MAAW;MAAc;;IACzB;MAAW;MAAc;;;EAE3B;EACA;IAAc,SAAS,eAAe;;;;qBAI3B;qBAWA,sBAAsB;;qBAYtB;;;;;;;;;;;;;;wBCWG,wBAAwB,KAAK,oBAAoB,eAAe;;KC5CpE;UAEK;;EAEf;EACA;EACA;EACA,OAAO;EACP;EACA;;;wBAac,gBAAgB,gBAAqC,eAAe;;qBA2CvE;;;;;wBAMG,aAAa,OAAI,eAAA,cAAuB;EAAiB;EAAgB;;;;;;qBAY5E;UCjFI;EACf;EACA
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/components.ts","../src/extract.ts","../src/problems.ts","../src/validate-example.ts"],"mappings":"A,UAAiB;GACd;;UAGc;EACf;EACA;IACE;IACA;IACA;IACA;MAAW;MAAc;;IACzB;MAAW;MAAc;;;EAE3B;EACA;IAAc,SAAS,eAAe;;;;qBAI3B;qBAWA,sBAAsB;;qBAYtB;;;;;;;;;;;;;;wBCWG,wBAAwB,KAAK,oBAAoB,eAAe;;KC5CpE;UAEK;;EAEf;EACA;EACA;EACA,OAAO;EACP;EACA;;;wBAac,gBAAgB,gBAAqC,eAAe;;qBA2CvE;;;;;wBAMG,aAAa,OAAI,eAAA,cAAuB;EAAiB;EAAgB;;;;;;qBAY5E;UCjFI;EACf;EACA;;;;;;;;;wBAUc,uBACd,aAAY,2BACV,QAAQ,4BAA4B;;wBA0BxB,gBACd,QAAQ,yBACR,aAAY,0BACX"}
|
package/dist/index.js
CHANGED
|
@@ -5834,30 +5834,38 @@ const UNMAPPED_CODES = [
|
|
|
5834
5834
|
];
|
|
5835
5835
|
// src/validate-example.ts
|
|
5836
5836
|
/**
|
|
5837
|
-
*
|
|
5837
|
+
* A checker for many schemas against one set of references. The engine and the
|
|
5838
|
+
* references are set up once, so a whole document costs one setup, not one per schema.
|
|
5838
5839
|
*
|
|
5839
5840
|
* `references` supplies the components an example's schema may `$ref` — the ingest request
|
|
5840
5841
|
* points at the eight document roots, so without them it cannot compile.
|
|
5841
5842
|
*/
|
|
5842
|
-
function
|
|
5843
|
-
const examples = schema.examples;
|
|
5844
|
-
if (!Array.isArray(examples)) return [];
|
|
5843
|
+
function createExampleValidator(references = {}) {
|
|
5845
5844
|
const ajv = new Ajv2020({
|
|
5846
5845
|
strict: false,
|
|
5847
5846
|
allErrors: true
|
|
5848
5847
|
});
|
|
5849
5848
|
addFormats(ajv);
|
|
5850
5849
|
for (const [name, referenced] of Object.entries(references)) ajv.addSchema(referenced, `#/components/schemas/${name}`);
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5850
|
+
return (schema) => {
|
|
5851
|
+
const examples = schema.examples;
|
|
5852
|
+
if (!Array.isArray(examples)) return [];
|
|
5853
|
+
const validate = ajv.compile(schema);
|
|
5854
|
+
const faults = [];
|
|
5855
|
+
examples.forEach((example, index) => {
|
|
5856
|
+
if (!validate(example)) faults.push({
|
|
5857
|
+
index,
|
|
5858
|
+
errors: JSON.stringify(validate.errors)
|
|
5859
|
+
});
|
|
5857
5860
|
});
|
|
5858
|
-
|
|
5859
|
-
|
|
5861
|
+
ajv.removeSchema(schema);
|
|
5862
|
+
return faults;
|
|
5863
|
+
};
|
|
5864
|
+
}
|
|
5865
|
+
/** Faults in a schema's own examples. An empty array means every example validates. */
|
|
5866
|
+
function validateExample(schema, references = {}) {
|
|
5867
|
+
return createExampleValidator(references)(schema);
|
|
5860
5868
|
}
|
|
5861
|
-
export { EXPECTED_DEFINITIONS, MAIN_SCHEMAS, PROBLEM_BASE, ROOT_COMPONENT_NAMES, UNMAPPED_CODES, extractStandaloneSchema, loadProblemDocs, problemTypes, validateExample };
|
|
5869
|
+
export { EXPECTED_DEFINITIONS, MAIN_SCHEMAS, PROBLEM_BASE, ROOT_COMPONENT_NAMES, UNMAPPED_CODES, createExampleValidator, extractStandaloneSchema, loadProblemDocs, problemTypes, validateExample };
|
|
5862
5870
|
|
|
5863
5871
|
//# sourceMappingURL=index.js.map
|