Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

OpenAPI to Hydra parser

License

NotificationsYou must be signed in to change notification settings

HTTP-APIs/hydra-openapi-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This library contains the OpenAPI parser implemntaion in Python to be used withhydrus andhydra-python-agent.

Currently the library consists of openapi_parser module which helps hydrus parse OpenAPI standard docs.

To install the library:

pip install git+https://github.com/HTTP-APIs/hydra-openapi-parser.git#egg=hydra_openapi_parser

Note :- If using hydrus, the library doesn't need to be installed separately as it is already a part of requirements.txt for hydrus.Usage

To import the modules:

fromhydra_openapi_parserimportopenapi_parser

Porting out from hydrus the hydraspecs directory

Sample use-cases of openapi_parser module

Once the OpenAPI YAML document is assigned into the variabledoc as a Python dictionary, you can do the following:

  • Parse the OpenAPI doc into a HydraDoc
parsed_dict=openapi_parser.parse(doc)
  • Generate an empty object
object=openapi_parser.generate_empty_object()
  • Test if an endpoint is valid
path='A/B/{id}/C/D'openapi_parser.valid_endpoint(path)# Falsepath='A/B/{id}'openapi_parser.valid_endpoint(path)# Collectionpath='A/B/C'openapi_parser.valid_endpoint(path)# True
  • Extract class name from the path
path="A/B/C/Pet"path_list=path.split('/')openapi_parser.get_class_name(path_list)# Pet
  • Fetch data from location
path='#/definitions/Order'path_list=path.split('/')data=openapi_parser.get_data_at_location(path_list,doc)# data is of type dict
  • Remove variables from path
path="A/B/C/{id}"output=openapi_parser.sanitise_path(path)
  • Identify if an object is a collection
schema_block= {'type':'array','items': {'$ref':'#/definitions/Pet'    }}method="/Pet"openapi_parser.check_collection(schema_block,method)# True

About

OpenAPI to Hydra parser

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors8

Languages


[8]ページ先頭

©2009-2025 Movatter.jp