Skip to content

Instantly share code, notes, and snippets.

@netmilk
Created Feb 13, 2015
Embed
What would you like to do?
Example for support of JSON schema draft v3 and v4 in Apiary

FORMAT: 1A

JSON Schema example API

API Exmample for demonstration of different versions of JSON schema

Valid schema v4 [/schema_v4_valid]

Create [POST]

  • Request (application/json)

    • Schema

          {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "id": "http://jsonschema.net",
            "type": "object",
            "properties": {
              "title": {
                "id": "http://jsonschema.net/title",
                "type": "string"
              }
            },
            "required": [
              "title"
            ]
          }
      
  • Response 201 (application/json)

Valid schema v3 [/schema_v3_valid]

Create [POST]

  • Request (application/json)

    • Schema

          {
            "$schema": "http://json-schema.org/draft-03/schema#",
            "id": "http://jsonschema.net",
            "type": "object",
            "properties": {
              "title": {
                "id": "http://jsonschema.net/title",
                "type": "string",
                "required": true
              }
            }
          }
      
  • Response 201 (application/json)

Invalid schema v4 [/schema_v4_invalid]

Create [POST]

  • Request (application/json)

    • Schema

          {
            "$schema": "http://json-schema.org/draft-04/schema#",
            "id": "http://jsonschema.net",
            "type": "any",
            "properties": {
              "title": {
                "id": "http://jsonschema.net/title",
                "type": "string",
                "required": true
              }
            }
          }
      
  • Response 201 (application/json)

Invalid schema v3 [/schema_v3_invalid]

Create [POST]

  • Request (application/json)

    • Schema

          {
            "$schema": "http://json-schema.org/draft-03/schema#",
            "id": "http://jsonschema.net",
            "type": "object",
            "properties": {
              "title": {
                "id": "http://jsonschema.net/title",
                "type": "string"
              }
            },
            "required": [
              "title"
            ]
          }
      
  • Response 201 (application/json)

Valid schema v4 without identification [/schema_v4_valid_wo_ident]

Create [POST]

  • Request (application/json)

    • Schema

          {
            "id": "http://jsonschema.net",
            "type": "object",
            "properties": {
              "title": {
                "id": "http://jsonschema.net/title",
                "type": "string"
              }
            },
            "required": [
              "title"
            ]
          }
      
  • Response 201 (application/json)

Valid schema v3 without identification [/schema_v3_valid_wo_ident]

Create [POST]

  • Request (application/json)

    • Schema

          {
            "id": "http://jsonschema.net",
            "type": "object",
            "properties": {
              "title": {
                "id": "http://jsonschema.net/title",
                "type": "string",
                "required": true
              }
            }
          }
      
  • Response 201 (application/json)

Not valid schema at all without identification [/schema_wo_ident_invalid]

Create [POST]

  • Request (application/json)

    • Schema

          {
            "id": "http://jsonschema.net",
            "type": "any",
            "required": ["title"],
            "properties": {
              "title": {
                "id": "http://jsonschema.net/title",
                "type": "string"
              }
            }
          }
      
  • Response 201 (application/json)

#! /bin/bash
uris=""
uris+="/schema_v4_valid " # Resource with valid v4 schema
uris+="/schema_v3_valid " # Resource with valid v3 schema
uris+="/schema_v4_invalid " # Resource with invalid v4 schema
uris+="/schema_v3_invalid " # Resource with invalid v3 schema
uris+="/schema_v4_valid_wo_ident " # Resource with valid v4 schema but without $schema ident
uris+="/schema_v3_valid_wo_ident " # Resource with valid v3 schema but without $schema ident
uris+="/schema_wo_ident_invalid " # Resource with invalid v3 or v4 schema without ident
for uri in $uris
do
curl --include --request POST \
--header "Content-Type: application/json" \
--data-binary "{\"different\": \"body\"}" \
"http://private-85473-jsonschemaexamples.apiary-mock.com$uri"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment