microsoft / design-to-code

A system of development tools, and utilities used à la carte or as a suite to build enterprise-grade websites and applications.
MIT License
24 stars 6 forks source link

[Feature] Create JSON schema for generic HTML element use #42

Open janechu opened 5 years ago

janechu commented 5 years ago

Note: as an initial step, investigate if there is already a source for these JSON schemas

Description

Similar to how React components have Typescript interfaces for props that extend the HTMLElement attributes, the JSON schemas should also extend the possible attributes that are passed to the element.

Requirements

The JSON schema should include:

Note: be sure to pay attention to extra JSON schema keywords that could prove useful, such as pattern, propertyNames.

These schemas should map to the TypeScript HTMLElement interface to line up more closely with the prop contract for components.

For information on JSON schemas here are a few good resources:

JSON schemas for HTML use should be placed in the fast-web-utilities package. The file name should be html-element.schema.ts and be in the same format as other *.ts JSON schema exports, an example of which can be found here: https://github.com/microsoft/fast-dna/blob/master/packages/fast-components-react-base/src/checkbox/checkbox.schema.ts

It's not necessary to use any of the extra additions we include for our components such as reactProperties and this schema can stick to the typical JSON schema format.

Currently we use Ajv as our validation package, do add a spec file named html-element.schema.spec.ts and include the Ajv lib as a devDependency with sufficient tests to ensure your schema is correctly checking for all appropriate properties.