openapi: 3.0.1 info: title: Simple Social Media API description: A basic Social Networking Service (SNS) API that allows users to create, retrieve, update, and delete posts; add comments; and like/unlike posts. version: 1.0.0 contact: name: Contoso Product Team email: support@contoso.com license: name: MIT url: https://opensource.org/licenses/MIT servers: - url: http://localhost:8080/api description: Local development server paths: /posts: get: summary: List all posts description: Retrieve all recent posts to browse what others are sharing operationId: getPosts tags: - Posts responses: '200': description: Successfully retrieved posts content: application/json: schema: type: array items: $ref: '#/components/schemas/Post' '500': $ref: '#/components/responses/InternalServerError' post: summary: Create a new post description: Create a new post to share something with others operationId: createPost tags: - Posts requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/NewPostRequest' responses: '201': description: Post created successfully content: application/json: schema: $ref: '#/components/schemas/Post' '400': $ref: '#/components/responses/BadRequest' '500': $ref: '#/components/responses/InternalServerError' /posts/{postId}: get: summary: Get a specific post description: Retrieve a specific post by its ID to read in detail operationId: getPostById tags: - Posts parameters: - $ref: '#/components/parameters/PostIdPath' responses: '200': description: Successfully retrieved the post content: application/json: schema: $ref: '#/components/schemas/Post' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' patch: summary: Update a post description: Update an existing post if you made a mistake or have something to add operationId: updatePost tags: - Posts parameters: - $ref: '#/components/parameters/PostIdPath' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UpdatePostRequest' responses: '200': description: Post updated successfully content: application/json: schema: $ref: '#/components/schemas/Post' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' delete: summary: Delete a post description: Delete a post if you no longer want it shared operationId: deletePost tags: - Posts parameters: - $ref: '#/components/parameters/PostIdPath' responses: '204': description: Post deleted successfully '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' /posts/{postId}/comments: get: summary: List comments for a post description: Retrieve all comments on a specific post operationId: getCommentsByPostId tags: - Comments parameters: - $ref: '#/components/parameters/PostIdPath' responses: '200': description: Successfully retrieved comments content: application/json: schema: type: array items: $ref: '#/components/schemas/Comment' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' post: summary: Create a comment description: Add a comment to a post to share your thoughts operationId: createComment tags: - Comments parameters: - $ref: '#/components/parameters/PostIdPath' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/NewCommentRequest' responses: '201': description: Comment created successfully content: application/json: schema: $ref: '#/components/schemas/Comment' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' /posts/{postId}/comments/{commentId}: get: summary: Get a specific comment description: Retrieve a specific comment by its ID operationId: getCommentById tags: - Comments parameters: - $ref: '#/components/parameters/PostIdPath' - $ref: '#/components/parameters/CommentIdPath' responses: '200': description: Successfully retrieved the comment content: application/json: schema: $ref: '#/components/schemas/Comment' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' patch: summary: Update a comment description: Update an existing comment to correct or revise it operationId: updateComment tags: - Comments parameters: - $ref: '#/components/parameters/PostIdPath' - $ref: '#/components/parameters/CommentIdPath' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UpdateCommentRequest' responses: '200': description: Comment updated successfully content: application/json: schema: $ref: '#/components/schemas/Comment' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' delete: summary: Delete a comment description: Delete a comment if necessary operationId: deleteComment tags: - Comments parameters: - $ref: '#/components/parameters/PostIdPath' - $ref: '#/components/parameters/CommentIdPath' responses: '204': description: Comment deleted successfully '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' /posts/{postId}/likes: post: summary: Like a post description: Like a post to show appreciation operationId: likePost tags: - Likes parameters: - $ref: '#/components/parameters/PostIdPath' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/LikeRequest' responses: '201': description: Post liked successfully content: application/json: schema: $ref: '#/components/schemas/LikeResponse' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' delete: summary: Unlike a post description: Remove your like from a post if you change your mind operationId: unlikePost tags: - Likes parameters: - $ref: '#/components/parameters/PostIdPath' responses: '204': description: Like removed successfully '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' components: parameters: PostIdPath: name: postId in: path required: true description: Unique identifier of the post schema: type: string format: uuid example: "123e4567-e89b-12d3-a456-426614174000" CommentIdPath: name: commentId in: path required: true description: Unique identifier of the comment schema: type: string format: uuid example: "987fcdeb-51a2-43d1-9f6b-123456789abc" schemas: Post: type: object required: - id - username - content - createdAt - updatedAt - likesCount - commentsCount properties: id: type: string format: uuid description: Unique identifier for the post example: "123e4567-e89b-12d3-a456-426614174000" username: type: string minLength: 1 maxLength: 50 description: Username of the post author example: "john_doe" content: type: string minLength: 1 maxLength: 2000 description: Content of the post example: "Just had an amazing hike in the mountains! #outdoorlife" createdAt: type: string format: date-time description: Timestamp when the post was created example: "2025-06-01T10:30:00Z" updatedAt: type: string format: date-time description: Timestamp when the post was last updated example: "2025-06-01T10:30:00Z" likesCount: type: integer minimum: 0 description: Number of likes on the post example: 15 commentsCount: type: integer minimum: 0 description: Number of comments on the post example: 3 Comment: type: object required: - id - postId - username - content - createdAt - updatedAt properties: id: type: string format: uuid description: Unique identifier for the comment example: "987fcdeb-51a2-43d1-9f6b-123456789abc" postId: type: string format: uuid description: ID of the post this comment belongs to example: "123e4567-e89b-12d3-a456-426614174000" username: type: string minLength: 1 maxLength: 50 description: Username of the comment author example: "jane_smith" content: type: string minLength: 1 maxLength: 1000 description: Content of the comment example: "Great photo! Where was this taken?" createdAt: type: string format: date-time description: Timestamp when the comment was created example: "2025-06-01T11:15:00Z" updatedAt: type: string format: date-time description: Timestamp when the comment was last updated example: "2025-06-01T11:15:00Z" NewPostRequest: type: object required: - username - content properties: username: type: string minLength: 1 maxLength: 50 description: Username of the post author example: "john_doe" content: type: string minLength: 1 maxLength: 2000 description: Content of the post example: "Just had an amazing hike in the mountains! #outdoorlife" UpdatePostRequest: type: object required: - username - content properties: username: type: string minLength: 1 maxLength: 50 description: Username of the post author (for validation) example: "john_doe" content: type: string minLength: 1 maxLength: 2000 description: Updated content of the post example: "Just had an amazing hike in the mountains! The view was breathtaking. #outdoorlife #hiking" NewCommentRequest: type: object required: - username - content properties: username: type: string minLength: 1 maxLength: 50 description: Username of the comment author example: "jane_smith" content: type: string minLength: 1 maxLength: 1000 description: Content of the comment example: "Great photo! Where was this taken?" UpdateCommentRequest: type: object required: - username - content properties: username: type: string minLength: 1 maxLength: 50 description: Username of the comment author (for validation) example: "jane_smith" content: type: string minLength: 1 maxLength: 1000 description: Updated content of the comment example: "Great photo! Where was this taken? The scenery looks amazing!" LikeRequest: type: object required: - username properties: username: type: string minLength: 1 maxLength: 50 description: Username of the user liking the post example: "mike_wilson" LikeResponse: type: object required: - postId - username - likedAt properties: postId: type: string format: uuid description: ID of the liked post example: "123e4567-e89b-12d3-a456-426614174000" username: type: string description: Username who liked the post example: "mike_wilson" likedAt: type: string format: date-time description: Timestamp when the post was liked example: "2025-06-01T12:00:00Z" Error: type: object required: - error - message properties: error: type: string description: Error code or type example: "VALIDATION_ERROR" message: type: string description: Human-readable error message example: "The request body is invalid" details: type: array description: Additional error details (optional) items: type: string example: ["username is required", "content must not be empty"] responses: BadRequest: description: Bad request - invalid input or validation error content: application/json: schema: $ref: '#/components/schemas/Error' example: error: "VALIDATION_ERROR" message: "The request body is invalid" details: ["username is required", "content must not be empty"] NotFound: description: Resource not found content: application/json: schema: $ref: '#/components/schemas/Error' example: error: "NOT_FOUND" message: "The requested resource was not found" InternalServerError: description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' example: error: "INTERNAL_ERROR" message: "An unexpected error occurred" tags: - name: Posts description: Operations related to posts management - name: Comments description: Operations related to comments management - name: Likes description: Operations related to likes management