Skip to content

Commit

Permalink
🎉 Tool for generation catalog schema from OpenAPI definition file (#5734
Browse files Browse the repository at this point in the history
)

* Add tool for generating catalog json schema from openapi definition file
  • Loading branch information
avida committed Sep 1, 2021
1 parent 75a6a75 commit 8d2cd1e
Show file tree
Hide file tree
Showing 7 changed files with 31,453 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/connector-development/cdk-python/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The schema of a stream is the return value of `Stream.get_json_schema`.
By default, `Stream.get_json_schema` reads a `.json` file in the `schemas/` directory whose name is equal to the value of the `Stream.name` property. In turn `Stream.name` by default returns the name of the class in snake case. Therefore, if you have a class `class EmployeeBenefits(HttpStream)` the default behavior will look for a file called `schemas/employee_benefits.json`. You can override any of these behaviors as you need.

Important note: any objects referenced via `$ref` should be placed in the `shared/` directory in their own `.json` files.

### Generating schemas from OpenAPI definitions
If you are implementing a connector to pull data from an API which publishes an [OpenAPI/Swagger spec](https://swagger.io/specification/), you can use a tool we've provided for generating JSON schemas from the OpenAPI definition file. Detailed information can be found [here](https://github.com/airbytehq/airbyte/tree/master/tools/openapi2jsonschema/).

## Dynamic schemas
If you'd rather define your schema in code, override `Stream.get_json_schema` in your stream class to return a `dict` describing the schema using [JSONSchema](https://json-schema.org).
Expand All @@ -21,3 +24,4 @@ def get_json_schema(self):
schema['dynamically_determined_property'] = "property"
return schema
```

11 changes: 11 additions & 0 deletions tools/openapi2jsonschema/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.7-slim

RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

RUN pip install git+https://github.com/airbytehq/openapi2jsonschema.git@v0.1

RUN mkdir -p /schemas

WORKDIR /schemas

ENTRYPOINT ["/usr/local/bin/openapi2jsonschema"]
13 changes: 13 additions & 0 deletions tools/openapi2jsonschema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# openapi2jsonschema
Util for generating catalog schema from OpenAPI definition file. Froked from [openapi2jsonschema](https://github.com/instrumenta/openapi2jsonschema) util with fixes for generating standlone schemas e.g. ones that don't contain reference to another files/resources.

## Usage
```bash
$ tools/openapi2jsonschema/run.sh <path to OpenAPI definition file>
```
It would generate set of jsonschema files based on components described on OpenAPI definition and place it on "**schemas**" fodler in current working directory.

Support OpenAPI v2.0, v3.0 and v3.1. Works with both json and yaml OpenAPI formats.

### Examples
You can try to run this tool on sample OpenApi definition files located in [exmaples](./examples) directory. That is some OpenAPI files taken from APIs-guru repo [from github](https://github.com/APIs-guru).
Loading

0 comments on commit 8d2cd1e

Please sign in to comment.