@oada/formats
Reworked OADA formats
Last updated 3 months ago by aultac .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @oada/formats 
SYNC missed versions from official npm registry.

Deploys by Netlify

@OADA/formats

The purpose of this repo is to act as an inventory of known OADA API and ag data formats. These formats are represented as JSON Schema.

Schemas

The JSON Schema files are publicly available from https://formats.openag.io/. The $id of our schemas is also the URL at which it is available for download (i.e., if you configure your JSON Schema tool to resolve $refs via HTTP, you can reference our schemas with no further effort.). This makes the schemas/formats useful to any of the many environments which have JSON Schema implementations available.

Caveat about schema files

In order to have TypeScript sanity check the formats of our schemas for us, we wrap our JSON Schemas in TypeScript modules.

// Somewhat opinionated TypeScript type definitions for JSON Schema
import { JSONSchema8 as Schema } from 'jsonschema8'

const schema: Schema = {
  /* The actual JSON Schema */
}

/**
 * Simply exports an object of the schema,
 * but now TS understands what it is and how it should look.
 */
export default schema

The original intention was to simply have json files of the JSON Schema, but the convenience of having TypeScript check our schemas for us motivated this compromise. The published versions of the schemas have this wrapping removed and are pure JSON Schema.

Adding formats

All that is needed to add a format is to create a new .schema.ts file within src/schemas which exports valid JSON Schema. You can easily add the file for your new format with hygen:

$ hygen format new your/format/name

Testing formats

Our test suite will automatically sanity check all formats (including your new ones). Schemas are (among other checks) checked against the metaschema, and expected to match any examples they have.

You are strongly encouraged to add examples to your new formats. Aditionally if you create a .schema.spec.ts file for your format, any mocha tests in it will run with our the test suite.

Node library

This project is chiefly a collection of pure JSON Schema schemas, but there is also a small node library for utilizing the schemas in TypeScript/JavaScript.

Node installation

yarn add @oada/formats

Library Usage

The TypeScript/JavaScript library exports an async function that resolves to an Ajv instance which is loaded with all the the schemas from this project.

import loadAllFormats from '@oada/formats'

const obj = {
  /* Properties and stuff here */
}

let formats = await loadAllFormats()

// Check that obj matches the format for and OADA bookmarks document
formats.validate('https://formats.openag.io/oada/bookmarks.schema', obj)

In addition to being loaded with all the OADA formats, the returned Ajv instance is also augmented to be able to resolve content types to the relevant schema.

// Returns the schema for an OADA Bookmarks document
const { schema } = formats.getSchema('applications/vnd.oada.bookmarks.1+json')

Current Tags

  • 1.1.3-alpha.0                                ...           alpha (a month ago)
  • 1.1.2                                ...           latest (3 months ago)

8 Versions

  • 1.1.3-alpha.0                                ...           a month ago
  • 1.1.2                                ...           3 months ago
  • 1.1.1                                ...           3 months ago
  • 1.1.0                                ...           3 months ago
  • 1.0.4                                ...           3 months ago
  • 1.0.3                                ...           3 months ago
  • 1.0.2                                ...           3 months ago
  • 1.0.1                                ...           3 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 9
Dependencies (5)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |