raml-org / raml-tck

Test Compatibility Kit for RAML 1.0
http://raml-org.github.io/raml-tck/
8 stars 10 forks source link

Diff in format of each resource type between 0.8 and 1.0 #17

Closed xaka closed 8 years ago

xaka commented 8 years ago

RAML 0.8:

"get": {
  "responses": {
    "200": {
      "body": {
        "application/json": {
          "example": "{\n    \"data\": [{\n        \"username\": \"jack\",\n        \"first_name\": \"Jack\",\n        \"profile_picture\": \"http://distillery.s3.amazonaws.com/profiles/profile_66_75sq.jpg\",\n        \"id\": \"66\",\n        \"last_name\": \"Dorsey\"\n    },\n    {\n        \"username\": \"sammyjack\",\n        \"first_name\": \"Sammy\",\n        \"profile_picture\": \"http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg\",\n        \"id\": \"29648\",\n        \"last_name\": \"Jack\"\n    },\n    {\n        \"username\": \"jacktiddy\",\n        \"first_name\": \"Jack\",\n        \"profile_picture\": \"http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg\",\n        \"id\": \"13096\",\n        \"last_name\": \"Tiddy\"\n    }]\n}",
          "schema": "users"
        }
      }
    }
  }
},
"securedBy": [
  {
    "oauth_2_0": {
      "clientId": [],
      "scopes": [
        "relationships"
      ]
    }
  }
],
"type": "base"

RAML 1.0:

