OpenAPI Specification Design for PKI Manager REST API
Docs for PKI Manager 3.17.0 (released 2026-11-24), from main 4d59c30 (30 commits after the release). Page last changed in 1.2.0.
Source:
backlog/decisions/decision-008 - OpenAPI-Specification-Design-for-PKI-Manager-REST-API.md
Status
Section titled “Status”Proposed | Date: 2025-11-27
Context
Section titled “Context”The PKI Manager currently uses tRPC for type-safe API communication between the React frontend and Fastify backend. While tRPC provides excellent developer experience and type safety within the TypeScript ecosystem, there is a need to expose the API via a standard REST interface with OpenAPI documentation for:
- External integrations - Third-party systems and automation tools
- Non-TypeScript clients - Python scripts, shell scripts, other language SDKs
- API documentation - Self-documenting API for developers
- Testing - Standardized API testing with tools like Postman, curl, and automated integration tests
- Compliance - Industry-standard API specification for audits
Decision
Section titled “Decision”Implement an OpenAPI 3.1 specification alongside the existing tRPC implementation using a parallel REST layer approach. The REST endpoints will be served by Fastify alongside the tRPC routes, sharing the same business logic and validation schemas.
Architecture Approach
Section titled “Architecture Approach”┌─────────────────────────────────────────────────────────────┐│ Fastify Server │├─────────────────────────────────────────────────────────────┤│ /trpc/* │ /api/v1/* ││ (tRPC adapter) │ (REST endpoints) │├─────────────────────────────────────────────────────────────┤│ Shared Business Logic ││ (services/, db/, kms integration) │└─────────────────────────────────────────────────────────────┘OpenAPI Endpoint Design
Section titled “OpenAPI Endpoint Design”Base URL
Section titled “Base URL”/api/v1Resources and Endpoints
Section titled “Resources and Endpoints”Certificate Authorities (CAs)
Section titled “Certificate Authorities (CAs)”| Method | Endpoint | tRPC Equivalent | Description |
|---|---|---|---|
| GET | /cas |
ca.list | List all CAs with filtering |
| POST | /cas |
ca.create | Create a new CA |
| GET | /cas/{id} |
ca.getById | Get CA details |
| POST | /cas/{id}/revoke |
ca.revoke | Revoke a CA |
| DELETE | /cas/{id} |
ca.delete | Delete a CA |
| GET | /cas/{id}/certificates |
certificate.list (filtered) | List certificates issued by CA |
| GET | /cas/{id}/crls |
crl.list | List CRLs for CA |
| POST | /cas/{id}/crls |
crl.generate | Generate new CRL |
Certificates
Section titled “Certificates”| Method | Endpoint | tRPC Equivalent | Description |
|---|---|---|---|
| GET | /certificates |
certificate.list | List all certificates |
| POST | /certificates |
certificate.issue | Issue a new certificate |
| GET | /certificates/{id} |
certificate.getById | Get certificate details |
| POST | /certificates/{id}/renew |
certificate.renew | Renew a certificate |
| POST | /certificates/{id}/revoke |
certificate.revoke | Revoke a certificate |
| DELETE | /certificates/{id} |
certificate.delete | Delete a certificate |
| GET | /certificates/{id}/download |
certificate.download | Download certificate |
Bulk Operations
Section titled “Bulk Operations”| Method | Endpoint | tRPC Equivalent | Description |
|---|---|---|---|
| POST | /certificates/bulk/issue |
certificate.bulkIssue | Bulk issue from CSV |
| POST | /certificates/bulk/revoke |
certificate.bulkRevoke | Bulk revoke certificates |
| POST | /certificates/bulk/renew |
certificate.bulkRenew | Bulk renew certificates |
| DELETE | /certificates/bulk |
certificate.bulkDelete | Bulk delete certificates |
| POST | /certificates/bulk/download |
certificate.bulkDownload | Bulk download certificates |
| Method | Endpoint | tRPC Equivalent | Description |
|---|---|---|---|
| GET | /crls/{id} |
crl.getLatest (by id) | Get CRL by ID |
Search & Discovery
Section titled “Search & Discovery”| Method | Endpoint | tRPC Equivalent | Description |
|---|---|---|---|
| GET | /search |
search.global | Global search |
| GET | /domains |
domain.list | List domains |
Dashboard & Reports
Section titled “Dashboard & Reports”| Method | Endpoint | tRPC Equivalent | Description |
|---|---|---|---|
| GET | /dashboard/stats |
dashboard.stats | Dashboard statistics |
| GET | /dashboard/expiring |
dashboard.expiringSoon | Expiring items |
| GET | /audit |
audit.list | Audit log entries |
| POST | /reports |
audit.generateReport | Generate report |
Request/Response Standards
Section titled “Request/Response Standards”Pagination
Section titled “Pagination”{ "items": [...], "pagination": { "total": 100, "limit": 50, "offset": 0, "hasMore": true }}Error Responses
Section titled “Error Responses”{ "error": { "code": "VALIDATION_ERROR", "message": "Invalid input", "details": [ { "field": "subject.country", "message": "Must be exactly 2 characters" } ] }}Query Parameters for Filtering
Section titled “Query Parameters for Filtering”status- Filter by status (active, revoked, expired)type- Filter by certificate typecaId- Filter by issuing CAsearch- Text searchsortBy- Sort fieldsortOrder- asc/desclimit- Page size (1-100)offset- Page offset
Authentication & Authorization
Section titled “Authentication & Authorization”Initially, the REST API will use the same authentication mechanism as the tRPC endpoints. Future considerations:
- API key authentication for machine-to-machine
- OAuth2/OIDC integration via Keycloak
Implementation Strategy
Section titled “Implementation Strategy”-
Phase 1: Core Infrastructure
- Install
@fastify/swaggerand@fastify/swagger-ui - Configure OpenAPI 3.1 specification
- Set up REST route registration pattern
- Create shared service layer extraction
- Install
-
Phase 2: Resource Endpoints
- Implement CA REST endpoints
- Implement Certificate REST endpoints
- Implement CRL REST endpoints
-
Phase 3: Bulk & Utility Endpoints
- Implement bulk operations
- Implement search/discovery endpoints
- Implement dashboard/audit endpoints
-
Phase 4: Testing & Documentation
- Write integration tests for all endpoints
- Generate OpenAPI specification
- Set up Swagger UI at
/api/docs
Technology Choices
Section titled “Technology Choices”- @fastify/swagger - OpenAPI schema generation from Fastify routes
- @fastify/swagger-ui - Interactive API documentation UI
- zod-to-json-schema - Convert existing Zod schemas to JSON Schema for OpenAPI
- supertest - HTTP integration testing
File Structure
Section titled “File Structure”backend/src/├── rest/│ ├── index.ts # REST plugin registration│ ├── openapi.ts # OpenAPI configuration│ ├── routes/│ │ ├── ca.routes.ts # CA REST routes│ │ ├── certificate.routes.ts│ │ ├── crl.routes.ts│ │ ├── bulk.routes.ts│ │ ├── search.routes.ts│ │ └── audit.routes.ts│ └── schemas/│ └── openapi-schemas.ts # JSON Schema versions of Zod schemas├── services/ # Shared business logic (extracted from procedures)│ ├── ca.service.ts│ ├── certificate.service.ts│ └── crl.service.ts└── tests/ └── rest/ ├── ca.test.ts ├── certificate.test.ts └── bulk.test.tsIntegration Test Design
Section titled “Integration Test Design”Test Categories
Section titled “Test Categories”-
CRUD Operations
- Create, read, update, delete for each resource
- Validation error handling
- Not found error handling
-
Business Logic
- CA revocation cascade
- Certificate renewal chain
- Validity period enforcement
- Type-specific validations
-
Bulk Operations
- CSV parsing and validation
- Partial success handling
- Large batch processing
-
Download Formats
- All 14+ download formats
- Password-protected formats
- Chain building
Test Structure
Section titled “Test Structure”describe('CA REST API', () => { describe('POST /api/v1/cas', () => { it('creates a CA with valid input') it('validates required fields') it('validates country code length') it('validates validity years range') })
describe('GET /api/v1/cas', () => { it('lists CAs with pagination') it('filters by status') it('searches by subject') it('sorts by specified field') })
describe('POST /api/v1/cas/{id}/revoke', () => { it('revokes CA and cascades to certificates') it('generates CRL on revocation') it('rejects already revoked CA') })})Consequences
Section titled “Consequences”Positive
Section titled “Positive”- Industry-standard API documentation
- Enables non-TypeScript integrations
- Better testing infrastructure
- Self-documenting API
- Future-proof for external consumers
Negative
Section titled “Negative”- Additional code to maintain (REST routes alongside tRPC)
- Need to keep REST and tRPC in sync
- Increased surface area for bugs
Mitigations
Section titled “Mitigations”- Extract shared business logic to services
- Use Zod schemas for both REST and tRPC validation
- Comprehensive integration tests ensure parity
References
Section titled “References”PKI Manager is a personal project of Oriol Rius, built for his own use. It is not a commercial product. About this project