Skip to content

Commit

Permalink
force ordering on API
Browse files Browse the repository at this point in the history
  • Loading branch information
generall committed May 22, 2024
1 parent 140b47c commit 18085d6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
11 changes: 11 additions & 0 deletions fern/api-ordering.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file defines the ordering of the API endpoints in the generated OpenAPI spec.
# If the api is not defined in this file, it will be appended to the end of the spec in unspecified order.

order:
- path: /collections/{collection_name}
- path: /collections/{collection_name}/points
- path: /collections/{collection_name}/points/search
- path: /collections/{collection_name}/snapshots
- path: /collections/aliases
- path: /cluster
- path: /telemetry
56 changes: 56 additions & 0 deletions tools/order_openapi_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import argparse
from collections import OrderedDict
import yaml
import json

def load_yaml(path: str):
with open(path, 'r') as f:
return yaml.load(f, Loader=yaml.FullLoader)

def load_json(path: str):
with open(path, 'r') as f:
return json.load(f)

def save_json(data, path: str):
with open(path, 'w') as f:
json.dump(data, f, indent=2)


def order_openapi_file(openapi, ordering):
paths = openapi['paths']

orderred_paths = OrderedDict()

for path in ordering:
if path in paths:
orderred_paths[path] = paths[path]

for path in paths.keys():
if path not in orderred_paths:
orderred_paths[path] = paths[path]

openapi['paths'] = orderred_paths


def main():
parser = argparse.ArgumentParser(description='Generate snippet overwrites for the OpenAPI spec')
parser.add_argument('--openapi', type=str, help='Path to the OpenAPI spec')
parser.add_argument('--output', type=str, help='Path to the snippet overwrite file')
args = parser.parse_args()

ordering = load_yaml("fern/api-ordering.yml")

ordering_list = [
item['path']
for item in ordering['order']
]

openapi = load_json(args.openapi)

order_openapi_file(openapi, ordering_list)

save_json(openapi, args.output)


if __name__ == '__main__':
main()
7 changes: 6 additions & 1 deletion tools/sync-openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ cd $PROJECT_ROOT
# Update master API

cp qdrant/docs/redoc/master/openapi.json $PROJECT_ROOT/fern/apis/master/openapi.json
# Make sure that methods in OpenAPI schema are ordered as we want
python tools/order_openapi_file.py --openapi $PROJECT_ROOT/fern/apis/master/openapi.json --output $PROJECT_ROOT/fern/apis/master/openapi-orderred.json
mv $PROJECT_ROOT/fern/apis/master/openapi-orderred.json $PROJECT_ROOT/fern/apis/master/openapi.json

# Generate fern overwrites from the snippets

Expand Down Expand Up @@ -50,7 +53,9 @@ rm -rf $PROJECT_ROOT/fern/apis/$latest_version
cp -r $PROJECT_ROOT/fern/apis/master $PROJECT_ROOT/fern/apis/$latest_version

cp qdrant/docs/redoc/$latest_version/openapi.json $PROJECT_ROOT/fern/apis/$latest_version/openapi.json

# Make sure that methods in OpenAPI schema are ordered as we want
python tools/order_openapi_file.py --openapi $PROJECT_ROOT/fern/apis/$latest_version/openapi.json --output $PROJECT_ROOT/fern/apis/$latest_version/openapi-orderred.json
mv $PROJECT_ROOT/fern/apis/$latest_version/openapi-orderred.json $PROJECT_ROOT/fern/apis/$latest_version/openapi.json


# Create version file in `fern/versions` by replacing master with the latest version
Expand Down

0 comments on commit 18085d6

Please sign in to comment.