"methods": {
  "method": "get",
  "responses": {
    "200": {
      "body": {
        "application/json": {
          "example": "{\n    \"data\": [{\n        \"username\": \"jack\",\n        \"first_name\": \"Jack\",\n        \"profile_picture\": \"http://distillery.s3.amazonaws.com/profiles/profile_66_75sq.jpg\",\n        \"id\": \"66\",\n        \"last_name\": \"Dorsey\"\n    },\n    {\n        \"username\": \"sammyjack\",\n        \"first_name\": \"Sammy\",\n        \"profile_picture\": \"http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg\",\n        \"id\": \"29648\",\n        \"last_name\": \"Jack\"\n    },\n    {\n        \"username\": \"jacktiddy\",\n        \"first_name\": \"Jack\",\n        \"profile_picture\": \"http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg\",\n        \"id\": \"13096\",\n        \"last_name\": \"Tiddy\"\n    }]\n}",
          "name": "application/json",
          "schema": "users",
          "schemaContent": "users"
        }
      },
      "code": "200"
    }
  },
  "securedBy": [
    {
      "name": "oauth_2_0",
      "securityScheme": {
        "describedBy": {
          "queryParameters": {
            "access_token": {
              "description": "Used to send a valid OAuth 2 access token. Do not use together with\nthe \"Authorization\" header\n",
              "name": "access_token"
            }
          }
        },
        "description": "Instagram's API uses the OAuth 2.0 protocol for simple, but effective\nauthentication and authorization. The one thing to keep in mind is tha\nall requests to the API must be made over SSL (https:// not http://)\n",
        "name": "oauth_2_0",
        "settings": {
          "accessTokenUri": "https://api.instagram.com/oauth/access_token",
          "authorizationGrants": [
            "code",
            "token"
          ],
          "authorizationUri": "https://api.instagram.com/oauth/authorize",
          "scopes": [
            "basic",
            "comments",
            "relationships",
            "likes"
          ]
        },
        "type": "OAuth 2.0"
      },
      "securitySchemeName": "oauth_2_0",
      "structuredValue": null
    },
    {
      "name": "clientId",
      "securityScheme": {
        "describedBy": {
          "queryParameters": {
            "client_id": {
              "description": "Client_id is is identifier of  your server, script, or program with a specific application\nthis parameter is required if you are accessing APIs without authenticating\n",
              "example": "9e0dbc0a3b8d436ca65ae2df9825c893",
              "name": "client_id"
            }
          }
        },
        "description": "in many situations, you may not need to authenticate users at all.\nFor instance, you may request popular photos without authenticating\n(i.e. you do not need to provide an access_token; just use your client ID with your request).\nWe only require authentication in cases where your application is making requests on behalf of a user\n(commenting, liking, browsing a user's feed, etc.).\n",
        "name": "clientId",
        "type": "x-customHeader"
      },
      "securitySchemeName": "clientId",
      "structuredValue": null
    }
  ]
},
"name": "usersListing",
"securedBy": {
  "name": "oauth_2_0",
  "securityScheme": null,
  "securitySchemeName": "[object Object]",
  "structuredValue": {
    "clientId": [],
    "scopes": [
      "relationships"
    ]
  }
},
"type": {
  "name": "base",
  "resourceType": {
    "methods": [
      {
        "method": "delete",
        "responses": {
          "503": {
            "code": "503",
            "description": "Server Unavailable. Check Your Rate Limits.\n"
          }
        },
        "securedBy": [
          {
            "name": "oauth_2_0",
            "securityScheme": {
              "describedBy": {
                "queryParameters": {
                  "access_token": {
                    "description": "Used to send a valid OAuth 2 access token. Do not use together with\nthe \"Authorization\" header\n",
                    "name": "access_token"
                  }
                }
              },
              "description": "Instagram's API uses the OAuth 2.0 protocol for simple, but effective\nauthentication and authorization. The one thing to keep in mind is tha\nall requests to the API must be made over SSL (https:// not http://)\n",
              "name": "oauth_2_0",
              "settings": {
                "accessTokenUri": "https://api.instagram.com/oauth/access_token",
                "authorizationGrants": [
                  "code",
                  "token"
                ],
                "authorizationUri": "https://api.instagram.com/oauth/authorize",
                "scopes": [
                  "basic",
                  "comments",
                  "relationships",
                  "likes"
                ]
              },
              "type": "OAuth 2.0"
            },
            "securitySchemeName": "oauth_2_0",
            "structuredValue": null
          },
          {
            "name": "clientId",
            "securityScheme": {
              "describedBy": {
                "queryParameters": {
                  "client_id": {
                    "description": "Client_id is is identifier of  your server, script, or program with a specific application\nthis parameter is required if you are accessing APIs without authenticating\n",
                    "example": "9e0dbc0a3b8d436ca65ae2df9825c893",
                    "name": "client_id"
                  }
                }
              },
              "description": "in many situations, you may not need to authenticate users at all.\nFor instance, you may request popular photos without authenticating\n(i.e. you do not need to provide an access_token; just use your client ID with your request).\nWe only require authentication in cases where your application is making requests on behalf of a user\n(commenting, liking, browsing a user's feed, etc.).\n",
              "name": "clientId",
              "type": "x-customHeader"
            },
            "securitySchemeName": "clientId",
            "structuredValue": null
          }
        ]
      },
      {
        "method": "post",
        "responses": {
          "503": {
            "code": "503",
            "description": "Server Unavailable. Check Your Rate Limits.\n"
          }
        },
        "securedBy": [
          {
            "name": "oauth_2_0",
            "securityScheme": {
              "describedBy": {
                "queryParameters": {
                  "access_token": {
                    "description": "Used to send a valid OAuth 2 access token. Do not use together with\nthe \"Authorization\" header\n",
                    "name": "access_token"
                  }
                }
              },
              "description": "Instagram's API uses the OAuth 2.0 protocol for simple, but effective\nauthentication and authorization. The one thing to keep in mind is tha\nall requests to the API must be made over SSL (https:// not http://)\n",
              "name": "oauth_2_0",
              "settings": {
                "accessTokenUri": "https://api.instagram.com/oauth/access_token",
                "authorizationGrants": [
                  "code",
                  "token"
                ],
                "authorizationUri": "https://api.instagram.com/oauth/authorize",
                "scopes": [
                  "basic",
                  "comments",
                  "relationships",
                  "likes"
                ]
              },
              "type": "OAuth 2.0"
            },
            "securitySchemeName": "oauth_2_0",
            "structuredValue": null
          },
          {
            "name": "clientId",
            "securityScheme": {
              "describedBy": {
                "queryParameters": {
                  "client_id": {
                    "description": "Client_id is is identifier of  your server, script, or program with a specific application\nthis parameter is required if you are accessing APIs without authenticating\n",
                    "example": "9e0dbc0a3b8d436ca65ae2df9825c893",
                    "name": "client_id"
                  }
                }
              },
              "description": "in many situations, you may not need to authenticate users at all.\nFor instance, you may request popular photos without authenticating\n(i.e. you do not need to provide an access_token; just use your client ID with your request).\nWe only require authentication in cases where your application is making requests on behalf of a user\n(commenting, liking, browsing a user's feed, etc.).\n",
              "name": "clientId",
              "type": "x-customHeader"
            },
            "securitySchemeName": "clientId",
            "structuredValue": null
          }
        ]
      },
      {
        "is": {
          "acceptCallback": {
            "name": "acceptCallback",
            "structuredValue": null,
            "trait": {
              "name": "acceptCallback",
              "queryParameters": {
                "callback": {
                  "description": "Callback function name. All output will be wrapper under this function name.\n",
                  "displayName": "callback",
                  "example": "callbackFunction",
                  "name": "callback",
                  "repeat": false,
                  "required": false,
                  "type": "string"
                }
              }
            }
          },
          "limitable": {
            "name": "limitable",
            "structuredValue": null,
            "trait": {
              "name": "limitable",
              "queryParameters": {
                "count": {
                  "description": "Number of items you would like to receive.",
                  "displayName": "count",
                  "example": "1",
                  "name": "count",
                  "repeat": false,
                  "required": false,
                  "type": "integer"
                }
              }
            }
          }
        },
        "method": "get",
        "responses": {
          "503": {
            "code": "503",
            "description": "Server Unavailable. Check Your Rate Limits.\n"
          }
        },
        "securedBy": [
          {
            "name": "oauth_2_0",
            "securityScheme": {
              "describedBy": {
                "queryParameters": {
                  "access_token": {
                    "description": "Used to send a valid OAuth 2 access token. Do not use together with\nthe \"Authorization\" header\n",
                    "name": "access_token"
                  }
                }
              },
              "description": "Instagram's API uses the OAuth 2.0 protocol for simple, but effective\nauthentication and authorization. The one thing to keep in mind is tha\nall requests to the API must be made over SSL (https:// not http://)\n",
              "name": "oauth_2_0",
              "settings": {
                "accessTokenUri": "https://api.instagram.com/oauth/access_token",
                "authorizationGrants": [
                  "code",
                  "token"
                ],
                "authorizationUri": "https://api.instagram.com/oauth/authorize",
                "scopes": [
                  "basic",
                  "comments",
                  "relationships",
                  "likes"
                ]
              },
              "type": "OAuth 2.0"
            },
            "securitySchemeName": "oauth_2_0",
            "structuredValue": null
          },
          {
            "name": "clientId",
            "securityScheme": {
              "describedBy": {
                "queryParameters": {
                  "client_id": {
                    "description": "Client_id is is identifier of  your server, script, or program with a specific application\nthis parameter is required if you are accessing APIs without authenticating\n",
                    "example": "9e0dbc0a3b8d436ca65ae2df9825c893",
                    "name": "client_id"
                  }
                }
              },
              "description": "in many situations, you may not need to authenticate users at all.\nFor instance, you may request popular photos without authenticating\n(i.e. you do not need to provide an access_token; just use your client ID with your request).\nWe only require authentication in cases where your application is making requests on behalf of a user\n(commenting, liking, browsing a user's feed, etc.).\n",
              "name": "clientId",
              "type": "x-customHeader"
            },
            "securitySchemeName": "clientId",
            "structuredValue": null
          }
        ]
      }
    ],
    "name": "base"
  },
  "structuredValue": null
}
sichvoge commented 8 years ago

