Created
September 30, 2023 23:40
-
-
Save Layeska/39f25f2a364d6f0a0e13e84f710841d2 to your computer and use it in GitHub Desktop.
Ejemplo OpenApi Libreria Swagger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"openapi": "3.0.0", | |
"info": { | |
"title": "API de Librería", | |
"description": "API para gestionar libros y autores en una librería", | |
"version": "1.0.0" | |
}, | |
"paths": { | |
"/libros": { | |
"get": { | |
"summary": "Obtiene la lista de todos los libros", | |
"responses": { | |
"200": { | |
"description": "Lista de libros obtenida correctamente", | |
"content": { | |
"application/json": { | |
"example": { | |
"libros": [ | |
{ | |
"id": 1, | |
"titulo": "Cien años de soledad", | |
"autor": "Gabriel García Márquez" | |
}, | |
{ | |
"id": 2, | |
"titulo": "1984", | |
"autor": "George Orwell" | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
}, | |
"post": { | |
"summary": "Crea un nuevo libro", | |
"requestBody": { | |
"required": true, | |
"content": { | |
"application/json": { | |
"schema": { | |
"type": "object", | |
"properties": { | |
"titulo": { | |
"type": "string" | |
}, | |
"autor": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
}, | |
"responses": { | |
"201": { | |
"description": "Libro creado correctamente" | |
}, | |
"400": { | |
"description": "Petición inválida" | |
} | |
} | |
} | |
}, | |
"/libros/{id}": { | |
"parameters": [ | |
{ | |
"name": "id", | |
"in": "path", | |
"required": true, | |
"description": "ID del libro", | |
"schema": { | |
"type": "integer" | |
} | |
} | |
], | |
"get": { | |
"summary": "Obtiene un libro por su ID", | |
"responses": { | |
"200": { | |
"description": "Libro obtenido correctamente", | |
"content": { | |
"application/json": { | |
"example": { | |
"id": 1, | |
"titulo": "Cien años de soledad", | |
"autor": "Gabriel García Márquez" | |
} | |
} | |
} | |
}, | |
"404": { | |
"description": "Libro no encontrado" | |
} | |
} | |
}, | |
"put": { | |
"summary": "Actualiza un libro existente por su ID", | |
"requestBody": { | |
"required": true, | |
"content": { | |
"application/json": { | |
"schema": { | |
"type": "object", | |
"properties": { | |
"titulo": { | |
"type": "string" | |
}, | |
"autor": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
}, | |
"responses": { | |
"200": { | |
"description": "Libro actualizado correctamente" | |
}, | |
"400": { | |
"description": "Petición inválida" | |
}, | |
"404": { | |
"description": "Libro no encontrado" | |
} | |
} | |
}, | |
"delete": { | |
"summary": "Elimina un libro por su ID", | |
"responses": { | |
"204": { | |
"description": "Libro eliminado correctamente" | |
}, | |
"404": { | |
"description": "Libro no encontrado" | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment