fix: correct status code

This commit is contained in:
Reinaldy Rafli 2021-08-04 17:08:06 +07:00
parent 79a8dccd9c
commit e38f36c579
3 changed files with 354 additions and 354 deletions

View File

@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"title": "Jokesbapak2 Image API",
"description": "Jokes Bapak2 is an image API that you can use for free! I've been seeing lots and lots of Indonesian dad jokes on Twitter, Facebook and Instagram on early 2020. In a month, I made a Discord bot that provides the jokes. But I thought, why not make it as an API?\n",
"description": "Jokes Bapak2 is an image API that you can use for free! I've been seeing lots and lots of Indonesian dad jokes on Twitter, Facebook and Instagram on early 2020. In a month, I made a Discord bot that provides the jokes. But I thought, why not make it as an API?\n",
"version": "0.0.1",
"contact": {
"name": "Reinaldy Rafli",
@ -68,382 +68,382 @@
}
},
"responses": {
"200": {
"description": "Image has been added",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/request.joke"
},
"example": {
"link": "https://link.to/image.jpg"
}
}
}
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
},
"example": {
"error": "URL provided is not a valid image"
}
}
}
},
"403": {
"description": "Must be authenticated to submit a joke",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
}
},
"/id/{id}": {
"parameters": [
{
"in": "path",
"name": "id",
"schema": {
"type": "number"
},
"required": true,
"description": "A number that represents image's ID"
}
],
"get": {
"summary": "Get random Jokes Bapak2 image by ID",
"description": "Returns consistent image for every call.",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Image data",
"content": {
"image/jpeg": {},
"image/png": {},
"image/gif": {}
}
},
"404": {
"description": "Provided image ID was not found",
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "Requested ID was not found."
}
}
}
}
},
"patch": {
"summary": "Update a Joke with certain image ID",
"description": "Returns consistent image for every call.",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Sucessfully updated an image item",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/response.confirmation"
},
{
"201": {
"description": "Image has been added",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/request.joke"
}
]
}
}
}
},
"400": {
"description": "Link provided is not a valid image",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
},
"403": {
"description": "Must be authenticated to submit a joke",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
},
"406": {
"description": "If the Joke ID does not exists",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
},
"delete": {
"summary": "Delete a Joke with certain image ID",
"description": "hi",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Sucessfully deleted an image item",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.confirmation"
}
}
}
},
"403": {
"description": "Must be authenticated to submit a joke",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
},
"406": {
"description": "If the Joke ID does not exists",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
}
},
"/today": {
"get": {
"summary": "Get the joke of the day",
"description": "A joke a day makes more of a dad out of you.",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Image data",
"content": {
"image/jpeg": {},
"image/png": {},
"image/gif": {}
}
}
}
}
},
"/total": {
"get": {
"summary": "Get total amount of jokes in database",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Total jokes",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.confirmation"
},
"example": {
"message": "154"
}
}
}
}
}
}
},
"/submit": {
"get": {
"summary": "Get submitted Jokes",
"tags": [
"Submission"
],
"parameters": [
{
"name": "author",
"in": "query",
"required": false,
"description": "Author to be queried",
"schema": {
"type": "string"
}
},
{
"name": "approved",
"in": "query",
"required": false,
"description": "Whether query just approved jokes or not",
"schema": {
"type": "boolean"
}
},
{
"name": "limit",
"in": "query",
"required": false,
"schema": {
"type": "number"
}
},
{
"name": "page",
"in": "query",
"required": false,
"schema": {
"type": "number"
}
}
],
"responses": {
"200": {
"description": "asd",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"count": {
"type": "number"
},
"jokes": {
"type": "array",
"items": {
"$ref": "#/components/schemas/response.submission"
}
"example": {
"link": "https://link.to/image.jpg"
}
}
}
}
}
}
}
},
"post": {
"summary": "Submit a joke",
"description": "Must be in multipart/form-data format. Author must be in the format of \"Name <email>\".\n",
"tags": [
"Submission"
],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"properties": {
"link": {
"description": "Image link",
"type": "string"
},
"image": {
"description": "Image data",
"type": "string"
},
"author": {
"description": "Person who submitted this",
"type": "string"
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
},
"example": {
"error": "URL provided is not a valid image"
}
}
},
"required": [
"author",
"image",
"link"
]
}
},
"403": {
"description": "Must be authenticated to submit a joke",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "Joke successfully submitted",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"/id/{id}": {
"parameters": [
{
"in": "path",
"name": "id",
"schema": {
"type": "number"
},
"required": true,
"description": "A number that represents image's ID"
}
],
"get": {
"summary": "Get random Jokes Bapak2 image by ID",
"description": "Returns consistent image for every call.",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Image data",
"content": {
"image/jpeg": {},
"image/png": {},
"image/gif": {}
}
},
"404": {
"description": "Provided image ID was not found",
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "Requested ID was not found."
}
}
}
}
},
"patch": {
"summary": "Update a Joke with certain image ID",
"description": "Returns consistent image for every call.",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Sucessfully updated an image item",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/response.confirmation"
},
{
"$ref": "#/components/schemas/request.joke"
}
]
}
}
}
},
"400": {
"description": "Link provided is not a valid image",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
},
"403": {
"description": "Must be authenticated to submit a joke",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
},
"406": {
"description": "If the Joke ID does not exists",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
},
"delete": {
"summary": "Delete a Joke with certain image ID",
"description": "hi",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Sucessfully deleted an image item",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.confirmation"
}
}
}
},
"403": {
"description": "Must be authenticated to submit a joke",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
},
"406": {
"description": "If the Joke ID does not exists",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
}
},
"/today": {
"get": {
"summary": "Get the joke of the day",
"description": "A joke a day makes more of a dad out of you.",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Image data",
"content": {
"image/jpeg": {},
"image/png": {},
"image/gif": {}
}
}
}
}
},
"/total": {
"get": {
"summary": "Get total amount of jokes in database",
"tags": [
"Jokes"
],
"responses": {
"200": {
"description": "Total jokes",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.confirmation"
},
{
"example": {
"message": "154"
}
}
}
}
}
}
},
"/submit": {
"get": {
"summary": "Get submitted Jokes",
"tags": [
"Submission"
],
"parameters": [
{
"name": "author",
"in": "query",
"required": false,
"description": "Author to be queried",
"schema": {
"type": "string"
}
},
{
"name": "approved",
"in": "query",
"required": false,
"description": "Whether query just approved jokes or not",
"schema": {
"type": "boolean"
}
},
{
"name": "limit",
"in": "query",
"required": false,
"schema": {
"type": "number"
}
},
{
"name": "page",
"in": "query",
"required": false,
"schema": {
"type": "number"
}
}
],
"responses": {
"200": {
"description": "asd",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"$ref": "#/components/schemas/response.submission"
"count": {
"type": "number"
},
"jokes": {
"type": "array",
"items": {
"$ref": "#/components/schemas/response.submission"
}
}
}
}
]
}
}
}
}
},
"400": {
"description": "Invalid data was sent",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
"post": {
"summary": "Submit a joke",
"description": "Must be in multipart/form-data format. Author must be in the format of \"Name <email>\".\n",
"tags": [
"Submission"
],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"properties": {
"link": {
"description": "Image link",
"type": "string"
},
"image": {
"description": "Image data",
"type": "string"
},
"author": {
"description": "Person who submitted this",
"type": "string"
}
},
"required": [
"author",
"image",
"link"
]
}
}
}
},
"responses": {
"201": {
"description": "Joke successfully submitted",
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/response.confirmation"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/components/schemas/response.submission"
}
}
}
]
}
}
}
},
"400": {
"description": "Invalid data was sent",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
}
},
"/health": {
"get": {
"summary": "Health check",
"description": "Ping the databases to make sure everything's alright",
"tags": [
"Health"
],
"responses": {
"200": {
"description": "Everything is okay"
},
"403": {
"description": "Something is not okay",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
}
}
}
},
"/health": {
"get": {
"summary": "Health check",
"description": "Ping the databases to make sure everything's alright",
"tags": [
"Health"
],
"responses": {
"200": {
"description": "Everything is okay"
},
"403": {
"description": "Something is not okay",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/response.error"
}
}
}
}
}
}
}
},
"components": {
"schemas": {

View File

@ -47,7 +47,7 @@ paths:
- $ref: '#/components/schemas/request.auth'
- $ref: '#/components/schemas/request.joke'
responses:
200:
201:
description: Image has been added
content:
application/json:
@ -248,7 +248,7 @@ paths:
- image
- link
responses:
200:
201:
description: Joke successfully submitted
content:
application/json:

View File

@ -93,7 +93,7 @@ func SubmitJoke(c *fiber.Ctx) error {
}
return c.
Status(fiber.StatusOK).
Status(fiber.StatusCreated).
JSON(models.ResponseSubmission{
Message: "Joke submitted. Please wait for a few days for admin to approve your submission.",
Data: submission[0],