-
Notifications
You must be signed in to change notification settings - Fork 0
Integrate open api spec #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
93b9011
cc31d95
f315ec7
513f8db
4447a04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Development | ||
|
|
||
| This page describes the set-up of a development environment. The project uses a generated client based on Rapidata's OpenApi spec located at https://docs.rabbitdata.ch/. | ||
|
|
||
| ## OpenAPI Client generation | ||
|
|
||
| ### Download Specs | ||
|
|
||
| The specs used for generation are tracked at `openapi/output.swagger.json`. The following steps are only necessary to synchronize the generated client with the latest spec. | ||
|
|
||
| This requires [openapi-merge-cli](https://www.npmjs.com/package/openapi-merge-cli) installed globally | ||
|
|
||
| ``` | ||
| npm i -g openapi-merge-cli | ||
| ``` | ||
|
|
||
| Download and merge the specification from https://docs.rabbitdata.ch/: | ||
|
|
||
| ``` | ||
| ./openapi/download-and-merge-spec.sh | ||
| ``` | ||
|
|
||
| This should have produced/updated the file at `openapi/output.swagger.json` | ||
|
|
||
| ### Generate OpenAPI Client | ||
|
|
||
| This requires [openapi-generator](https://github.com/OpenAPITools/openapi-generator) installed | ||
|
|
||
| ``` | ||
| brew install openapi-generator | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mainly a macOS thing right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, gotta add instructions for other operating systems at some point, but I think all of us internally would figure it out anyway |
||
| ``` | ||
|
|
||
| Execute the generation command by running | ||
|
|
||
| ``` | ||
| ./openapi/generate.sh | ||
| ``` | ||
|
|
||
| ## Python Package Management | ||
|
|
||
| This repository is using [poetry](https://python-poetry.org/) to manage dependencies. | ||
|
|
||
| To set-up a python environment using conda, run: | ||
| ``` | ||
| conda create -n rapi-client | ||
| ``` | ||
|
|
||
| Then let poetry install all dependencies: | ||
|
|
||
| ``` | ||
| poetry install | ||
| ``` | ||
|
|
||
| This will also install the OpenAPI Client located at `openapi/openapi-client` as a development dependency. So any new generation does not require a re-install. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| from rapidata.rapidata_client import RapidataClient | ||
| from rapidata.rapidata_client.workflow import FeatureFlags | ||
| from rapidata.rapidata_client.workflow import ClassifyWorkflow | ||
| from rapidata.rapidata_client.workflow.referee import NaiveReferee | ||
| from rapidata.rapidata_client.referee import NaiveReferee | ||
|
|
||
| CLIENT_ID = os.getenv("CLIENT_ID") | ||
| CLIENT_SECRET = os.getenv("CLIENT_SECRET") | ||
|
|
@@ -32,7 +32,7 @@ | |
| .workflow( | ||
| ClassifyWorkflow( | ||
| question="Who should be president?", | ||
| categories=["Kamala Harris", "Donald Trump"], | ||
| options=["Kamala Harris", "Donald Trump"], | ||
|
Comment on lines
34
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should change this example
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. happening in the pr up the chain: https://github.com/RapidataAI/rapidata-python/pull/5/files |
||
| ) | ||
| .referee(NaiveReferee(required_guesses=15)) | ||
| .feature_flags(FeatureFlags().alert_on_fast_response(3)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| openapi-client/ | ||
| spec/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/bash | ||
|
|
||
| rm -rf openapi/spec | ||
| mkdir openapi/spec | ||
|
|
||
| # Use a function to simulate an associative array | ||
| url_for() { | ||
| case $1 in | ||
| "order") echo "https://api.app.rabbitdata.ch/Order/swagger/v1/swagger.json" ;; | ||
| "dataset") echo "https://api.app.rabbitdata.ch/Dataset/swagger/v1/swagger.json" ;; | ||
| "identity") echo "https://api.app.rabbitdata.ch/Identity/swagger/v1/swagger.json" ;; | ||
| *) echo "" ;; | ||
| esac | ||
| } | ||
|
|
||
| # List of keys | ||
| keys=("order" "dataset" "identity") | ||
|
|
||
| for key in "${keys[@]}"; do | ||
| url=$(url_for "$key") | ||
| output_json="openapi/spec/${key}.json" | ||
| output_ts="openapi/${key}.zod.ts" | ||
|
|
||
| # Download the JSON file using curl | ||
| curl -o "$output_json" "$url" | ||
|
|
||
| echo "Downloaded $url to $output_json" | ||
|
|
||
| done | ||
|
|
||
| # Merge the OpenAPI specs into a single file (output.swagger.json) | ||
| cd openapi | ||
| npx openapi-merge-cli |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| rm -rf openapi/openapi-client | ||
|
|
||
| openapi-generator generate -i openapi/output.swagger.json -g python -o openapi/openapi-client --skip-validate-spec |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "inputFile": "./spec/dataset.json" | ||
| }, | ||
| { | ||
| "inputFile": "./spec/order.json" | ||
| }, | ||
| { | ||
| "inputFile": "./spec/identity.json" | ||
| } | ||
| ], | ||
| "output": "./output.swagger.json" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we install something needed for the python package with the npm installer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
necessary for the client generation