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: Comment on 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 to see in detail 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: Correct or revise your comment 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 your 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 if you change your mind operationId: unlikePost tags: - Likes parameters: - $ref: '#/components/parameters/PostIdPath' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UnlikeRequest' responses: '204': description: Post unliked successfully '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' components: parameters: PostIdPath: name: postId in: path required: true description: Unique identifier for the post schema: type: string format: uuid example: "123e4567-e89b-12d3-a456-426614174000" CommentIdPath: name: commentId in: path required: true description: Unique identifier for the comment schema: type: string format: uuid example: "123e4567-e89b-12d3-a456-426614174001" 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 description: Username of the post author minLength: 1 maxLength: 50 example: "outdoorexplorer" content: type: string description: Content of the post minLength: 1 maxLength: 2000 example: "Just got back from an amazing hiking trip! The views were incredible." createdAt: type: string format: date-time description: Timestamp when the post was created example: "2025-05-30T14:30:00Z" updatedAt: type: string format: date-time description: Timestamp when the post was last updated example: "2025-05-30T14: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: "123e4567-e89b-12d3-a456-426614174001" postId: type: string format: uuid description: ID of the post this comment belongs to example: "123e4567-e89b-12d3-a456-426614174000" username: type: string description: Username of the comment author minLength: 1 maxLength: 50 example: "naturelover" content: type: string description: Content of the comment minLength: 1 maxLength: 1000 example: "That sounds amazing! Which trail did you take?" createdAt: type: string format: date-time description: Timestamp when the comment was created example: "2025-05-30T15:00:00Z" updatedAt: type: string format: date-time description: Timestamp when the comment was last updated example: "2025-05-30T15:00:00Z" NewPostRequest: type: object required: - username - content properties: username: type: string description: Username of the post author minLength: 1 maxLength: 50 example: "outdoorexplorer" content: type: string description: Content of the post minLength: 1 maxLength: 2000 example: "Just got back from an amazing hiking trip! The views were incredible." UpdatePostRequest: type: object required: - username - content properties: username: type: string description: Username of the post author (for verification) minLength: 1 maxLength: 50 example: "outdoorexplorer" content: type: string description: Updated content of the post minLength: 1 maxLength: 2000 example: "Just got back from an amazing hiking trip! The views were incredible. UPDATE: Added some photos to my profile!" NewCommentRequest: type: object required: - username - content properties: username: type: string description: Username of the comment author minLength: 1 maxLength: 50 example: "naturelover" content: type: string description: Content of the comment minLength: 1 maxLength: 1000 example: "That sounds amazing! Which trail did you take?" UpdateCommentRequest: type: object required: - username - content properties: username: type: string description: Username of the comment author (for verification) minLength: 1 maxLength: 50 example: "naturelover" content: type: string description: Updated content of the comment minLength: 1 maxLength: 1000 example: "That sounds amazing! Which trail did you take? I'm looking for good hiking spots too." LikeRequest: type: object required: - username properties: username: type: string description: Username of the user liking the post minLength: 1 maxLength: 50 example: "adventurefan" UnlikeRequest: type: object required: - username properties: username: type: string description: Username of the user unliking the post minLength: 1 maxLength: 50 example: "adventurefan" LikeResponse: type: object required: - postId - username - createdAt properties: postId: type: string format: uuid description: ID of the liked post example: "123e4567-e89b-12d3-a456-426614174000" username: type: string description: Username of the user who liked the post example: "adventurefan" createdAt: type: string format: date-time description: Timestamp when the like was created example: "2025-05-30T16:00:00Z" Error: type: object required: - error - message properties: error: type: string description: Error type example: "NOT_FOUND" message: type: string description: Human-readable error message example: "The requested post was not found" details: type: string description: Additional error details example: "Post with ID 123e4567-e89b-12d3-a456-426614174000 does not exist" responses: BadRequest: description: Bad request - invalid input data content: application/json: schema: $ref: '#/components/schemas/Error' example: error: "BAD_REQUEST" message: "Invalid input data" details: "Username and content are required fields" NotFound: description: Resource not found content: application/json: schema: $ref: '#/components/schemas/Error' example: error: "NOT_FOUND" message: "The requested resource was not found" details: "Post with the specified ID does not exist" InternalServerError: description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' example: error: "INTERNAL_SERVER_ERROR" message: "An unexpected error occurred" details: "Please try again later or contact support" tags: - name: Posts description: Operations related to posts management - name: Comments description: Operations related to comments management - name: Likes description: Operations related to liking and unliking posts