qxf2-page-object-model icon indicating copy to clipboard operation
qxf2-page-object-model copied to clipboard

Generate Endpoint file from OpenAPI spec

Open shivahari opened this issue 10 months ago • 1 comments

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


shivahari avatar Apr 11 '24 06:04 shivahari

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

akkuldn avatar Apr 24 '24 08:04 akkuldn