diff --git a/.gitignore b/.gitignore index 303e7bb..39bd4dd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,3 @@ tmp goapp tmp - -docs \ No newline at end of file diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 0000000..4c65105 --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,326 @@ +// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT +// This file was generated by swaggo/swag +package docs + +import ( + "bytes" + "encoding/json" + "strings" + "text/template" + + "github.com/swaggo/swag" +) + +var doc = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "termsOfService": "todo-list-hateoas.herokuapp.com", + "contact": { + "name": "Vinícius Boscardin", + "email": "boscardinvinicius@gmail.com" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/item": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Fetch items by initials", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Fetch items by initials", + "parameters": [ + { + "type": "string", + "description": "vnb", + "name": "initials", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Create new item", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Create new item", + "parameters": [ + { + "description": "item", + "name": "company", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + } + }, + "/item/{id}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get item by id", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Get item by id", + "parameters": [ + { + "type": "integer", + "description": "1", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Update item by id", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Update item by id", + "parameters": [ + { + "description": "item", + "name": "item", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.Item" + } + }, + { + "type": "integer", + "description": "1", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete item by id", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Delete item by id", + "parameters": [ + { + "type": "integer", + "description": "1", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + } + } + }, + "definitions": { + "domain.Item": { + "type": "object", + "properties": { + "_links": { + "type": "array", + "items": { + "$ref": "#/definitions/domain.Link" + } + }, + "date": { + "type": "string", + "example": "2021-02-02" + }, + "description": { + "type": "string", + "example": "Descrição da tarefa 1" + }, + "initials": { + "type": "string", + "maxLength": 3, + "example": "vin" + }, + "name": { + "type": "string", + "example": "Tarefa 1" + } + } + }, + "domain.Link": { + "type": "object", + "properties": { + "doc": { + "type": "string", + "example": "http(s)://\u003cDOMAIN_OR_IP\u003e/doc/index.html" + }, + "href": { + "type": "string", + "example": "http(s)://\u003cDOMAIN_OR_IP\u003e/item/{id}" + }, + "method": { + "type": "string", + "example": "GET" + } + } + } + } +}` + +type swaggerInfo struct { + Version string + Host string + BasePath string + Schemes []string + Title string + Description string +} + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = swaggerInfo{ + Version: "2021.12.5.0", + Host: "todo-list-hateoas.herokuapp.com", + BasePath: "/", + Schemes: []string{}, + Title: "Clean architecture and Level 3 of REST", + Description: "An application of studies on the implementation of clean architecture with golang with a plus of REST level 3 implementations", +} + +type s struct{} + +func (s *s) ReadDoc() string { + sInfo := SwaggerInfo + sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1) + + t, err := template.New("swagger_info").Funcs(template.FuncMap{ + "marshal": func(v interface{}) string { + a, _ := json.Marshal(v) + return string(a) + }, + "escape": func(v interface{}) string { + // escape tabs + str := strings.Replace(v.(string), "\t", "\\t", -1) + // replace " with \", and if that results in \\", replace that with \\\" + str = strings.Replace(str, "\"", "\\\"", -1) + return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1) + }, + }).Parse(doc) + if err != nil { + return doc + } + + var tpl bytes.Buffer + if err := t.Execute(&tpl, sInfo); err != nil { + return doc + } + + return tpl.String() +} + +func init() { + swag.Register(swag.Name, &s{}) +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..585443f --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,258 @@ +{ + "swagger": "2.0", + "info": { + "description": "An application of studies on the implementation of clean architecture with golang with a plus of REST level 3 implementations", + "title": "Clean architecture and Level 3 of REST", + "termsOfService": "todo-list-hateoas.herokuapp.com", + "contact": { + "name": "Vinícius Boscardin", + "email": "boscardinvinicius@gmail.com" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "2021.12.5.0" + }, + "host": "todo-list-hateoas.herokuapp.com", + "basePath": "/", + "paths": { + "/item": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Fetch items by initials", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Fetch items by initials", + "parameters": [ + { + "type": "string", + "description": "vnb", + "name": "initials", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + }, + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Create new item", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Create new item", + "parameters": [ + { + "description": "item", + "name": "company", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + } + }, + "/item/{id}": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get item by id", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Get item by id", + "parameters": [ + { + "type": "integer", + "description": "1", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + }, + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Update item by id", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Update item by id", + "parameters": [ + { + "description": "item", + "name": "item", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.Item" + } + }, + { + "type": "integer", + "description": "1", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + }, + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Delete item by id", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "item" + ], + "summary": "Delete item by id", + "parameters": [ + { + "type": "integer", + "description": "1", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.Item" + } + } + } + } + } + }, + "definitions": { + "domain.Item": { + "type": "object", + "properties": { + "_links": { + "type": "array", + "items": { + "$ref": "#/definitions/domain.Link" + } + }, + "date": { + "type": "string", + "example": "2021-02-02" + }, + "description": { + "type": "string", + "example": "Descrição da tarefa 1" + }, + "initials": { + "type": "string", + "maxLength": 3, + "example": "vin" + }, + "name": { + "type": "string", + "example": "Tarefa 1" + } + } + }, + "domain.Link": { + "type": "object", + "properties": { + "doc": { + "type": "string", + "example": "http(s)://\u003cDOMAIN_OR_IP\u003e/doc/index.html" + }, + "href": { + "type": "string", + "example": "http(s)://\u003cDOMAIN_OR_IP\u003e/item/{id}" + }, + "method": { + "type": "string", + "example": "GET" + } + } + } + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..8115234 --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,168 @@ +basePath: / +definitions: + domain.Item: + properties: + _links: + items: + $ref: '#/definitions/domain.Link' + type: array + date: + example: "2021-02-02" + type: string + description: + example: Descrição da tarefa 1 + type: string + initials: + example: vin + maxLength: 3 + type: string + name: + example: Tarefa 1 + type: string + type: object + domain.Link: + properties: + doc: + example: http(s):///doc/index.html + type: string + href: + example: http(s):///item/{id} + type: string + method: + example: GET + type: string + type: object +host: todo-list-hateoas.herokuapp.com +info: + contact: + email: boscardinvinicius@gmail.com + name: Vinícius Boscardin + description: An application of studies on the implementation of clean architecture + with golang with a plus of REST level 3 implementations + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + termsOfService: todo-list-hateoas.herokuapp.com + title: Clean architecture and Level 3 of REST + version: 2021.12.5.0 +paths: + /item: + get: + consumes: + - application/json + description: Fetch items by initials + parameters: + - description: vnb + in: query + name: initials + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.Item' + security: + - ApiKeyAuth: [] + summary: Fetch items by initials + tags: + - item + post: + consumes: + - application/json + description: Create new item + parameters: + - description: item + in: body + name: company + required: true + schema: + $ref: '#/definitions/domain.Item' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.Item' + security: + - ApiKeyAuth: [] + summary: Create new item + tags: + - item + /item/{id}: + delete: + consumes: + - application/json + description: Delete item by id + parameters: + - description: "1" + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.Item' + security: + - ApiKeyAuth: [] + summary: Delete item by id + tags: + - item + get: + consumes: + - application/json + description: Get item by id + parameters: + - description: "1" + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.Item' + security: + - ApiKeyAuth: [] + summary: Get item by id + tags: + - item + put: + consumes: + - application/json + description: Update item by id + parameters: + - description: item + in: body + name: item + required: true + schema: + $ref: '#/definitions/domain.Item' + - description: "1" + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.Item' + security: + - ApiKeyAuth: [] + summary: Update item by id + tags: + - item +swagger: "2.0"