@open-form-spec/validator
v0.2.0
Published
OFS spec validation against JSON schema and OpenAPI
Readme
@open-form-spec/validator
Validates .ofs.yaml files against the OFS JSON schema and checks field/enum references against OpenAPI specs. Used internally by @open-form-spec/runner — you only need this package directly if you are building custom tooling.
Install
npm install @open-form-spec/validatorAPI
validate(options)
Validates a set of parsed OFS documents against the schema and optional OpenAPI data.
import { validate } from "@open-form-spec/validator";
const errors = await validate({
specs: [doc],
openApiEnums: { api: { AccountType: ["PERSONAL", "BUSINESS"] } },
openApiSchemas: { api: { Registration: { email: { type: "string" } } } },
});
if (errors.length > 0) {
for (const err of errors) {
console.error(`${err.file}: ${err.message}`);
}
}extractEnumsFromOpenAPI(openapi)
Extracts all enum values from a parsed OpenAPI document.
import { extractEnumsFromOpenAPI } from "@open-form-spec/validator";
const enums = extractEnumsFromOpenAPI(openapiDoc);
// { AccountType: ["PERSONAL", "BUSINESS"] }extractSchemasFromOpenAPI(openapi)
Extracts property type/format information from all schemas in a parsed OpenAPI document.
import { extractSchemasFromOpenAPI } from "@open-form-spec/validator";
const schemas = extractSchemasFromOpenAPI(openapiDoc);
// { Registration: { email: { type: "string", format: "email" } } }ValidationError
| Field | Type | Description |
|-------|------|-------------|
| file | string | Source file path |
| message | string | Error description |
