diff --git a/definition/request.go b/definition/request.go index 0d2dc1e..2a9abe9 100644 --- a/definition/request.go +++ b/definition/request.go @@ -7,3 +7,16 @@ type Request struct { Body []Body Headers []Header } + +// IsEmpty verifies is the request is empty +func (r Request) IsEmpty() bool { + if r.Title != "" || r.Description != "" { + return false + } + + if len(r.Body) > 0 || len(r.Headers) > 0 { + return false + } + + return true +} \ No newline at end of file diff --git a/examples/spec/blueprint/realworld.apib b/examples/spec/blueprint/realworld.apib index 3228249..284b245 100644 --- a/examples/spec/blueprint/realworld.apib +++ b/examples/spec/blueprint/realworld.apib @@ -74,7 +74,7 @@ Returns a specific Post. + Response 200 (application/json) - This is a mighty example + Single post Resource + Body @@ -121,7 +121,20 @@ Returns a specific Post. "you_starred": false }, "meta": { - "code": 200, + "code": 200 + } + } + ++ Response 404 (application/json) + + Resource Not found + + + Body + + { + "data": {}, + "meta": { + "code": 200 } } diff --git a/try-it-out/css/try-it-out.css b/try-it-out/css/try-it-out.css index 75e4806..c686de5 100644 --- a/try-it-out/css/try-it-out.css +++ b/try-it-out/css/try-it-out.css @@ -12,3 +12,10 @@ h1 { text-align: center; color: #FF0000; } + +pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; } +.string { color: green; } +.number { color: darkorange; } +.boolean { color: blue; } +.null { color: magenta; } +.key { color: red; } \ No newline at end of file diff --git a/try-it-out/index.html b/try-it-out/index.html index 28e62d2..94f4022 100644 --- a/try-it-out/index.html +++ b/try-it-out/index.html @@ -3,372 +3,713 @@ - REST API Documentation + Real World API - - - -
- -

REST API Documentation

- -
-

Getting Started

- -
+ -
-

Resources

- +
+ +
+

Resources

+ +
+
+ +
+ + + + +
+

Response

+
+
+
+
- - - -
-
    -
  • -
    - /v1/products/{uuid}/items - - - -
    -
    - -
    -
    -

    Request

    -
    -
    -
    -

    Description

    -

    get items ...

    -
    -
    -
    -
    -
    -

    Request

    -
    -
    -
    -

    Description

    -

    patch items....

    +
    +
    +
    +

    Status 200

    +

    Single post Resource

    + +
    +

    Body

    +

    + application/json +

    + + +
    +

    +
    + +
    + + + +

    + Example-1 +

    +
    +
    {
    +    "data": {
    +        "id": "1", // note this is a string
    +        "user": {
    +            ...
    +        },
    +        "created_at": "2012-07-16T17:25:47Z",
    +        "text": "@berg FIRST post on this new site #newsocialnetwork",
    +        "html": "<span itemprop=\"mention\" data-mention-name=\"berg\" data-mention-id=\"2\">@berg</span> FIRST post on <a href=\"https://join.app.net\" rel=\"nofollow\">this new site</a> <span itemprop=\"hashtag\" data-hashtag-name=\"newsocialnetwork\">#newsocialnetwork</span>.",
    +        "source": {
    +            "client_id": "udxGzAVBdXwGtkHmvswR5MbMEeVnq6n4",
    +            "name": "Clientastic for iOS",
    +            "link": "http://app.net"
    +        },
    +        "machine_only": false,
    +        "reply_to": null,
    +        "thread_id": "1",
    +        "num_replies": 3,
    +        "num_reposts": 0,
    +        "num_stars": 0,
    +        "entities": {
    +            "mentions": [{
    +                "name": "berg",
    +                "id": "2",
    +                "pos": 0,
    +                "len": 5
    +            }],
    +            "hashtags": [{
    +                "name": "newsocialnetwork",
    +                "pos": 34,
    +                "len": 17
    +            }],
    +            "links": [{
    +                "text": "this new site",
    +                "url": "https://join.app.net"
    +                "pos": 20,
    +                "len": 13
    +            }]
    +        },
    +        "you_reposted": false,
    +        "you_starred": false
    +    },
    +    "meta": {
    +        "code": 200
    +    }
    +}
    +
    +
    +
    -
    -
    - -
    -
  • -
  • -
    - /v1/products/{uuid}/images - - -
    -
    - -
    -
    -

    Request

    -
    -
    -
    -

    Description

    -

    get images...

    -
    -
    -
    -
    -
    -

    Request

    -
    -
    -
    -

    Description

    -

    patch images ....

    +
    +
    +

    Status 404

    +

    Resource Not found

    + +
    +

    Body

    +

    + application/json +

    + + +
    +

    +
    + +
    + + + +

    + Example-1 +

    +
    +
    {
    +    "data": {},
    +    "meta": {
    +        "code": 200
    +    }
    +}
    +
    +
    +
    -
    -
    -
    -
  • +
