Home

Awesome

logo

API Blueprint AST

Deprecation Notice

As of 2015-12-02 the API Blueprint AST is deprecated and should not be used for new development. The API Blueprint AST has been superseded by API Elements.

JSON & YAML face of the API Blueprint

API Blueprint AST is JSON or YAML, machine-friendly, face of API Blueprint suitable for use in tools consuming (or producing) API Blueprint.

This document defines serialization formats for API Blueprint abstract syntax tree, or AST for short.

For the definition of API Blueprint AST Source Map see the API Blueprint AST Source Map definition.

Converting API Blueprint to AST and its serialization is the task of API Blueprint Parser – Drafter or one of its bindings. Reverse process from AST (serialization) to API Blueprint is also possible thanks to the Matter Compiler.

Don't like to design APIs in JSON or YAML?

If you are looking for a way to describe your Web API without using JSON or YAML see API Blueprint.

Version

Future Development

As of version 3.0 the API Blueprint AST is in the interim transition period towards unified document-structure based on the concept of DOM elements (see the Element object). Please refrain from using AST elements marked as "deprecated".

Quick Links

AST Definition

Following is the definition of API Blueprint AST media types using the MSON syntax.

NOTE: Most of the keys corresponds to their counter parts in API Blueprint Specification. Where applicable, refer to the relevant entry API Blueprint Language Specification for details.

Blueprint (object)

Element (object)

A component of an API description.

Properties

Resource Group (object)

Deprecated, replaced by the category Element.

Logical group of resources.

Properties

Resource (object)

Description of one resource, or a cluster of resources defined by its URI template.

Properties

Action (object)

An HTTP transaction (a request-response transaction). Actions are specified by an HTTP request method within a resource.

Properties

Payload (object)

An API Blueprint payload.

Properties

Header

A HTTP header that are expected to be transferred with an HTTP message.

Properties

Asset (Element)

An API Blueprint asset. The content is an Asset in its textual representation as written in the source API Blueprint.

Properties

Parameter (object)

Description of one URI template parameter.

Properties

Transaction Example (object)

An HTTP transaction example with expected HTTP message request and response payload(s).

Properties

Reference (object)

A reference object which is used whenever there is a reference to a Resource Model.

Properties

Media Types

The application/vnd.apiblueprint.ast is the media type for API Blueprint AST. The media type serialization format is specified in the +<serialization format> appendix.

Serialization formats

Two supported, feature-equal serialization formats are JSON and YAML:

Example: JSON Serialization

application/vnd.apiblueprint.ast.json; version=4.0

{
  "_version": "<AST version>",
  "metadata": [
    {
      "name": "<metadata key name>",
      "value": "<metadata value>"
    }
  ],
  "name": "<API name>",
  "description": "<API description>",
  "element": "category",
  "content": [
    {
      "element": "category",
      "attributes": {
        "name": "<resource group name>"
      },
      "content": [
        {
          "element": "copy",
          "content": "<resource group description>"
        },
        {
          "name": "<resource name>",
          "description": "<resource description>",
          "element": "resource",
          "uriTemplate": "<resource URI template>",
          "model": {
            "name": "<resource model name>",
            "description": "<resource model description>",
            "headers": [
              {
                "name": "<HTTP header field name>",
                "value": "<HTTP header field value>"
              }
            ],
            "content": [
              {
                "element": "dataStructure",
                "content":{
                  "element": "object",
                  "meta": {
                    "ref": "<sub-type>"
                  },
                  "content": []
                }
              },
              {
                "element": "asset",
                "attributes":  {
                  "role": "bodyExample"
                },
                "content": "<resource model body>"
              },
              {
                "element": "asset",
                "attributes":  {
                  "role": "bodySchema"
                },
                "content": "<resource model schema>"
              }
            ]
          },
          "parameters": [
            {
              "name": "<name>",
              "description": "<description>",
              "type": "<type>",
              "required": "<required parameter flag>",
              "default": "<default value>",
              "example": "<example value>",
              "values": [
                {
                  "value": "<enum element>"
                }
              ]
            }
          ],
          "actions": [
            {
              "name": "<action name>",
              "description": "<action description>",
              "method": "<action HTTP request method>",
              "parameters": [
                {
                  "name": "<name>",
                  "description": "<description>",
                  "type": "<type>",
                  "required": "<required parameter flag>",
                  "default": "<default value>",
                  "example": "<example value>",
                  "values": [
                    {
                      "value": "<enum element>"
                    }
                  ]
                }
              ],
              "examples": [
                {
                  "name": "<transaction example name>",
                  "description": "<transaction example description>",
                  "requests": [
                    {
                      "name": "<request name>",
                      "description": "<request description>",
                      "headers": [
                        {
                          "name": "<HTTP header field name>",
                          "value": "<HTTP header field value>"
                        }
                      ],
                      "content": [
                        {
                          "element": "dataStructure",
                          "content": {
                            "element": "object",
                            "meta": {
                              "ref": "<sub-type>"
                            },
                            "content": []
                          }
                        },
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodyExample"
                          },
                          "content": "<request body>"
                        },
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodySchema"
                          },
                          "content": "<request schema>"
                        }
                      ]
                    }
                  ],
                  "responses": [
                    {
                      "name": "<response HTTP status code>",
                      "description": "<response description>",
                      "headers": [
                        {
                          "name": "<HTTP header field name>",
                          "value": "<HTTP header field value>"
                        }
                      ],
                      "content": [
                        {
                          "element": "dataStructure",
                          "content": {
                            "element": "object",
                            "meta": {
                              "ref": "<sub-type>"
                            },
                            "content": []
                          }
                        },
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodyExample"
                          },
                          "content": "<request body>"
                        },
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodySchema"
                          },
                          "content": "<request schema>"
                        }
                      ]
                    }
                  ]
                }
              ],
              "content": [
                {
                  "element": "dataStructure",
                  "content": {
                    "element": "object",
                    "meta": {
                      "ref": "<sub-type>"
                    },
                    "content": []
                  }
                }
              ]
            },
            {
              "name": "<action name>",
              "description": "<action description>",
              "method": "<action HTTP request method>",
              "parameters": [],
              "examples": [
                {
                  "name": "<transaction example name>",
                  "description": "<transaction example description>",
                  "responses": [
                    {
                      "name": "<response HTTP status code>",
                      "reference": {
                        "id": "<resource model name>"
                      },
                      "description": "<resource model description>",
                      "headers": [
                        {
                          "name": "<HTTP header field name>",
                          "value": "<HTTP header field value>"
                        }
                      ],
                      "content": [
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodyExample"
                          },
                          "content": "<resource model body>"
                        },
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodySchema"
                          },
                          "content": "<resource model schema>"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "content": [
            {
              "element": "dataStructure",
              "content": {
                "element": "object",
                "meta": {
                  "id": "<resource-name>",
                  "ref": "<sub-type>"
                },
                "content": []
              }
            }
          ]
        }
      ]
    },
    {
      "element": "category",
      "content": [
        {
          "element": "dataStructure",
          "content": {
            "element": "object",
            "meta": {
              "id": "<data-structure-name>",
              "ref": "<sub-type>"
            },
            "content": []
          }
        }
      ]
    }
  ]
}

Related Media Types

Serialization in Drafter

The drafter command-line tool supports serialization of API Blueprint AST via the --format option. Similarly, it also supports serialization of API Blueprint Source Map using the --format and --sourcemap option.

License

MIT License. See the LICENSE file.