Swagger Validator App#
Project Overview##
This is a Python web application built using Streamlit that provides validation and conversion tools for Swagger (OpenAPI) specifications.
Core Functionality##
The application serves as a comprehensive tool for working with Swagger/OpenAPI specifications with the following primary features:
1. Swagger Specification Validation###
- Validates OpenAPI specifications against official OpenAPI standards
- Uses the
prancelibrary for parsing andopenapi-spec-validatorfor validation - Provides detailed error messages when validation fails
- Displays human-readable validation error summaries
2. Format Conversion###
- Converts JSON format specifications to YAML format
- Converts YAML format specifications to JSON format
- Provides download functionality for converted files
- Maintains proper formatting and structure during conversion
3. Multiple Input Methods###
- Paste Method: Direct text input via text area for copying/pasting specifications
- File Upload: Supports uploading .json, .yaml, and .yml files
- URL Fetch: Retrieves specifications directly from web URLs using HTTP requests
4. Swagger UI Integration###
- Embeds interactive Swagger UI for valid specifications
- Renders specifications in a scrollable, 800-pixel height container
- Uses official Swagger UI CSS and JavaScript libraries from CDN
- Provides full interactive API documentation experience
Technical Architecture##
Dependencies (requirements.txt)###
- streamlit==1.14.0: Web application framework for the user interface
- requests==2.25.1: HTTP library for fetching specifications from URLs
- PyYAML==5.4.1: YAML parsing and serialization
- prance==0.19.0: OpenAPI specification parsing and resolution
- openapi-spec-validator==0.3.1: Official OpenAPI specification validation
Application Structure###
The application follows a single-file architecture with the main application logic in swagger-validator.py.
Key Components###
Configuration
- Wide layout configuration for better screen utilization
- Expanded sidebar by default
- Custom CSS to hide Streamlit's default menu, footer, and header for cleaner appearance
State Management
- Uses Streamlit's session state to maintain validation history
- Stores validation actions, specifications, and results across user interactions
- Implements persistent history that survives page interactions
User Interface Elements
- Main Page: Primary validation and conversion interface
- About Page: Information about the application and its features
- Sidebar Navigation: Page selection and history display
- History Panel: Expandable entries showing previous validation actions
Error Handling
- Comprehensive error parsing for validation failures
- JSON and YAML syntax error handling
- HTTP request error handling for URL fetching
- Detailed error messages with validation context
File Processing
- Automatic format detection (JSON vs YAML based on content structure)
- UTF-8 encoding for file uploads
- Support for multiple file extensions (.json, .yaml, .yml)
Application Workflow##
Validation Process###
- User selects input method (paste, upload, or URL)
- Application receives and processes the specification
- Format detection determines if input is JSON or YAML
- Specification is parsed and validated against OpenAPI standards
- Results are displayed with either success message and Swagger UI or detailed error information
- Action and result are saved to session history
Conversion Process###
- User provides specification in either JSON or YAML format
- Application detects source format
- Converts to target format while preserving structure and data
- Provides download button for converted file
- Displays converted content with syntax highlighting
- Saves conversion action to history
User Experience Features##
Visual Elements###
- Syntax highlighting for code display
- Responsive layout with wide configuration
- Clean interface with hidden Streamlit branding
- Organized sidebar with clear navigation
Interactive Elements###
- Multiple input methods for flexibility
- Immediate validation feedback
- Download buttons for converted files
- Expandable history entries
- Scrollable Swagger UI integration
Session Persistence###
- Maintains history of all validation and conversion actions
- Stores specifications and results for reference
- Allows users to review previous work within the session
Creator Information##
The application is created by Mrutyunjay Patil (email: patilmrutyunjay2@gmail.com)
File Structure##
The project consists of:
swagger-validator.py: Main application file containing all functionalityrequirements.txt: Python dependency specifications
Architecture Diagram
Drag to pan, scroll to zoom