Skip to content

Instantly share code, notes, and snippets.

View jdesrosiers's full-sized avatar

Jason Desrosiers jdesrosiers

  • Hyperjump Software, LLC
  • San Luis Obispo, CA
View GitHub Profile
@jdesrosiers
jdesrosiers / README.md
Last active February 13, 2024 19:38
@hyperjump/json-schema Evaluation Scafolding

Evaluation Scafolding

This is a starter for building a custom evaluation handler for [@hyperjump/json-schema] using its AST. Using the AST allows you to support any JSON Schema version [@hyperjump/json-schema] supports without having to code for the inticacies of schema identification and referencing. You can implement each keyword as if there were no references.

This code will walk through the schema using the AST. You provide a handler for each keyword to do whatever evaluation you require.

Keyword URIs

The concept of keywords being identified as URIs is unique to [@hyperjump/json-schema] and not part of the JSON Schema standard. Unfortunately, there are some keywords that have changed from one release to another and using URIs to identify them allows us to distinguish between two keywords with the same name. For example, items changes behavior in 2020-12, so there are different URIs for each version.

{
"$id": "https://json-schema.org/draft/2020-12/schema",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Core and Validation specifications meta-schema",
"$dynamicAnchor": "meta",
"allOf": [
{
"$ref": "meta/core"
},
{
@jdesrosiers
jdesrosiers / schema.json
Created June 26, 2022 21:52
Customizable refactor of draft-07 meta-schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/my-custom-draft-07/schema#",
"title": "Core schema meta-schema",
"allOf": [{ "$ref": "#/definitions/schema" }],
"$comment": "Add constraints here that should only apply to root schemas and not sub-schemas",
"definitions": {
"schema": {
@jdesrosiers
jdesrosiers / level3.md
Last active May 23, 2022 22:21
Level 3 Lesson Plan

Level 2-3 Lesson Plan

Schedule

Monday

4:30 - 5:00 Warm up, Stretch, and Holds. Level 4-5 warms up separately, but you still need to keep an eye on them. 5:00 - 5:20 Parallel Bars 5:20 - 5:40 Mushroom 5:40 - 6:00 Small Floor

@jdesrosiers
jdesrosiers / validating-openapi-and-json-schema.md
Last active December 5, 2021 02:55
Blog: Validating OpenAPI and JSON Schema

Validating OpenAPI and JSON Schema

Starting with the release of OpenAPI 3.1, the dialect of JSON Schema used in OpenAPI documents is configurable. By default, you get the OpenAPI 3.1 Schema dialect, but you can choose to use draft 2020-12 or any other dialect if you choose. This brings up the question of how to validate an OpenAPI 3.1 document if one of its components (JSON Schema) is open-ended. In this article, we'll cover how to configure the default JSON Schema dialect of an OpenAPI 3.1 document and how to validate that document, including JSON Schemas, no matter which dialect(s) you choose to use.

What is a JSON Schema dialect?

Because not everyone is familiar with the term "dialect" in this context, let's take a moment to define it before moving on. A JSON Schema dialect is any unique incarnation of JSON Schema. This includes any official release of JSON Schema such as draft-07 or draft 2020-12, but it also includes custom versions of JSON Schema. OpenAPI has effectively had three dialects of JS