Refactor Example Generation with Improved Type Handling and Unit Tests#5
Merged
rahulkaushal04 merged 13 commits intomainfrom May 9, 2025
Merged
Refactor Example Generation with Improved Type Handling and Unit Tests#5rahulkaushal04 merged 13 commits intomainfrom
rahulkaushal04 merged 13 commits intomainfrom
Conversation
…y to utilize it - Introduced generate_test_value function for generating test values based on regex patterns and length constraints. - Removed the previous implementation of generate_test_value from parameter.py. - Updated test cases to reflect the new behavior of returning "example" for invalid patterns.
…ance RequestBody with example generation functionality - Updated type hints in `body.py`, `endpoint.py`, `parameter.py`, `base_parser.py`, and `openapi_parser.py` to use built-in `dict` and `list` instead of `Dict` and `List`. - Added `__post_init__` method in `RequestBody` to generate example values if not provided. - Implemented helper functions for generating example JSON bodies and properties based on schema definitions.
…signatures and add support for object properties - Updated `generate_json_example` to accept only properties, removing the resolved schema parameter. - Introduced `generate_object_property` to handle object type properties in example generation. - Enhanced example generation logic to include object properties based on schema definitions.
…l property types and improve structure - Introduced a handler for different content types in `generate_example_body`. - Added `generate_property_value` to streamline property value generation for various types. - Enhanced `generate_object_property` to handle `additionalProperties` in schemas. - Implemented `generate_array_property` to support array types in example generation.
- Updated the return type of `generate_test_value` to always return a string instead of an optional type. - Enhanced the `generate_string_property` function to provide a default format value of "none" when no format is specified in the schema.
- Removed the API Reference link from the README. - Simplified the security workflow by removing pip-audit and adjusting the Bandit scan configuration. - Added detailed API reference documentation for the Parser module, including usage examples and method descriptions.
- Added .vscode and *.ipynb to .gitignore for better file management. - Created MANIFEST.in to include requirements.txt and VERSION in the package distribution. - Removed commented-out code in OpenAPIParser for improved readability and clarity. - Enhanced request body handling in OpenAPIParser to prefer JSON content types and improved property resolution logic.
- Introduced new test cases for the generate_test_value function to validate correct behavior with valid and invalid patterns, as well as exception handling. - Removed outdated test cases from test_parameter.py that were previously testing generate_test_value.
- Improved error handling in `generate_property_value` and related functions to ensure consistent fallback values. - Streamlined the logic for generating example values for various property types, including strings, numbers, booleans, objects, and arrays. - Introduced a new test suite in `test_body.py` to validate example generation across different schemas and property configurations, ensuring robustness and correctness.
…y.py - Enhanced documentation for `generate_example_body`, `generate_json_example`, `generate_property_value`, `generate_string_property`, `generate_numerical_property`, `generate_object_property`, and `generate_array_property` functions to clarify their purpose, arguments, and return types. - Updated setup.cfg to include mypy configuration for better type checking and unused config warnings.
- Modified the Bandit security scan command in the GitHub Actions workflow to use a custom configuration file (bandit.yaml) for improved scanning accuracy and flexibility.
- Changed the Python version from 3.8 to 3.9 in both the CI and security workflows to ensure compatibility with the latest dependencies and features.
… with latest dependencies
rahulkaushal04
added a commit
that referenced
this pull request
May 10, 2025
#5) Add generate_test_value function and refactor type hints - Implement generate_test_value in utils.py for regex-based test value generation - Refactor dataclasses to use built-in `dict` and `list` types instead of `Dict` and `List` - Update type hints across modules (body.py, endpoint.py, parameter.py, base_parser.py, openapi_parser.py) - Add appropriate unit tests for the new utility function Enhance RequestBody with intelligent example generation - Add __post_init__ method to RequestBody to auto-generate examples when not provided - Implement comprehensive example generation for JSON schemas based on property types - Support various data types (string, number, integer, boolean, object, array) with format-specific examples - Add support for schema constraints (min/max length, pattern, enum values, etc.) Improve code quality and project structure - Enhance error handling in example generation functions with consistent fallbacks - Add detailed docstrings for all new functions with proper type annotations - Update test cases to verify example generation behavior across different schemas - Update project configuration files (.gitignore, MANIFEST.in, setup.cfg) Update dependencies and CI configuration - Update Python version from 3.8 to 3.9 in CI workflows for better compatibility - Upgrade urllib3 to version 2.4.0 for security and dependency compatibility - Modify Bandit security scan to use custom configuration - Simplify security workflow by removing pip-audit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors the test value and example generation logic across the codebase with improved type handling and comprehensive unit tests. Key changes include:
generate_test_valuefunction inutils.pyto generate test values matching regex patternsRequestBodyto support additional property types (string, number, boolean, object, array)body.pywith comprehensive type hints and docstringsRelated Issue
Type of Change
Checklist
Screenshots (if applicable)
Additional Context
Testing Instructions
Run the test suite to verify that all tests pass:
pytest src/tests/Check that example generation works as expected by using the RequestBody and Parameter dataclasses
Steps to reproduce or test the changes
Expected behavior
Dependencies