This commit is contained in:
74
README.md
74
README.md
@@ -1,17 +1,13 @@
|
||||
# JSON to OpenAPI Generator
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
A Python CLI tool that analyzes JSON data files and automatically generates valid OpenAPI 3.0 specification files. It infers data types, detects nested structures, and produces specs ready for Swagger UI, ReDoc, and code generators.
|
||||
A Python CLI tool that analyzes JSON data files and automatically generates valid OpenAPI 3.0 specification files. It infers data types, detects nested structures, and produces specs ready for Swagger UI and code generators.
|
||||
|
||||
## Features
|
||||
|
||||
- **Automatic Type Inference**: Infers OpenAPI schema types (string, number, integer, boolean, null, array, object) from JSON data
|
||||
- **Nested Object Detection**: Recursively detects nested objects and arrays to build complete schema trees
|
||||
- **Format Detection**: Automatically detects date, datetime, email, URI, UUID, and byte formats
|
||||
- **Batch Processing**: Process multiple JSON files in a single command with parallel processing support
|
||||
- **Batch Processing**: Process multiple JSON files in a single command
|
||||
- **Interactive Customization**: Interactive CLI prompts to customize endpoint names, paths, HTTP methods, and descriptions
|
||||
- **OpenAPI 3.0 Output**: Generates valid OpenAPI 3.0 YAML/JSON output compatible with Swagger UI, ReDoc, and code generators
|
||||
- **Validation**: Built-in validation of generated OpenAPI specs
|
||||
@@ -30,12 +26,6 @@ pip install -e .
|
||||
pip install json-to-openapi
|
||||
```
|
||||
|
||||
### Development Installation
|
||||
|
||||
```bash
|
||||
pip install -e ".[dev]"
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Conversion
|
||||
@@ -123,7 +113,7 @@ json-to-openapi validate openapi.yaml
|
||||
|
||||
### Simple Object
|
||||
|
||||
**Input JSON:**
|
||||
Input JSON:
|
||||
```json
|
||||
{
|
||||
"name": "John",
|
||||
@@ -132,7 +122,7 @@ json-to-openapi validate openapi.yaml
|
||||
}
|
||||
```
|
||||
|
||||
**Generated OpenAPI:**
|
||||
Generated OpenAPI:
|
||||
```yaml
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
@@ -161,7 +151,7 @@ paths:
|
||||
|
||||
### Nested Structure
|
||||
|
||||
**Input JSON:**
|
||||
Input JSON:
|
||||
```json
|
||||
{
|
||||
"user": {
|
||||
@@ -174,11 +164,9 @@ paths:
|
||||
}
|
||||
```
|
||||
|
||||
The tool automatically detects nested objects and creates the appropriate schema with properties.
|
||||
|
||||
### Array with Objects
|
||||
|
||||
**Input JSON:**
|
||||
Input JSON:
|
||||
```json
|
||||
{
|
||||
"users": [
|
||||
@@ -188,8 +176,6 @@ The tool automatically detects nested objects and creates the appropriate schema
|
||||
}
|
||||
```
|
||||
|
||||
The tool merges array object properties and generates comprehensive array item schemas.
|
||||
|
||||
## API Reference
|
||||
|
||||
### Python API
|
||||
@@ -226,10 +212,8 @@ The analyzer automatically detects:
|
||||
- **String Formats**: date, date-time, email, uri, uuid, byte
|
||||
- **Complex Types**: objects with properties, arrays with items
|
||||
- **Required Fields**: All object properties are marked as required
|
||||
- **Integer Formats**: int32 for standard integers, int64 for large integers
|
||||
- **Number Formats**: double for floating-point numbers
|
||||
|
||||
### Error Handling
|
||||
## Error Handling
|
||||
|
||||
The tool handles common errors gracefully:
|
||||
|
||||
@@ -246,50 +230,12 @@ The tool handles common errors gracefully:
|
||||
pytest tests/ -v
|
||||
```
|
||||
|
||||
### Test Coverage
|
||||
### Installing Development Dependencies
|
||||
|
||||
```bash
|
||||
pytest tests/ --cov=json_to_openapi --cov-report=html
|
||||
pip install -e ".[dev]"
|
||||
```
|
||||
|
||||
### Code Quality
|
||||
|
||||
```bash
|
||||
ruff check .
|
||||
mypy .
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
json-to-openapi/
|
||||
├── json_to_openapi/
|
||||
│ ├── __init__.py # Package initialization
|
||||
│ ├── analyzer.py # JSON type inference and analysis
|
||||
│ ├── cli.py # CLI interface
|
||||
│ └── schema_generator.py # OpenAPI schema generation
|
||||
├── tests/
|
||||
│ ├── __init__.py
|
||||
│ ├── conftest.py # Pytest fixtures
|
||||
│ ├── test_analyzer.py # Type inference tests
|
||||
│ ├── test_schema_generator.py # Schema generation tests
|
||||
│ ├── test_cli.py # CLI tests
|
||||
│ └── test_integration.py # Integration tests
|
||||
├── examples/
|
||||
│ ├── users.json # Example user data
|
||||
│ └── products.json # Example product data
|
||||
├── .python-version
|
||||
├── requirements.txt
|
||||
├── setup.py
|
||||
├── setup.cfg
|
||||
├── pyproject.toml
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
MIT License
|
||||
|
||||
Reference in New Issue
Block a user