Skip to main content

An SDK for parsing OpenAPI (Swagger) 2.0 - 3.0 specifications

Project description

oapi

test distribute

oapi is a library and CLI for authoring python data models (for clients or servers), and/or client libraries, for web APIs, based on an OpenAPI specification (both OpenAPI/Swagger version 2 and version 3 are supported).

oapi-generated packages/modules differ from those generated by other tools (including but not limited to swagger-codegen) in that oapi generates a data model which enforces the schemas defined in the OpenAPI specification. This means that request and response objects cannot comprise data types which differ from those specified in the spec, and objects cannot have properties which are not defined. If an API will add properties to an object which are not explicitly defined in the schema properties, that object should have an "additionalProperties" attribute, in which case oapi will treat these objects as dictionaries/mappings. oapi also fully supports polymorphism when a schema has an "anyOf", "allOf", or "oneOf" attribute (although oapi does not require a discriminator to be defined). This design decision could prove to be an annoyance to lazy developers of client applications, since inaccurate OpenAPI schemas are endemic to many organizations. The author of this library, however, asserts that end-to-end data validation is absolutely essential for applications which are part of a critical data pipeline. The author of this library is also of the opinion that when encountering inaccurate OpenAPI specifications, you should fix the spec, and if you are not the owner of the spec (and can't convince the owner to fix it), you should script your fix in order to apply that same fix to future versions of the specification.

Notable features of an oapi generated client/model library include:

  • oapi generated data models and clients are fully type-hinted (they will pass inspection by mypy).
  • oapi generated data models and clients adhere to PEP-8 formatting standards, and will pass inspection by flake8 (with the default options).
  • oapi generated data models and clients include docstrings for all models, model properties, client methods, and client method parameters, inferred from "description" and "summary" attributes of elements within the specification.
  • oapi generated clients will handle the most common server-to-server authentication methods out-of-box, including the OAuth2 authorization code flow (client_id/client_secret), API keys, bearer tokens, HTTP basic auth, and most cookie-based authentication patterns. Custom authentication methods are also easily accomplished by specifying custom base classes and/or passing initialization decorators to the oapi client shell command or to the oapi.client.create() function.
  • oapi generated clients and models are easily updated. For instance: oapi generated data model classes can be renamed using your favorite IDE's refactoring tools, and subsequent updates to that data model (such as to reflect minor-version updates to the spec which add endpoints, schemas, parameters, etc.) will retain your new class names, so long as the schema from which the class was generated remains in the same location within the spec. Class naming can also be customized by passing a custom hook to the get_class_name_from_pointer parameter for oapi.model.Module or oapi.model.create.

TODO: Finish README.md

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oapi-1.60.0.tar.gz (62.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oapi-1.60.0-py3-none-any.whl (62.7 kB view details)

Uploaded Python 3

File details

Details for the file oapi-1.60.0.tar.gz.

File metadata

  • Download URL: oapi-1.60.0.tar.gz
  • Upload date:
  • Size: 62.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for oapi-1.60.0.tar.gz
Algorithm Hash digest
SHA256 8619f14064b40a688c1c9fb8f97b0d1b51b7ab294990dd907853775ade4f9138
MD5 a8668bfece22443e4b85f905a24c15b4
BLAKE2b-256 74c66a5090f2182617a7b3ee54e9561530a56b4d0656b270ae87319a689195a5

See more details on using hashes here.

File details

Details for the file oapi-1.60.0-py3-none-any.whl.

File metadata

  • Download URL: oapi-1.60.0-py3-none-any.whl
  • Upload date:
  • Size: 62.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for oapi-1.60.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e58201e2a95b008a1c2417aaec8b03db2a853971371aa9a2e99974c84f52ff2e
MD5 d16600852fc21a03e84a77ee64c49cb6
BLAKE2b-256 9b4a92e557c37e5ef9f6660016811e4270f0a60134a3d8f39942382bafbb6f2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page