{ "openapi": "3.0.3", "info": { "title": "Letter Service API", "version": "1.0.0", "description": "API for generating, sending, and managing letters." }, "servers": [ { "url": "/" } ], "security": [ { "bearerAuth": [] } ], "paths": { "/health": { "get": { "summary": "Health check", "tags": [ "System" ], "security": [], "responses": { "200": { "description": "Service is healthy", "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string", "example": "ok" }, "uptime": { "type": "number", "example": 123.45 } } } } } }, "500": { "$ref": "#/components/responses/InternalServerError" } } } }, "/letters/{userId}": { "parameters": [ { "name": "userId", "in": "path", "required": true, "description": "Unique identifier of a user.", "schema": { "type": "string", "format": "uuid", "example": "223e4567-e89b-12d3-a456-426614174111" } } ], "get": { "summary": "Get all letters for a user", "description": "Returns all letters belonging to the specified user across all cases.", "tags": [ "Letters" ], "responses": { "200": { "description": "List of letters for the user.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/LetterResource" } } } } }, "401": { "$ref": "#/components/responses/Unauthorized" }, "403": { "$ref": "#/components/responses/Forbidden" }, "404": { "$ref": "#/components/responses/NotFound" }, "500": { "$ref": "#/components/responses/InternalServerError" } } } }, "/letters/{userId}/{caseReferenceNumber}": { "parameters": [ { "name": "userId", "in": "path", "required": true, "description": "Unique identifier of the user.", "schema": { "type": "string", "format": "uuid", "example": "223e4567-e89b-12d3-a456-426614174111" } }, { "name": "caseReferenceNumber", "in": "path", "required": true, "description": "Case reference number.", "schema": { "type": "string", "example": "25-70123" } } ], "get": { "summary": "Get all letters for a case", "description": "Returns all letters for a specific case belonging to a specific user.", "tags": [ "Letters" ], "responses": { "200": { "description": "List of letters for the case.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/LetterResource" } } } } }, "401": { "$ref": "#/components/responses/Unauthorized" }, "403": { "$ref": "#/components/responses/Forbidden" }, "404": { "$ref": "#/components/responses/NotFound" }, "500": { "$ref": "#/components/responses/InternalServerError" } } } }, "/letters/{userId}/{caseReferenceNumber}/{letterId}": { "parameters": [ { "name": "userId", "in": "path", "required": true, "description": "Unique identifier of the user.", "schema": { "type": "string", "format": "uuid", "example": "223e4567-e89b-12d3-a456-426614174111" } }, { "name": "caseReferenceNumber", "in": "path", "required": true, "description": "Case reference number.", "schema": { "type": "string", "example": "25-700123" } }, { "name": "letterId", "in": "path", "required": true, "description": "Unique identifier of the letter.", "schema": { "type": "string", "format": "uuid", "example": "123e4567-e89b-12d3-a456-426614174000" } }, { "name": "format", "in": "query", "required": false, "description": "Response format", "schema": { "type": "string", "enum": [ "json", "template", "pdf" ], "default": "json" } } ], "get": { "summary": "Get a specific letter", "description": "Returns the details of a specific letter for a given user and case. Available as raw json, an interpolated template or a PDF stream.", "tags": [ "Letters" ], "responses": { "200": { "description": "Details of the requested letter.", "content": { "application/json": { "schema": { "oneOf": [ { "$ref": "#/components/schemas/LetterResource" }, { "$ref": "#/components/schemas/TemplateResource" } ] } }, "application/pdf": { "schema": { "type": "string", "format": "binary" } } } }, "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" }, "403": { "$ref": "#/components/responses/Forbidden" }, "404": { "$ref": "#/components/responses/NotFound" }, "500": { "$ref": "#/components/responses/InternalServerError" } } } } }, "components": { "securitySchemes": { "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT" } }, "schemas": { "LetterData": { "type": "object", "description": "Dynamic key-value pairs used to populate the letter template. Required fields will vary depending on letterType.", "additionalProperties": { "type": "string", "example": "Some value" }, "example": { "recipientName": "Mr Test Testcase", "caseReference": "25-700123", "decisionDate": "2024-01-15" } }, "LetterResource": { "type": "object", "description": "Represents a stored letter and its associated metadata.", "properties": { "userId": { "type": "string", "format": "uuid", "description": "Unique identifier of the user who owns the letter.", "example": "223e4567-e89b-12d3-a456-426614174111" }, "caseReferenceNumber": { "type": "string", "description": "Reference number of the case to which the letter belongs.", "example": "25-700123" }, "letterId": { "type": "string", "format": "uuid", "description": "Unique identifier of the letter.", "example": "123e4567-e89b-12d3-a456-426614174000" }, "letterType": { "type": "string", "description": "Code that identifies which letter template was used.", "example": "AA01" }, "letterData": { "$ref": "#/components/schemas/LetterData" } }, "required": [ "userId", "caseReferenceNumber", "letterId", "letterType", "letterData" ] }, "TemplateResource": { "description": "Represents a stored letter, its associated metadata and the interpolated template instance", "allOf": [ { "$ref": "#/components/schemas/LetterResource" }, { "type": "object", "properties": { "templateInstance": { "type": "object", "description": "Interpolated/derived values produced by applying the template.", "additionalProperties": true } }, "required": ["templateInstance"] } ] }, "ErrorObject": { "type": "object", "properties": { "status": { "type": "integer", "example": 401 }, "title": { "type": "string", "example": "401 Unauthorized" }, "detail": { "type": "string", "example": "No authorization token was found" } }, "required": ["status", "title", "detail"], "additionalProperties": false }, "ErrorResponse": { "type": "object", "properties": { "errors": { "type": "array", "items": { "$ref": "#/components/schemas/ErrorObject" } } }, "required": ["errors"], "additionalProperties": false } }, "responses": { "BadRequest": { "description": "There is an issue with the request", "content": { "application/vnd.api+json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "Unauthorized": { "description": "Access token is missing or invalid", "content": { "application/vnd.api+json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "Forbidden": { "description": "The JWT doesn't permit access to this endpoint", "content": { "application/vnd.api+json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "NotFound": { "description": "The specified resource was not found", "content": { "application/vnd.api+json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "InternalServerError": { "description": "Unexpected server error.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } } } } }