OpenAPI Specification Generation Guide
This guide provides instructions on how to generate OpenAPI specifications for the MOOD MNKY API services and integrate them with our documentation system.Overview
OpenAPI specifications (formerly known as Swagger specifications) provide a standardized way to describe RESTful APIs. For the MOOD MNKY ecosystem, we use OpenAPI specifications to:- Document API endpoints, parameters, and responses
- Provide interactive API testing through Swagger UI
- Enable automatic client library generation
- Ensure API consistency across services
- Power our API playground in the documentation
Prerequisites
To work with OpenAPI specifications, you’ll need:- Node.js 18+ installed
- Basic understanding of REST APIs
- Access to the service repositories
- Development environment set up for each service
Understanding OpenAPI in Our Ecosystem
MOOD MNKY uses OpenAPI 3.0 specifications for all API services. Each service (Ollama, Flowise, Langchain, and n8n) maintains its own OpenAPI specification, which is then integrated into our documentation system.File Locations
The OpenAPI specifications are stored in the following locations:Generating OpenAPI Specifications
Each service has a different process for generating OpenAPI specifications:Ollama
Ollama uses a manual approach to create and maintain the OpenAPI specification:-
Navigate to the Ollama service directory:
-
Install the required packages:
-
Run the generation script:
-
The generated specification will be available at
dist/openapi.yaml -
Copy the generated file to the documentation:
Flowise
Flowise has built-in OpenAPI generation:-
Navigate to the Flowise service directory:
-
Start the Flowise service:
-
Access the OpenAPI specification at:
-
Save this file to the documentation:
Langchain
Langchain uses FastAPI’s automatic OpenAPI generation:-
Navigate to the Langchain service directory:
-
Start the Langchain service:
-
Access the OpenAPI specification at:
-
Convert the JSON to YAML format and save it:
n8n
For n8n, we need to extract the OpenAPI specification:-
Navigate to the n8n service directory:
-
Start the n8n service:
-
Access the OpenAPI specification at:
-
Convert the JSON to YAML format and save it:
Customizing OpenAPI Specifications
After generating the base specifications, you may need to customize them for better documentation:Adding Server Information
Ensure each specification includes both development and production servers:Enhancing Descriptions
Improve endpoint descriptions to provide more context:Adding Examples
Include request and response examples for key endpoints:Security Definitions
Add security schemes for authentication:Validating OpenAPI Specifications
Before integrating specifications into documentation, validate them:-
Install the validator:
-
Validate a specification:
- Fix any validation errors before proceeding
Integrating with Documentation
Once your OpenAPI specifications are ready, integrate them with our Mintlify documentation:- Update the
docs.jsonconfiguration to reference the OpenAPI specifications:
- Ensure the API playground can access the specifications:
Automating Specification Updates
Set up automation to keep OpenAPI specifications up-to-date:- Create a script to fetch and update all specifications:
- Add an npm script to run the update:
- Run the update script:
Best Practices
- Keep Specifications in Sync: Update OpenAPI specs whenever API changes occur.
- Version Control: Commit OpenAPI specs to version control to track changes.
- Maintain Consistency: Use similar terminology and patterns across all service specifications.
- Include Authentication: Always document authentication requirements for each endpoint.
- Add Examples: Provide realistic examples for request bodies and responses.
- Document Error Responses: Include potential error responses with status codes and descriptions.
- Use Tags: Organize endpoints using tags for better navigation.
Generating Client Libraries
You can generate client libraries from OpenAPI specifications:-
Install the OpenAPI Generator:
-
Generate a TypeScript client for Ollama:
-
Generate a Python client for Langchain:
Additional Resources
- OpenAPI Specification - The official OpenAPI specification
- Swagger Editor - Online editor for OpenAPI specs
- OpenAPI Generator - For generating client libraries
- Swagger UI Guide - How to use our Swagger UI interfaces
- Mintlify OpenAPI Documentation - Integrating OpenAPI with Mintlify