REPO: NOVA_Mock_Service
This project serves as a Mock Service for the Nova 2025 Information Integration Tool Collaboration Project, aligning with the design of the "Collaboration Integration Plan (Draft)" to facilitate parallel development and integration testing between frontend, backend, and various teams.
View on GitHub ↗Nova Mock Service User Guide
Directory Structure
contracts/—— OpenAPI contract files (openapi.yaml)samples/—— Golden JSON sample data for each endpointsamples/ndjson/—— NDJSON samples for batch importserver/—— FastAPI mock service codetools/—— Scripts for validation and checks
Quick Start
Method 1: Prism (Recommended, Automatic Contract-Based Mocking)
- Install Node.js.
- Install Prism globally:
npm i -g @stoplight/prism-cli - Start the mock service (in the mock-service directory):
prism mock contracts/openapi.yaml --port 4010 - Access the endpoints:
- http://localhost:4010/api/v1/docs
- http://localhost:4010/api/v1/ai/summary
- ... (All endpoints defined in the contract are accessible)
Method 2: FastAPI Lightweight Mock
- Install Python 3.10+.
- Install dependencies:
pip install fastapi uvicorn pydantic - Start the service (in the mock-service/server directory):
uvicorn server:app --port 4011 - Access the endpoints:
How to Extend
- Add new endpoints:
- Update the
contracts/openapi.yamlfile with new endpoints and schemas. - Add corresponding JSON samples in the
samples/directory. - For the FastAPI method, add routes in
server/server.py.
- Update the
- Add new batch import samples:
- Add NDJSON files in the
samples/ndjson/directory.
- Add NDJSON files in the
Debugging Guide
It is recommended to use Apifox for API debugging and testing.
Steps
- Import OpenAPI Contract:
- Open Apifox, create or select a project.
- Import the
contracts/openapi.yamlfile.
- Validate Endpoints:
- View and test all defined endpoints in Apifox.
- Ensure the API responses match the contract.
- Mock Data Testing:
- Use Apifox's mock functionality to quickly validate API responses.
Apifox enables efficient API debugging and contract validation, improving development and integration efficiency.
Validation and Checks (Repository Scripts)
Some colleagues reported errors during execution (which I didn't notice as it worked fine locally). To improve the robustness of the mock service, I used an LLM to generate a batch of validation scripts. These may be added to CI in the future.
The tools directory contains simple scripts for quickly checking the quality of OpenAPI contracts locally:
-
Check for duplicate mapping keys in YAML (using a strict loader):
python tools/check_dup_yaml.py contracts/openapi.yaml -
Lint the contract using Spectral (requires installation or npx):
# Using npx (no global installation required) npx @stoplight/spectral lint contracts/openapi.yaml --ruleset .spectral.yaml
Notes
- All API response structures, fields, and examples align with the "Collaboration Integration Plan (Draft)".
- The Prism method is recommended for contract-driven development with automatic mocking.
- The FastAPI method is suitable for scenarios requiring custom logic or special responses.
If you encounter issues or need to add endpoints, feel free to supplement samples, contracts, or scripts in this directory and update the main documentation accordingly.