apiaryio / mson-ast

MSON AST Serialization Media Types
MIT License
4 stars 1 forks source link
deprecated

MSON AST & Source Map

This document defines serialization formats for MSON abstract syntax tree. For the definition of MSON AST Source Map see the MSON AST Source Map definition.

Deprecation Notice

As of 2015-08-10 the AST is deprecated and should not be used for new development. The MSON AST has been superseded by Data Structure Refract Namespace. The Data Structure Refract Namespace will be offered by API Blueprint parser harness – Drafter.

If you are relying on MSON AST please contact @zdne as soon as possible.

Version

Quick Links

AST Definition

Following is the definition of MSON AST serializations data structures using the MSON syntax.

NOTE: Refer to the MSON Specification for the explanation of terms used throughout this document.

Document (object)

Top-level MSON document or block.

Properties

Named Type (object)

User-defined named type.

Properties

Type Name (enum)

Base or named type's name.

Members

Symbol (object)

Type symbol (identifier).

Properties

Type Definition (object)

Definition of an instance value type.

Properties

Type Section (object)

Section of a type. The section can be any of the Type Sections as described in the MSON Specification.

Properties

Element (object)

An element of a type section. The element holds either a member type (value or property), Mixin type, One Of type or groups elements in a collection of Elements.

Properties

Elements (array[Element])

Collection of elements.

Property Member (Value Member)

Individual member of an object type structure.

Properties

Property Name (object)

Name of a property member.

Properties

Value Member (object)

Individual member of an array or enum type structure.

Properties

Mixin (Type Definition)

Mixin type.

One Of (Elements)

One Of type. List of mutually exclusive elements.

Note the only allowed Element classes are are property, mixin, oneOf and group.

Value Definition (object)

Value definition of a type instance.

Properties

Value (object)

Sample or actual value of a type instance

Properties

Markdown (string)

Markdown formatted plain text string.

Literal (string)

Literal value in the form of a plain-text.

Media Types

The base type media type is application/vnd.mson.ast.

Serialization formats

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

Example: JSON Serialization

Given the following MSON

- id: 1 (required)
- name: A green door
- price: 12.50 (number)
- tags: home, green
- vector (array)
    - 1
    - 2
    - 3

application/vnd.mson.ast+json; version=2.0

{
  "types": [
    {
      "name": null,
      "typeDefinition": {
        "typeSpecification": {
          "name": "object"
        }
      },
      "sections": [
        {
          "class": "memberType",
          "content": [
            {
              "class": "property",
              "content": {
                "name": {
                  "literal": "id"
                },
                "valueDefinition": {
                  "values": [
                    {
                      "literal": "1"
                    }
                  ],
                  "typeDefinition": {
                    "attributes": [
                      "required"
                    ]
                  }
                }
              }
            },
            {
              "class": "property",
              "content": {
                "name": {
                  "literal": "name"
                },
                "valueDefinition": {
                  "values": [
                    {
                      "literal": "A green door"
                    }
                  ]
                }
              }
            },
            {
              "class": "property",
              "content": {
                "name": {
                  "literal": "price"
                },
                "valueDefinition": {
                  "values": [
                    {
                      "literal": "12.50"
                    }
                  ],
                  "typeDefinition": {
                    "typeSpecification": {
                      "name": "number"
                    }
                  }
                }
              }
            },
            {
              "class": "property",
              "content": {
                "name": {
                  "literal": "tags"
                },
                "valueDefinition": {
                  "values": [
                    {
                      "literal": "home"
                    },
                    {
                      "literal": "green"
                    }
                  ]
                }
              }
            },
            {
              "class": "property",
              "content": {
                "name": {
                  "literal": "vector"
                },
                "valueDefinition": {
                  "typeDefinition": {
                    "typeSpecification": {
                      "name": "array"
                    }
                  }
                },
                "sections": [
                  {
                    "class": "memberType",
                    "content": [
                      {
                        "class": "value",
                        "content": {
                          "valueDefinition": {
                            "values": [
                              {
                                "literal": "1"
                              }
                            ]
                          }
                        }
                      },
                      {
                        "class": "value",
                        "content": {
                          "valueDefinition": {
                            "values": [
                              {
                                "literal": "2"
                              }
                            ]
                          }
                        }
                      },
                      {
                        "class": "value",
                        "content": {
                          "valueDefinition": {
                            "values": [
                              {
                                "literal": "3"
                              }
                            ]
                          }
                        }
                      }
                    ]
                  }
                ]
              }
            }
          ]
        }
      ]
    }
  ]
}

License

MIT License. See the LICENSE file.