diff --git a/app/main.py b/app/main.py index 3779b1d..14b333b 100644 --- a/app/main.py +++ b/app/main.py @@ -21,6 +21,7 @@ class UserCreate(BaseModel): """Request body for creating a new user.""" name: str = Field(..., description="Full name of the user") email: str = Field(..., description="Email address") + role: str = Field("member", description="User role") class User(BaseModel): @@ -28,6 +29,7 @@ class User(BaseModel): id: int = Field(..., description="Unique user identifier") name: str = Field(..., description="Full name of the user") email: str = Field(..., description="Email address") + role: str = Field("member", description="User role") class HealthResponse(BaseModel): @@ -92,7 +94,7 @@ def get_user(user_id: int) -> User: def create_user(body: UserCreate) -> User: """Create a new user and return the created resource.""" global _next_id - user = User(id=_next_id, name=body.name, email=body.email) + user = User(id=_next_id, name=body.name, email=body.email, role=body.role) _users_db[_next_id] = user _next_id += 1 return user diff --git a/artifacts/openapi_baseline.json b/artifacts/openapi_baseline.json new file mode 100644 index 0000000..b738e51 --- /dev/null +++ b/artifacts/openapi_baseline.json @@ -0,0 +1,298 @@ +{ + "components": { + "schemas": { + "HTTPValidationError": { + "properties": { + "detail": { + "items": { + "$ref": "#/components/schemas/ValidationError" + }, + "title": "Detail", + "type": "array" + } + }, + "title": "HTTPValidationError", + "type": "object" + }, + "HealthResponse": { + "description": "Health-check response.", + "properties": { + "status": { + "description": "Service status", + "examples": [ + "ok" + ], + "title": "Status", + "type": "string" + } + }, + "required": [ + "status" + ], + "title": "HealthResponse", + "type": "object" + }, + "User": { + "description": "Representation of a user returned by the API.", + "properties": { + "email": { + "description": "Email address", + "title": "Email", + "type": "string" + }, + "id": { + "description": "Unique user identifier", + "title": "Id", + "type": "integer" + }, + "name": { + "description": "Full name of the user", + "title": "Name", + "type": "string" + }, + "role": { + "default": "member", + "description": "User role", + "title": "Role", + "type": "string" + } + }, + "required": [ + "id", + "name", + "email" + ], + "title": "User", + "type": "object" + }, + "UserCreate": { + "description": "Request body for creating a new user.", + "properties": { + "email": { + "description": "Email address", + "title": "Email", + "type": "string" + }, + "name": { + "description": "Full name of the user", + "title": "Name", + "type": "string" + }, + "role": { + "default": "member", + "description": "User role", + "title": "Role", + "type": "string" + } + }, + "required": [ + "name", + "email" + ], + "title": "UserCreate", + "type": "object" + }, + "ValidationError": { + "properties": { + "ctx": { + "title": "Context", + "type": "object" + }, + "input": { + "title": "Input" + }, + "loc": { + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "title": "Location", + "type": "array" + }, + "msg": { + "title": "Message", + "type": "string" + }, + "type": { + "title": "Error Type", + "type": "string" + } + }, + "required": [ + "loc", + "msg", + "type" + ], + "title": "ValidationError", + "type": "object" + } + } + }, + "info": { + "description": "A minimal enterprise API used to demonstrate Docs Drift Guard.", + "title": "Enterprise User API", + "version": "1.0.0" + }, + "openapi": "3.1.0", + "paths": { + "/health": { + "get": { + "description": "Return the current health status of the service.", + "operationId": "health_check_health_get", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HealthResponse" + } + } + }, + "description": "Successful Response" + } + }, + "summary": "Health check", + "tags": [ + "health" + ] + } + }, + "/v1/audit": { + "delete": { + "description": "Clear all recorded mismatches.", + "operationId": "clear_audit_log_v1_audit_delete", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "additionalProperties": true, + "title": "Response Clear Audit Log V1 Audit Delete", + "type": "object" + } + } + }, + "description": "Successful Response" + } + }, + "summary": "Clear the audit log", + "tags": [ + "audit" + ] + }, + "get": { + "description": "Return all API call mismatches recorded by the middleware.\nUseful for identifying clients that are using stale field names\nor calling endpoints that don't exist.", + "operationId": "get_audit_log_v1_audit_get", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "additionalProperties": true, + "title": "Response Get Audit Log V1 Audit Get", + "type": "object" + } + } + }, + "description": "Successful Response" + } + }, + "summary": "View API call mismatch audit log", + "tags": [ + "audit" + ] + } + }, + "/v1/users": { + "post": { + "description": "Create a new user and return the created resource.", + "operationId": "create_user_v1_users_post", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UserCreate" + } + } + }, + "required": true + }, + "responses": { + "201": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + }, + "description": "Successful Response" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "summary": "Create a new user", + "tags": [ + "users" + ] + } + }, + "/v1/users/{user_id}": { + "get": { + "description": "Retrieve a single user by their unique ID.", + "operationId": "get_user_v1_users__user_id__get", + "parameters": [ + { + "in": "path", + "name": "user_id", + "required": true, + "schema": { + "title": "User Id", + "type": "integer" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + }, + "description": "Successful Response" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "summary": "Get a user by ID", + "tags": [ + "users" + ] + } + } + } +} diff --git a/docs/api_reference.md b/docs/api_reference.md index 8f48f0c..21cdd4b 100644 --- a/docs/api_reference.md +++ b/docs/api_reference.md @@ -1,6 +1,163 @@ -# API Reference +# Enterprise User API – API Reference -> This file is **auto-generated** by `drift_guard`. -> Run `python -m drift_guard.guard baseline` to regenerate. +> **Version:** 1.0.0 -_No baseline generated yet. Run the baseline command to populate this file._ +A minimal enterprise API used to demonstrate Docs Drift Guard. + +--- + +## Endpoints Overview + +| Method | Path | Summary | +|--------|------|---------| +| GET | `/health` | Health check | +| DELETE | `/v1/audit` | Clear the audit log | +| GET | `/v1/audit` | View API call mismatch audit log | +| POST | `/v1/users` | Create a new user | +| GET | `/v1/users/{user_id}` | Get a user by ID | + +--- + +## GET `/health` + +**Health check** + +### Response `200` + +Successful Response + +| Field | Type | Required | Description | +|-------|------|----------|-------------| +| `status` | string | Yes | Service status | + + +### Example + +```bash +curl -s "http://localhost:8000/health" | python -m json.tool +``` + +--- + +## DELETE `/v1/audit` + +**Clear the audit log** + +### Response `200` + +Successful Response + +_No properties defined._ + + +### Example + +```bash +curl -s -X DELETE "http://localhost:8000/v1/audit" | python -m json.tool +``` + +--- + +## GET `/v1/audit` + +**View API call mismatch audit log** + +### Response `200` + +Successful Response + +_No properties defined._ + + +### Example + +```bash +curl -s "http://localhost:8000/v1/audit" | python -m json.tool +``` + +--- + +## POST `/v1/users` + +**Create a new user** + +### Request Body + +| Field | Type | Required | Description | +|-------|------|----------|-------------| +| `email` | string | Yes | Email address | +| `name` | string | Yes | Full name of the user | +| `role` | string | No | User role | + + +### Response `201` + +Successful Response + +| Field | Type | Required | Description | +|-------|------|----------|-------------| +| `email` | string | Yes | Email address | +| `id` | integer | Yes | Unique user identifier | +| `name` | string | Yes | Full name of the user | +| `role` | string | No | User role | + + +### Response `422` + +Validation Error + +| Field | Type | Required | Description | +|-------|------|----------|-------------| +| `detail` | array | No | | + + +### Example + +```bash +curl -s -X POST "http://localhost:8000/v1/users" \ + -H "Content-Type: application/json" \ + -d '{"email": "example_email", "name": "example_name", "role": "example_role"}' | python -m json.tool +``` + +--- + +## GET `/v1/users/{user_id}` + +**Get a user by ID** + +### Parameters + +| Name | In | Type | Required | Description | +|------|----|------|----------|-------------| +| `user_id` | path | integer | Yes | | + +### Response `200` + +Successful Response + +| Field | Type | Required | Description | +|-------|------|----------|-------------| +| `email` | string | Yes | Email address | +| `id` | integer | Yes | Unique user identifier | +| `name` | string | Yes | Full name of the user | +| `role` | string | No | User role | + + +### Response `422` + +Validation Error + +| Field | Type | Required | Description | +|-------|------|----------|-------------| +| `detail` | array | No | | + + +### Example + +```bash +curl -s "http://localhost:8000/v1/users/1" | python -m json.tool +``` + +--- + +_This file was auto-generated by [Docs Drift Guard](../drift_guard/guard.py). Do not edit manually._