-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters