Skip to content

Instantly share code, notes, and snippets.

@Dhananjay-JSR
Created March 28, 2025 11:16
Show Gist options
  • Save Dhananjay-JSR/108f93fc3f203c8537ed2859e19d5b8e to your computer and use it in GitHub Desktop.
Save Dhananjay-JSR/108f93fc3f203c8537ed2859e19d5b8e to your computer and use it in GitHub Desktop.
openapi: 3.0.0
info:
title: Sample Book API
description: A simple API to manage books.
version: 1.0.0
servers:
- url: https://api.example.com/v1
description: Production server
paths:
/books:
get:
summary: Get a list of books
operationId: getBooks
tags:
- Books
responses:
'200':
description: A list of books
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Book'
post:
summary: Add a new book
operationId: addBook
tags:
- Books
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Book'
responses:
'201':
description: Book created successfully
/books/{id}:
get:
summary: Get details of a book
operationId: getBookById
tags:
- Books
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: Details of the book
content:
application/json:
schema:
$ref: '#/components/schemas/Book'
'404':
description: Book not found
delete:
summary: Delete a book
operationId: deleteBook
tags:
- Books
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'204':
description: Book deleted successfully
components:
schemas:
Book:
type: object
properties:
id:
type: string
example: "1"
title:
type: string
example: "The Great Gatsby"
author:
type: string
example: "F. Scott Fitzgerald"
publishedYear:
type: integer
example: 1925
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment