blake.app

Introducing `to_json_schema`

I started working on a new command line app and ruby library called to_json_schema

for converting json to json schema. The app is for converting the json output of an api call into json schema so that I can use it to help document the discourse api without having to manually type the schema myself which can be quite tedious.

So my workflow for documenting the api is to:

  1. Make a curl request to an endpoint (using discourse_api_curl)
  2. Take that json output and pass it to to_json_schema
  3. Save the schema to a .json file inside the discourse api docs directory
  4. Reference the schema file in a spec

I literally just started working on it and thought I should save what I have for now and hopefully I can get it into a working state tomorrow.

Hopefully you find it useful.

Here is an example of what I have working so far. First this is the json input we are passing in:

cat ~/tmp/create_tag_group.json
{"tag_group":{"id":11,"name":"5145450606a690406fddfd28f7b95923","tag_names":[],"parent_tag_name":[],"one_per_topic":false,"permissions":{"everyone":1}}}

And this is the generated json schema for it:

./bin/to_json_schema -i ~/tmp/create_tag_group.json
{:input=>"/home/blake/tmp/create_tag_group.json"}
Going to read in json file /home/blake/tmp/create_tag_group.json
{
  "additionalProperties": false,
  "properties": {
    "tag_group": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "tag_names": {
          "type": "array",
          "items": [

          ]
        },
        "parent_tag_name": {
          "type": "array",
          "items": [

          ]
        },
        "one_per_topic": {
          "type": "boolean"
        },
        "permissions": {
          "type": "object",
          "properties": {
            "everyone": {
              "type": "integer"
            }
          },
          "required": [
            "everyone"
          ]
        }
      },
      "required": [
        "id",
        "name",
        "tag_names",
        "parent_tag_name",
        "one_per_topic",
        "permissions"
      ]
    }
  },
  "required": [
    "tag_group"
  ]
}