Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Endpoint file from OpenAPI spec #383

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

shivahari
Copy link
Collaborator

What changes added in the PR?

Added a utils/generate_endpoint_from_openapi_spec.py script to generate endpoints/<endpoint_name>_Endpoint.py file from an OpenAPI specification. It reads the endpoint details from the spec and uses the utils/endpoint_tempalte.py Jinja2 template to create the Endpoint files.


How to run the script?

pip install the dependencies from the requirements.txt file

python utils/generate_endpoint_from_openapi_spec.py --spec <location_to_the_json_or_yaml_openapi_spec>

^ command will dry-run OpenAPI spec parsing, it will help validate if the script was able to read and parse content from the spec.

python utils/generate_endpoint_from_openapi_spec.py --spec <location_to_the_json_or_yaml_openapi_spec> --generate-endpoint

^ command will generate the endpoints/<endpoint_name>_Endpoint.py file from the spec


@akkuldn
Copy link
Collaborator

akkuldn commented Apr 24, 2024

Nice work Shiva.

  • Generated the endpoint file for different API specifications
  • Generated endpoint for different request methods POST, GET, PUT, DELETE, PATCH
  • Generated the endpoint multiple times, observed that the previous files generated were getting overwritten
  • Tried generating endpoint with a non existent request method. It didn't generate the file as expected
  • Tried generating endpoints with special characters like - and _ in endpoint name, observed that - converted to _ in the method name.

Change to be made:

  • Can you please add the following line before method call endpoint = Endpoint(path.url, path.summary, ..., this is to ignore the Codacy warning
# pylint: disable=E1121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants