github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/etc/templates/openapi.tmpl (about) 1 {% autoescape off %}{ 2 "swagger": "2.0", 3 "info": { 4 "version": "0.1", 5 "title": "gohan API" 6 }, 7 "basePath": "/", 8 "schemes": [ 9 "http" 10 ], 11 "consumes": [ 12 "application/json" 13 ], 14 "produces": [ 15 "application/json" 16 ], 17 "paths": { {% for schema in schemas %}{% if schema.Metadata.type != "metaschema" && schema.Type != "abstract" %} 18 "{{ schema.GetPluralURL() }}": { 19 "get": { 20 "description" : "Get list of {{ schema.ID}} resources", 21 "produces": [ 22 "application/json" 23 ], 24 "responses": { 25 "200": { 26 "description": "{{ schema.description }}", 27 "schema": { 28 "type": "array", 29 "items": { 30 "$ref": "#/definitions/{{ schema.ID }}" 31 } 32 } 33 }, 34 "default": { 35 "description": "unexpected error", 36 "schema": { 37 "$ref": "#/definitions/errorModel" 38 } 39 } 40 } 41 }, 42 "post": { 43 "description" : "Create new {{ schema.ID }} resource", 44 "produces": [ 45 "application/json" 46 ], 47 "parameters": [ 48 { 49 "name": "{{ schema.ID }}", 50 "in": "body", 51 "description": "{{ schema.ID }} resource input", 52 "required": true, 53 "schema": { 54 "$ref": "#/definitions/{{ schema.ID }}Input" 55 } 56 }], 57 "responses": { 58 "201": { 59 "description": "{{ schema.ID }} created", 60 "schema": { 61 "$ref": "#/definitions/{{ schema.ID }}" 62 } 63 }, 64 "default": { 65 "description": "unexpected error", 66 "schema": { 67 "$ref": "#/definitions/errorModel" 68 } 69 } 70 } 71 } 72 }, 73 "{{ schema.URL }}/{id}": { 74 "get": { 75 "description" : "Show a {{ schema.ID}} resources", 76 "produces": [ 77 "application/json" 78 ], 79 "parameters": [ 80 { 81 "name": "id", 82 "in": "path", 83 "description": "ID of {{ schema.ID }} to fetch", 84 "required": true, 85 "type": "string" 86 } 87 ], 88 "responses": { 89 "200": { 90 "description": "{{ schema.description }}", 91 "schema": { 92 "$ref": "#/definitions/{{ schema.ID }}" 93 } 94 }, 95 "default": { 96 "description": "unexpected error", 97 "schema": { 98 "$ref": "#/definitions/errorModel" 99 } 100 } 101 } 102 }, 103 "put": { 104 "description" : "Update {{ schema.ID }} resource", 105 "produces": [ 106 "application/json" 107 ], 108 "parameters": [ 109 { 110 "name": "id", 111 "in": "path", 112 "description": "ID of {{ schema.ID }} to update", 113 "required": true, 114 "type": "string" 115 }, 116 { 117 "name": "{{ schema.ID }}", 118 "in": "body", 119 "description": "{{ schema.ID }} reosurce input", 120 "required": true, 121 "schema": { 122 "$ref": "#/definitions/{{ schema.ID }}Update" 123 } 124 }], 125 "responses": { 126 "200": { 127 "description": "{{ schema.ID }} created", 128 "schema": { 129 "$ref": "#/definitions/{{ schema.ID }}" 130 } 131 }, 132 "default": { 133 "description": "unexpected error", 134 "schema": { 135 "$ref": "#/definitions/errorModel" 136 } 137 } 138 } 139 }, 140 "delete": { 141 "description" : "Delete a {{ schema.ID }} resources", 142 "produces": [ 143 "application/json" 144 ], 145 "parameters": [ 146 { 147 "name": "id", 148 "in": "path", 149 "description": "ID of {{ schema.ID }} to fetch", 150 "required": true, 151 "type": "string" 152 } 153 ], 154 "responses": { 155 "204": { 156 "description": "{{ schema.ID }} get deleted", 157 "schema": { 158 "$ref": "#/definitions/{{ schema.ID }}" 159 } 160 }, 161 "default": { 162 "description": "unexpected error", 163 "schema": { 164 "$ref": "#/definitions/errorModel" 165 } 166 } 167 } 168 } 169 }{% for action in schema.Actions %}, 170 "{{ schema.GetPluralURL() }}{{ action.Path | swagger_path }}": { 171 "{{ action.Method|lower }}" : { 172 "description": "Action {{ action.ID}}", 173 "produces": [ 174 "application/json" 175 ], 176 {% with has_id=action.Path | swagger_has_id_param put_or_post=action.Method | lower == "post" or action.Method | lower == "put" %} 177 "parameters": [ {% if has_id %} 178 { 179 "name": "id", 180 "in": "path", 181 "description": "ID of {{ schema.ID }} to fetch", 182 "required": true, 183 "type": "string" 184 }{% endif %}{% if has_id and put_or_post %}, {% endif %} {% if put_or_post %} 185 { 186 "name": "{{ action.ID }} request object", 187 "in": "body", 188 "description": "{{ action.ID }} request object", 189 "required": true, 190 "schema": 191 {% with schema=action.InputSchema | swagger: " " %} 192 {% if schema == "null" %} 193 {} {% else %} {{schema}} {% endif %}{% endwith %} 194 }{% endif %} {% endwith %} 195 ], 196 "responses": { 197 "200": { 198 "description": "action {{ schema.ID }} response", 199 "schema": 200 {{ action.OutputSchema | swagger: " "}} 201 }, 202 "default": { 203 "description": "unexpected error", 204 "schema": { 205 "$ref": "#/definitions/errorModel" 206 } 207 } 208 } 209 } 210 }{% endfor %}{% if not forloop.Last %},{% endif %} 211 {% endif %}{% endfor %} 212 }, 213 "definitions": { {% for schema in schemas %}{% if schema.Metadata.type != "metaschema" %} 214 {% with jsonSchema=schema.JSONSchema | swagger: " " %} 215 {% if jsonSchema != "null" %} 216 "{{ schema.ID }}" : 217 {{ jsonSchema }}, {% endif %} {% endwith %} 218 {% with jsonSchemaInput=schema.JSONSchemaOnCreate | swagger: " " %} 219 {% if jsonSchemaInput != "null" %} 220 "{{ schema.ID }}Input" : 221 {{ jsonSchemaInput }}, {% endif %}{% endwith %} 222 {% with jsonSchemaUpdate=schema.JSONSchemaOnUpdate | swagger: " " %} 223 {% if jsonSchemaUpdate != "null" %} 224 "{{ schema.ID }}Update" : 225 {{ jsonSchemaUpdate }}, {% endif %}{% endwith %} 226 {% endif %}{% endfor %} 227 "errorModel": { 228 "type": "object", 229 "properties": { 230 "error": { 231 "description": "error message", 232 "title": "error", 233 "type": "string" 234 } 235 } 236 } 237 } 238 } 239 {% endautoescape %}