vega-contract
v0.0.1
Published
OpenAPI Contract Management and Validation
Downloads
6
Readme
Contract API Management and Validation
This project provides a comprehensive toolkit for managing and validating API contracts using the OpenAPI specification. The repository is structured to support microservices and tag-based organization for optimal Java interface generation.
Start here: Vega Contract-First Experience Guide — https://vegainvestments.atlassian.net/wiki/x/EQByVg
Quick Links
Documentation
- Swagger UI (requires authentication)
- Redocly Documentation
- Vacuum Changes Report
- Vacuum Quality Report
Installation
- Clone the repository:
git clone https://github.com/vegainvestments/contract - Navigate to the project directory:
cd contract - Install Node.js
- Set up Yarn Berry:
corepack enable yarn set version berry - Install dependencies:
yarn install
Repository Structure
contract/
├── entry/ # Source OpenAPI specs (author here)
│ ├── components/ # Shared components across all services
│ │ ├── UUID.yaml
│ │ ├── DateTime.yaml
│ │ ├── TimeFrame.yaml
│ │ └── ...
│ ├── <service>/
│ │ ├── index.yaml # Service root (servers, security, tags, path $refs)
│ │ ├── paths/ # Per-tag path files (operations live here)
│ │ │ └── v1/<tag>.yaml
│ │ └── models/ # Per-file models (requests, responses, types, enums)
│ │ └── v1/{requests|responses|types|enums}/*.yaml
├── bundled/ # Generated per-service bundles (DO NOT EDIT)
│ ├── analytics.yaml
│ ├── authentication.yaml
│ └── ...
├── bundled.yaml # Generated joined spec (all services)
└── package.json # Scripts and dependenciesKey Features
- Direct model references: Path files reference models directly (no
models/schemas.yamlindex) - No custom scripts: Uses industry-standard tools (Redocly, Vacuum)
- IntelliJ compatible: Relative
$refpaths resolve cleanly in IDEs - Microservice architecture: Clear separation by service under
entry/
Development Workflow
1. Edit API Definitions
Edit files in the appropriate location:
- Shared components:
entry/components/ - Service endpoints:
entry/<service>/paths/**.yaml - Service models:
entry/<service>/models/**.yaml
Notes:
- In path files, reference models directly, for example:
- Instead of
$ref: '../../index.yaml#/components/schemas/DealResponse' - Use
$ref: ../../models/v1/responses/DealResponse.yaml
- Instead of
- The legacy
models/schemas.yamlaggregator has been removed.
2. Validate Your Changes
# Run all linters
yarn lint
# Run Redocly linting only
yarn lint:redocly3. Bundle APIs
# Bundle all services and create merged specification (writes to bundled/* and bundled.yaml)
yarn bundle4. Test the Bundle
# Run quality checks on bundled specifications
yarn test:bundle5. View Documentation
# Open Swagger UI
yarn swagger
# Generate and view Redocly documentation
yarn docs
# View quality report
yarn report:qualityAvailable Scripts
Linting and Validation
yarn lint- Run all linters (ESLint, Redocly)yarn lint:eslint- Run ESLint on YAML filesyarn lint:redocly- Run Redocly OpenAPI linting
Building and Bundling
yarn bundle- Bundle all services and merge into single specyarn bundle:services- Bundle individual services onlyyarn bundle:merge- Merge bundled services using Redocly join
Testing and Reporting
yarn test:bundle- Validate bundled specificationsyarn report:quality- Generate and view Vacuum quality reportyarn report:diff- Show changes in API specification
Documentation
yarn swagger- View API in Swagger UIyarn docs- Generate and view Redocly documentation
Utilities
yarn precommit- Run before committing (lint, bundle, test, stage bundled)
Adding New Endpoints
Identify the service and tag
- Service: e.g.,
coinvest-deal - Tag: e.g.,
deal-opportunity
- Service: e.g.,
Edit the paths file
# Edit api/coinvest-deal/tags/deal-opportunity/paths.yamlAdd your endpoint
paths: /api/coinvest-deals/v1/deal-opportunities: post: summary: Create deal opportunity tags: - deal-opportunity # ... rest of operationAdd schemas if needed
- Request schemas:
api/coinvest-deal/components/schemas/ - Response schemas:
api/coinvest-deal/components/responses/
- Request schemas:
Reference shared components
parameters: - $ref: '../../../components/UUID.yaml'
Java Interface Generation
The tag-based structure maps directly to Java interfaces:
- Each tag becomes a Java interface
- Operations under a tag become methods in that interface
- Clean separation enables better code generation
Pre-commit Process
The repository uses Husky for pre-commit checks:
yarn precommit # Runs linting, bundling, testing, and stages generated filesTools Used
- @redocly/cli - Documentation and additional validation
- openapi-merge-cli - Merging multiple OpenAPI files
- @quobix/vacuum - Quality reporting
- @pb33f/openapi-changes - Change detection
Migration Notes
- All
$refusages now use double-quoted values and target direct file references underentry/<service>/models/**/{Name}.yaml. - The legacy flat
entry/*.yamlservice files have been replaced with per-service folders underentry/<service>/withindex.yaml,paths/, andmodels/. - When adding new models, create a new file under the appropriate folder and reference it directly from paths or other models.
Best Practices
- One Tag Per Directory - Keep operations organized by their tag
- Reuse Components - Use shared components from
api/components/ - Validate Often - Run
yarn lintfrequently during development - Clear Descriptions - Document all operations and schemas
- Consistent Naming - Follow the naming conventions enforced by linting
Troubleshooting
IntelliJ Not Resolving References
- Ensure you're using relative paths starting with
./or../ - Install the OpenAPI plugin for IntelliJ
- Work under the
entry/directory; references should resolve without additional configuration
Bundle Errors
- Ensure all
$refpaths are correct - Check that referenced files exist
- Run individual service bundles to isolate issues
