Package: oapi
oapioapiis a library and CLI for authoring python data models (for clientsorservers), and/or client libraries, for web APIs, based on an
OpenAPI specification (both OpenAPI/Swaggerversion 2andversion 3are supported).oapi-generated packages/modules differ from those generated by other tools
(including but not limited toswagger-codegen) in thatoapigenerates 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
caseoapiwill treat these objects as dictionaries/mappings.oapialso
fully supports polymorphism when a schema has an "anyOf", "allOf", or
"oneOf" attribute (althoughoapidoes notrequireadiscriminatorto 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 anoapigenerated client/model library include:oapigenerated data models and clients are fully type-hinted (they
will pass inspection bymypy).oapigenerated data models and clients adhere to PEP-8 formatting
standards, and will pass inspection byflake8(with the default options).oapigenerated 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.oapigenerated 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 theoapi clientshell
command or to theoapi.client.create()function.oapigenerated clients and models are easily updated. For instance:oapigenerated 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 theget_class_name_from_pointerparameter foroapi.model.Moduleoroapi.model.create.TODO: Finish README.md