Should we not try to use the same structure for both or is this on purpose? cc' @svacas @KonstantinSviridov

svacas commented 8 years ago

IMO resource type references should be serialized like the examples below, no need to serialize the referenced resource type. If the referenced resource type does not exist, or is declared more than once that should be reported as an error (the same logic applies to traits and security schemes)

/no-param:
  type: one
"type": "one"
/with-param:
  type:
    two:
      param: hi
"type": {
    "two": {
        "param": "hi"
    }
}
KonstantinSviridov commented 8 years ago

Ok, the formats are as follows:

Current TCK JSON:

{
  "methods": [
    { method object1 },
    { method object2 },
  ]  
}

Old JS Praser: in resource types:

{
  "methodName1": {
    method object
  },
  "methodName2": {
    method object
  },
}

At the same time the Old JS parsers serializes methods of resources just the same way, as in TCK JSON:

{
  "methods": [
    { method object1 },
    { method object2 },
  ]  
}

Thus, in case of resource, the old JS parser output contains all methods as elements of "methods" array, while in case of resource type it directly reflects YAML content. As I understand, the reason is that resource type YAML node can contain subnodes under parametrized keys, and one can not determine type of such nodes.

For TCK I would use a special field for children under parametrized keys, and I would continue serializing methods into an array. For example, serialize

get:
  responses:
    200:

<<updateMethod>>:
  body:
    application/json:

as

{
  methods:[{
    method: get
    responses: {
      200:{}
    }
  }],
  underParametrizedKeys:{
    <<updateMethod>>: {
      body: {
        application/json: {}
      }
   }
  }
}

But let's take approach of the old JS parser, if we have to be compatible with it.