This folder contains a simple API for mocking data related to power stations and reporting. The API is designed to provide dynamic mock data and can be easily wired towards a real API in the future.
Before you can run the mock API, make sure you have Node.js installed.
- Install dependencies:
npm install- Start the mock server with type generation:
npm run mockThe mock command runs the following steps in sequence:
npm run generate:apinpm run combine-yaml- Combines component YAML files into a single OpenAPI specorval --config ./orval.config.ts- Generates TypeScript types from the spec
npm run test:types- Validates TypeScript typesprism mock openapi.combined.yaml -d- Starts the mock server with dynamic data
npm run mock- Full sequence: generate types, validate, and start mock servernpm run generate:api- Combines YAML and generates TypeScript typesnpm run combine-yaml- Only combines component YAML filesnpm run test:types- Validates TypeScript types
.
├── components/ # OpenAPI component schemas
├── scripts/ # Build and development scripts
├── src/
│ └── api/ # Generated API types and client
├── openapi.yaml # Main OpenAPI specification
└── openapi.combined.yaml # Generated combined specification
The mock server uses Prism to provide dynamic responses based on the OpenAPI specification. When running, it will:
- Validate requests against the schema
- Generate dynamic response data
- Support all defined endpoints with example data
The server runs on http://localhost:4010 by default.
The project uses Orval to generate TypeScript types and a React Query client from the OpenAPI specification. Generated files are placed in src/api/generated/.
See https://v6.fakerjs.dev/guide/ for allowed methods for data generation in the OpenAPI schemas.
- Modify OpenAPI schemas in
components/or the main spec inopenapi.yaml - Run
npm run mockto regenerate types and start the server - The mock server will automatically use the updated specification
When adding new endpoints or modifying existing ones:
- Update the relevant component schemas in
components/ - Update the paths in
openapi.yaml - Run
npm run mockto validate and test changes
[Add your license information here]