openapi: 3.0.1 info: title: Simple Social Media Application 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: Product Owner / Tech Lead at Contoso 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 for browsing operationId: listPosts 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 with others operationId: createPost tags: - Posts requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/CreatePostRequest' 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}: parameters: - $ref: '#/components/parameters/PostId' get: summary: Get a specific post description: Retrieve a specific post by its ID operationId: getPost tags: - Posts responses: '200': description: Successfully retrieved 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 content operationId: updatePost tags: - Posts 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 specific post operationId: deletePost tags: - Posts responses: '204': description: Post deleted successfully '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' /posts/{postId}/comments: parameters: - $ref: '#/components/parameters/PostId' get: summary: List comments for a post description: Retrieve all comments for a specific post operationId: listComments tags: - Comments 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 new comment to a post operationId: createComment tags: - Comments requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/CreateCommentRequest' 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}: parameters: - $ref: '#/components/parameters/PostId' - $ref: '#/components/parameters/CommentId' get: summary: Get a specific comment description: Retrieve a specific comment by its ID operationId: getComment tags: - Comments responses: '200': description: Successfully retrieved 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 operationId: updateComment tags: - Comments 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 specific comment operationId: deleteComment tags: - Comments responses: '204': description: Comment deleted successfully '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' /posts/{postId}/likes: parameters: - $ref: '#/components/parameters/PostId' post: summary: Like a post description: Add a like to a specific post operationId: likePost tags: - Likes 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 a like from a specific post operationId: unlikePost tags: - Likes parameters: - name: username in: query required: true description: Username of the user removing the like schema: type: string minLength: 1 maxLength: 50 responses: '204': description: Post unliked successfully '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalServerError' components: parameters: PostId: name: postId in: path required: true description: Unique identifier for a post schema: type: string format: uuid CommentId: name: commentId in: path required: true description: Unique identifier for a comment schema: type: string format: uuid 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: 1000 description: Content of the post example: "Just had an amazing hiking experience with Contoso gear!" createdAt: type: string format: date-time description: Timestamp when the post was created example: "2025-05-30T10:30:00Z" updatedAt: type: string format: date-time description: Timestamp when the post was last updated example: "2025-05-30T10: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: "456e7890-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 minLength: 1 maxLength: 50 description: Username of the comment author example: "jane_smith" content: type: string minLength: 1 maxLength: 500 description: Content of the comment example: "Great post! I love their outdoor equipment too." createdAt: type: string format: date-time description: Timestamp when the comment was created example: "2025-05-30T11:15:00Z" updatedAt: type: string format: date-time description: Timestamp when the comment was last updated example: "2025-05-30T11:15:00Z" CreatePostRequest: 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: 1000 description: Content of the post example: "Just had an amazing hiking experience with Contoso gear!" 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: 1000 description: Updated content of the post example: "Just had an amazing hiking experience with Contoso gear! Highly recommend their backpacks." CreateCommentRequest: 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: 500 description: Content of the comment example: "Great post! I love their outdoor equipment too." 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: 500 description: Updated content of the comment example: "Great post! I love their outdoor equipment too. Where did you buy it?" 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 of the user who liked the post example: "mike_wilson" likedAt: type: string format: date-time description: Timestamp when the like was added example: "2025-05-30T12:00:00Z" ErrorResponse: type: object required: - error - message properties: error: type: string description: Error type example: "BadRequest" message: type: string description: Human-readable error message example: "The request is invalid or missing required fields" details: type: object description: Additional error details additionalProperties: true responses: BadRequest: description: Bad request - Invalid input or missing required fields content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' example: error: "BadRequest" message: "The request is invalid or missing required fields" details: field: "username" issue: "Username is required and cannot be empty" NotFound: description: Resource not found content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' example: error: "NotFound" message: "The requested resource was not found" InternalServerError: description: Internal server error content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' example: error: "InternalServerError" message: "An unexpected error occurred while processing the request" tags: - name: Posts description: Operations related to post management - name: Comments description: Operations related to comment management - name: Likes description: Operations related to post likes