Giter VIP home page Giter VIP logo

Comments (4)

pksunkara avatar pksunkara commented on May 28, 2024

Actually the drafter generated JSON AST for Element Object is wrong

Why do you say that? Please give an example blueprint, the AST generated out of it and what you think the AST should be.

from api-blueprint-ast.

ArtK007 avatar ArtK007 commented on May 28, 2024

@pksunkara I have given a code snippet in my first comment. I generated AST using drafter for almost all the examples present in github and found out Element Object AST is not what it should be...

Explanation : for the Element Object there are three properties "element (enum)", "attributes", "content". If the "element" is category the "content" property is List of Element Objects, but the AST is generated as List of different objects (ex Resource Object, DataStructure Object)

example AST for Advanced Action API
Note : Not considering the resouceGroup for shortening the AST
paste the both ASTs in JSON Editor would be easy to differentiate
Generated AST

{
  "_version": "4.0",
  "metadata": [
    {
      "name": "FORMAT",
      "value": "1A"
    }
  ],
  "name": "Advanced Action API",
  "description": "Description",
  "element": "category",
  "resourceGroups": [  ],
  "content": [
    {
      "element": "category",
      "content": [
        {
          "element": "resource",
          "name": "Tasks",
          "description": "",
          "uriTemplate": "/tasks/tasks{?status,priority}",
          "model": {},
          "parameters": [
            {
              "name": "status",
              "description": "",
              "type": "string",
              "required": true,
              "default": "",
              "example": "",
              "values": []
            },
            {
              "name": "priority",
              "description": "",
              "type": "number",
              "required": true,
              "default": "",
              "example": "",
              "values": []
            }
          ],
          "actions": [
            {
              "name": "List All Tasks",
              "description": "",
              "method": "GET",
              "parameters": [],
              "attributes": {
                "relation": "",
                "uriTemplate": ""
              },
              "content": [],
              "examples": [
                {
                  "name": "",
                  "description": "",
                  "requests": [],
                  "responses": [
                    {
                      "name": "200",
                      "description": "",
                      "headers": [
                        {
                          "name": "Content-Type",
                          "value": "application/json"
                        }
                      ],
                      "body": "[\n    {\n        \"id\": 123,\n        \"name\": \"Exercise in gym\",\n        \"done\": false,\n        \"type\": \"task\"\n    },\n    {\n        \"id\": 124,\n        \"name\": \"Shop for groceries\",\n        \"done\": true,\n        \"type\": \"task\"\n    }\n]\n",
                      "schema": "",
                      "content": [
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodyExample"
                          },
                          "content": "[\n    {\n        \"id\": 123,\n        \"name\": \"Exercise in gym\",\n        \"done\": false,\n        \"type\": \"task\"\n    },\n    {\n        \"id\": 124,\n        \"name\": \"Shop for groceries\",\n        \"done\": true,\n        \"type\": \"task\"\n    }\n]\n"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "Retrieve Task",
              "description": "This is a state transition to another resource\n\n",
              "method": "GET",
              "parameters": [
                {
                  "name": "id",
                  "description": "",
                  "type": "string",
                  "required": true,
                  "default": "",
                  "example": "",
                  "values": []
                }
              ],
              "attributes": {
                "relation": "",
                "uriTemplate": "/task/{id}"
              },
              "content": [],
              "examples": [
                {
                  "name": "",
                  "description": "",
                  "requests": [],
                  "responses": [
                    {
                      "name": "200",
                      "description": "",
                      "headers": [
                        {
                          "name": "Content-Type",
                          "value": "application/json"
                        }
                      ],
                      "body": "{\n    \"id\": 123,\n    \"name\": \"Go to gym\",\n    \"done\": false,\n    \"type\": \"task\"\n}\n",
                      "schema": "",
                      "content": [
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodyExample"
                          },
                          "content": "{\n    \"id\": 123,\n    \"name\": \"Go to gym\",\n    \"done\": false,\n    \"type\": \"task\"\n}\n"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "Delete Task",
              "description": "",
              "method": "DELETE",
              "parameters": [
                {
                  "name": "id",
                  "description": "",
                  "type": "string",
                  "required": true,
                  "default": "",
                  "example": "",
                  "values": []
                }
              ],
              "attributes": {
                "relation": "",
                "uriTemplate": "/task/{id}"
              },
              "content": [],
              "examples": [
                {
                  "name": "",
                  "description": "",
                  "requests": [],
                  "responses": [
                    {
                      "name": "204",
                      "description": "",
                      "headers": [],
                      "body": "",
                      "schema": "",
                      "content": []
                    }
                  ]
                }
              ]
            }
          ],
          "content": []
        }
      ]
    }
  ]
}

The AST should be as

{
  "_version": "4.0",
  "metadata": [
    {
      "name": "FORMAT",
      "value": "1A"
    }
  ],
  "name": "Advanced Action API",
  "description": " Description ",
  "element": "category",
  "resourceGroups": [],
  "content": [
    {
      "element": "category",
      "attributes" : {
          "name" : "element object"
      },
      "content": [
      {
        "element" : "resource",
        "attributes" : {
          "name" : "element object"
        },
        "content" : {
          "element": "resource",
          "name": "Tasks",
          "description": "",
          "uriTemplate": "/tasks/tasks{?status,priority}",
          "model": {},
          "parameters": [
            {
              "name": "status",
              "description": "",
              "type": "string",
              "required": true,
              "default": "",
              "example": "",
              "values": []
            },
            {
              "name": "priority",
              "description": "",
              "type": "number",
              "required": true,
              "default": "",
              "example": "",
              "values": []
            }
          ],
          "actions": [
            {
              "name": "List All Tasks",
              "description": "",
              "method": "GET",
              "parameters": [],
              "attributes": {
                "relation": "",
                "uriTemplate": ""
              },
              "content": [],
              "examples": [
                {
                  "name": "",
                  "description": "",
                  "requests": [],
                  "responses": [
                    {
                      "name": "200",
                      "description": "",
                      "headers": [
                        {
                          "name": "Content-Type",
                          "value": "application/json"
                        }
                      ],
                      "body": "[\n    {\n        \"id\": 123,\n        \"name\": \"Exercise in gym\",\n        \"done\": false,\n        \"type\": \"task\"\n    },\n    {\n        \"id\": 124,\n        \"name\": \"Shop for groceries\",\n        \"done\": true,\n        \"type\": \"task\"\n    }\n]\n",
                      "schema": "",
                      "content": [
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodyExample"
                          },
                          "content": "[\n    {\n        \"id\": 123,\n        \"name\": \"Exercise in gym\",\n        \"done\": false,\n        \"type\": \"task\"\n    },\n    {\n        \"id\": 124,\n        \"name\": \"Shop for groceries\",\n        \"done\": true,\n        \"type\": \"task\"\n    }\n]\n"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "Retrieve Task",
              "description": "This is a state transition to another resource\n\n",
              "method": "GET",
              "parameters": [
                {
                  "name": "id",
                  "description": "",
                  "type": "string",
                  "required": true,
                  "default": "",
                  "example": "",
                  "values": []
                }
              ],
              "attributes": {
                "relation": "",
                "uriTemplate": "/task/{id}"
              },
              "content": [],
              "examples": [
                {
                  "name": "",
                  "description": "",
                  "requests": [],
                  "responses": [
                    {
                      "name": "200",
                      "description": "",
                      "headers": [
                        {
                          "name": "Content-Type",
                          "value": "application/json"
                        }
                      ],
                      "body": "{\n    \"id\": 123,\n    \"name\": \"Go to gym\",\n    \"done\": false,\n    \"type\": \"task\"\n}\n",
                      "schema": "",
                      "content": [
                        {
                          "element": "asset",
                          "attributes": {
                            "role": "bodyExample"
                          },
                          "content": "{\n    \"id\": 123,\n    \"name\": \"Go to gym\",\n    \"done\": false,\n    \"type\": \"task\"\n}\n"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "Delete Task",
              "description": "",
              "method": "DELETE",
              "parameters": [
                {
                  "name": "id",
                  "description": "",
                  "type": "string",
                  "required": true,
                  "default": "",
                  "example": "",
                  "values": []
                }
              ],
              "attributes": {
                "relation": "",
                "uriTemplate": "/task/{id}"
              },
              "content": [],
              "examples": [
                {
                  "name": "",
                  "description": "",
                  "requests": [],
                  "responses": [
                    {
                      "name": "204",
                      "description": "",
                      "headers": [],
                      "body": "",
                      "schema": "",
                      "content": []
                    }
                  ]
                }
              ]
            }
          ],
          "content": []
        }
      }
      ]
    }
  ]
}

from api-blueprint-ast.

ArtK007 avatar ArtK007 commented on May 28, 2024

@pksunkara any update? Hoping you guys found the issue and it is resolved in refract since, Api Blueprint ast is not maintained anymore

from api-blueprint-ast.

pksunkara avatar pksunkara commented on May 28, 2024

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 Description Refract Namespace.

You can still get the API Blueprint AST from the parser by passing the appropriate option but please understand that we will not be maintaining it anymore.

from api-blueprint-ast.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.