Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"python.testing.unittestEnabled": true,
"python.analysis.enablePytestSupport": false,
"python.testing.pytestEnabled": false,
"python.analysis.typeCheckingMode": "strict"
"python.analysis.typeCheckingMode": "standard",
"python.analysis.extraPaths": [
"./openapi/openapi-client"
]
}
55 changes: 55 additions & 0 deletions docs/source/development.md
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
Copy link
Contributor

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?

Copy link
Contributor Author

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

```

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mainly a macOS thing right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

1 change: 1 addition & 0 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ Welcome! The Rapidata Python Client is a convenient way to interact with the Rap

quickstart
examples/index
development

```
4 changes: 2 additions & 2 deletions examples/classify_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change this example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
.referee(NaiveReferee(required_guesses=15))
.feature_flags(FeatureFlags().alert_on_fast_response(3))
Expand Down
2 changes: 2 additions & 0 deletions openapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
openapi-client/
spec/
33 changes: 33 additions & 0 deletions openapi/download-and-merge-spec.sh
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
3 changes: 3 additions & 0 deletions openapi/generate.sh
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
14 changes: 14 additions & 0 deletions openapi/openapi-merge.json
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"
}
Loading