You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+99Lines changed: 99 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,113 @@
5
5
[![travis-image]][travis]
6
6
[![pypi-image]][pypi]
7
7
8
+
## Introduction
9
+
10
+
This is a Python [Core API][coreapi] codec for the [Open API][openapi] schema format, also known as "Swagger".
11
+
8
12
## Installation
9
13
10
14
Install using pip:
11
15
12
16
$ pip install openapi-codec
13
17
18
+
## Creating Swagger schemas
19
+
20
+
To create a swagger schema from a `coreapi.Document`, use the codec directly.
21
+
22
+
>>> from openapi_codec import OpenAPICodec
23
+
>>> codec = OpenAPICodec()
24
+
>>> schema = codec.encode(document)
25
+
26
+
## Using with the Python Client Library
27
+
28
+
To use the Python client library to interact with a service that exposes a Swagger schema,
29
+
include the codec in [the `decoders` argument][decoders].
30
+
31
+
>>> from openapi_codec import OpenAPICodec
32
+
>>> from coreapi.codecs import JSONCodec
33
+
>>> from coreapi import Client
34
+
>>> decoders = [OpenAPICodec(), JSONCodec()]
35
+
>>> client = Client(decoders=decoders)
36
+
37
+
If the server exposes the schema without properly using an `application/openapi+json` content type, then you'll need to make sure to include `format='openapi'` on the initial request,
If the server exposes the schema without properly using an `application/openapi+json` content type, then you'll need to make sure to include `format=openapi` on the initial request, to force the correct codec to be used.
60
+
61
+
$ coreapi get http://petstore.swagger.io/v2/swagger.json --format openapi
0 commit comments