Using json-schema-viewer to explore schemas
If you already have schemas, that's great. If you have OpenAPI specs instead of dealing with schemas you can follow the next section
Let's say you start with something like this:
info:
description: Some info
title: your title
version: 2.0.0
paths:
/json:
get:
responses:
default:
description: 'OK response'
content:
application/json:
schema:
$ref: '#/components/schemas/OKResponse'
'500':
description: '500 response'
content:
application/json:
schema:
$ref: '#/components/schemas/FailResponse'
openapi: 3.0.2
components:
schemas:
OKResponse:
type: object
properties:
size:
type: number
accuracy:
type: string
quantity:
type: integer
FailResponse:
type: object
properties:
size:
type: number
accuracy:
type: string
quantity:
type: integer
You can extract the schemas to schemas/
by running:
pipx run --spec git+https://github.com/imochoa/openapi2jsonschema openapi2jsonschema /path/to/your/spec.yaml -o schemas/
requires pipx
Prepare the schemas for the json-schema-viewer docker image
The docker image expects a schema.json
at /var/www/schemas/schema/schema.json
that must contain these 2 keys:
{
"version":"x.y.z",
"id": "schema.json#",
}
So locate your top-level schema and prepare it:
cd schemas
cp OKResponse.json schema.json
jq '. += {"version":"1.1.3"}' schema.json | sponge schema.json
jq '. += {"id": "schema.json#"}' schema.json | sponge schema.json
requires more-utils jq
You have to mount your schemas onto /var/www/schemas/schema
(including the schema.json
file).
Which you can do like so:
docker run --rm -it -p 9001:9001 -v `realpath schemas`:/var/www/schemas/schema imochoa/json-schema-viewer
For more info, see the dockerhub page