+
+
+ +
+
+ + + + +
+

Response

+
+
+
+
- +
+
+
+

Status 204

+

+ + +
+
+
- -
  • -
    - - /v1/orders -
      -
    • - get - x -
    • -
    • + + +
    +
  • + +
  • +
    + + + /stream/0/posts + + + + +
    +
    + +
    + + +
    +

    Request

    +
    +
    + + + + +
    + + + +

    Headers

    +
    +

    Content-Type application/json

    +

    +
    -
    -
    -
    -

    Request

    -
    -
    GET!
    + +
    +

    Body

    +

    + application/json +

    + + + +
    +

    +
    + +
    + + +
    +
    + + +
    +

    Response

    +
    +
    +
    +
    -
    -
    -

    Request

    -
    -
    -
    -

    Description

    -

    Allows you to modify the properties of an account.

    -
    +
    +
    +
    +

    Status 201

    +

    -
    -

    URI Parameters

    -
    -

    AccountSid required, 34-34 characters string

    -

    A 34 character string that uniquely identifies this account.

    -
    -
    -

    mediaTypeExtension required, 34-34 characters string

    -
    -
    -

    version required, (2010-04-01) string

    -

    A 34 character string that uniquely identifies this account.

    +
    +

    Body

    +

    + application/json +

    + + +
    +

    +
    + +
    + + + +

    + Example-1 +

    +
    +
    {
    +    "data": {
    +        "id": "1", // note this is a string
    +        "user": {
    +            ...
    +        },
    +        "created_at": "2012-07-16T17:25:47Z",
    +        "text": "@berg FIRST post on this new site #newsocialnetwork",
    +        "html": "<span itemprop=\"mention\" data-mention-name=\"berg\" data-mention-id=\"2\">@berg</span> FIRST post on <a href=\"https://join.app.net\" rel=\"nofollow\">this new site</a> <span itemprop=\"hashtag\" data-hashtag-name=\"newsocialnetwork\">#newsocialnetwork</span>.",
    +        "source": {
    +            "client_id": "udxGzAVBdXwGtkHmvswR5MbMEeVnq6n4",
    +            "name": "Clientastic for iOS",
    +            "link": "http://app.net"
    +        },
    +        "machine_only": false,
    +        "reply_to": null,
    +        "thread_id": "1",
    +        "num_replies": 3,
    +        "num_reposts": 0,
    +        "num_stars": 0,
    +        "entities": {
    +            "mentions": [{
    +                "name": "berg",
    +                "id": "2",
    +                "pos": 0,
    +                "len": 5
    +            }],
    +            "hashtags": [{
    +                "name": "newsocialnetwork",
    +                "pos": 34,
    +                "len": 17
    +            }],
    +            "links": [{
    +                "text": "this new site",
    +                "url": "https://join.app.net"
    +                "pos": 20,
    +                "len": 13
    +            }]
    +        },
    +        "you_reposted": false,
    +        "you_starred": false
    +    },
    +    "meta": {
    +        "code": 200,
    +    }
    +}
    +
    +
    + +
    +
    +
    + +
    +
    + + -
    -

    Security schemes

    -

    Oauth

    + +
    +

    Response

    +
    +
    +
    +
      -

      Scope

      -

      finance_read

      +
    • 200
    • +
    +
    +
    +
    +
    +

    Status 200

    +

    -

    Headers

    -
    -

    Authorization string

    -

    Authorization description.

    -
    -
    +
    +

    Body

    +

    + application/json +

    + + +
    +

    +
    + +
    -
    -

    Body

    -

    application/x-www-form-urlencoded

    + -
    -

    param1 required, 34-34 characters string

    -

    A 34 character string that uniquely identifies this account.

    -
    -
    -

    param2 required, 34-34 characters string

    +

    + Example-1 +

    +
    +
    {
    +    "data": [
    +        {
    +            "id": "1", // note this is a string
    +            ...
    +        },
    +        {
    +            "id": "2",
    +            ...
    +        },
    +        {
    +            "id": "3",
    +            ...
    +        },
    +    ],
    +    "meta": {
    +        "code": 200,
    +    }
    +}
    +
    +
    + +
    -
    -
    -

    Response

    -
    -
    -
    - -
    -
    -
    -
    -

    Status 200

    -

    The request was successful, we updated the resource and the response - body contains the representation.

    - -
    -

    Body

    -

    - application/json - application/xml -

    - -

    Examples

    -

    - Example1 - Example2 -

    -
    -
    - { - "foo": "bar" - } -
    -
    - xml example 1 -
    -
    - json example 2 -
    -
    - xml example 2 -
    +
    +
    + +
    + + +
    +
  • + +
  • + +
    + +
    + + + + +
    +

    Response

    +
    +
    +
    + +
    +
    +
    +
    +

    Status 200

    +

    + +
    +

    Body

    +

    + application/json +

    + + +
    +

    +
    + +
    + + + +

    + Example-1 +

    +
    +
    {
    +    "data": {
    +        "id": "1", // note this is a string
    +        "user": {
    +            ...
    +        },
    +        "created_at": "2012-07-16T17:25:47Z",
    +        "text": "@berg FIRST post on this new site #newsocialnetwork",
    +        "html": "<span itemprop=\"mention\" data-mention-name=\"berg\" data-mention-id=\"2\">@berg</span> FIRST post on <a href=\"https://join.app.net\" rel=\"nofollow\">this new site</a> <span itemprop=\"hashtag\" data-hashtag-name=\"newsocialnetwork\">#newsocialnetwork</span>.",
    +        "source": {
    +            "client_id": "udxGzAVBdXwGtkHmvswR5MbMEeVnq6n4",
    +            "name": "Clientastic for iOS",
    +            "link": "http://app.net"
    +        },
    +        "machine_only": false,
    +        "reply_to": null,
    +        "thread_id": "1",
    +        "num_replies": 3,
    +        "num_reposts": 0,
    +        "num_stars": 0,
    +        "entities": {
    +            "mentions": [{
    +                "name": "berg",
    +                "id": "2",
    +                "pos": 0,
    +                "len": 5
    +            }],
    +            "hashtags": [{
    +                "name": "newsocialnetwork",
    +                "pos": 34,
    +                "len": 17
    +            }],
    +            "links": [{
    +                "text": "this new site",
    +                "url": "https://join.app.net"
    +                "pos": 20,
    +                "len": 13
    +            }]
    +        },
    +        "you_reposted": false,
    +        "you_starred": false
    +    },
    +    "meta": {
    +        "code": 200,
    +    }
    +}
    +
    +
    +
    -
    -
    -
    201
    -
    300
    -
    400
    -
    401
    -
    500
    -
    -
    -
    -
    -

    Request

    -
    -
    PATCH
  • - - + +
    +
    + + + + +
    +

    Response

    +
    +
    +
    + +
    +
    +
    +
    +

    Status 200

    +

    + +
    +

    Body

    +

    + application/json +

    + + +
    +

    +
    +
    + +

    + Example-1 +

    +
    +
    {
    +    "data": {
    +        "id": "1", // note this is a string
    +        "user": {
    +            ...
    +        },
    +        "created_at": "2012-07-16T17:25:47Z",
    +        "text": "@berg FIRST post on this new site #newsocialnetwork",
    +        "html": "<span itemprop=\"mention\" data-mention-name=\"berg\" data-mention-id=\"2\">@berg</span> FIRST post on <a href=\"https://join.app.net\" rel=\"nofollow\">this new site</a> <span itemprop=\"hashtag\" data-hashtag-name=\"newsocialnetwork\">#newsocialnetwork</span>.",
    +        "source": {
    +            "client_id": "udxGzAVBdXwGtkHmvswR5MbMEeVnq6n4",
    +            "name": "Clientastic for iOS",
    +            "link": "http://app.net"
    +        },
    +        "machine_only": false,
    +        "reply_to": null,
    +        "thread_id": "1",
    +        "num_replies": 3,
    +        "num_reposts": 0,
    +        "num_stars": 0,
    +        "entities": {
    +            "mentions": [{
    +                "name": "berg",
    +                "id": "2",
    +                "pos": 0,
    +                "len": 5
    +            }],
    +            "hashtags": [{
    +                "name": "newsocialnetwork",
    +                "pos": 34,
    +                "len": 17
    +            }],
    +            "links": [{
    +                "text": "this new site",
    +                "url": "https://join.app.net"
    +                "pos": 20,
    +                "len": 13
    +            }]
    +        },
    +        "you_reposted": false,
    +        "you_starred": false
    +    },
    +    "meta": {
    +        "code": 200,
    +    }
    +}
    +
    +
    + +
    +
    +
    +
    +
    + +
    - - - - + + + - + + + + + + + + diff --git a/try-it-out/js/rubber-doc.js b/try-it-out/js/rubber-doc.js index 3177cbe..bb36172 100644 --- a/try-it-out/js/rubber-doc.js +++ b/try-it-out/js/rubber-doc.js @@ -486,3 +486,30 @@ var rubberDoc = (function () { init: init }; })(); + +function syntaxHighlight(json) { + json = json.replace(/&/g, '&').replace(//g, '>'); + return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { + var cls = 'number'; + if (/^"/.test(match)) { + if (/:$/.test(match)) { + cls = 'key'; + } else { + cls = 'string'; + } + } else if (/true|false/.test(match)) { + cls = 'boolean'; + } else if (/null/.test(match)) { + cls = 'null'; + } + return '' + match + ''; + }); +} + +$(document).ready(function() { + $('.rd-json-render').each(function() { + $(this).html( + syntaxHighlight($(this).html()) + ); + }); +}); \ No newline at end of file diff --git a/try-it-out/templates/resource_actions.tmpl b/try-it-out/templates/resource_actions.tmpl index dceaa06..3febcc3 100644 --- a/try-it-out/templates/resource_actions.tmpl +++ b/try-it-out/templates/resource_actions.tmpl @@ -2,14 +2,17 @@ {{range $actionN, $action := .}}
    {{$transaction := index $action.Transactions 0}} + {{if not $transaction.Request.IsEmpty}}

    Request

    -
    -

    Description

    -

    {{$transaction.Request.Description}}

    -
    + {{if $transaction.Request.Description}} +
    +

    Description

    +

    {{$transaction.Request.Description}}

    +
    + {{- end}} {{if $action.Href.Parameters}}
    @@ -73,6 +76,7 @@ {{- end}} {{- end}}
    + {{- end}} {{if $action.Transactions}}
    @@ -110,6 +114,16 @@ {{template "custom_type" $customType}} {{- end}} {{- end}} + + {{if .Example -}} +

    + Example-1 +

    +
    +
    {{.Example}}
    +
    + {{end}}
    {{- end}} {{- end}}