File size: 2,693 Bytes
322135d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# This script generate model definitions for OpenAPI 3.0 documentation

set -e

# Ensure current path is project root
cd "$(dirname "$0")/../"

# Fallback to dockerized utilities if they are not installed locally

if command -v ytt &>/dev/null; then
    sh_with_ytt() { sh -c "$1"; }
else
    sh_with_ytt() { docker run --rm -v "${PWD}":/workspace --entrypoint sh gerritk/ytt -c "$1"; }
fi

if ! yq --version 2>&1 | grep -q mikefarah; then
    yq() { docker run --rm -v "${PWD}":/workdir mikefarah/yq "$@"; }
fi

# Apply `ytt` template engine to obtain OpenAPI definitions for REST endpoints

sh_with_ytt '
    set -e
    ytt -f ./openapi/openapi.lib.yml -f ./openapi/openapi-shards.ytt.yaml > ./openapi/openapi-shards.yaml
    ytt -f ./openapi/openapi.lib.yml -f ./openapi/openapi-service.ytt.yaml > ./openapi/openapi-service.yaml
    ytt -f ./openapi/openapi.lib.yml -f ./openapi/openapi-cluster.ytt.yaml > ./openapi/openapi-cluster.yaml
    ytt -f ./openapi/openapi.lib.yml -f ./openapi/openapi-collections.ytt.yaml > ./openapi/openapi-collections.yaml
    ytt -f ./openapi/openapi.lib.yml -f ./openapi/openapi-snapshots.ytt.yaml > ./openapi/openapi-snapshots.yaml
    ytt -f ./openapi/openapi.lib.yml -f ./openapi/openapi-shard-snapshots.ytt.yaml > ./openapi/openapi-shard-snapshots.yaml
    ytt -f ./openapi/openapi.lib.yml -f ./openapi/openapi-points.ytt.yaml > ./openapi/openapi-points.yaml
    ytt -f ./openapi/openapi.lib.yml -f ./openapi/openapi-main.ytt.yaml > ./openapi/openapi-main.yaml
'

# Generates models from internal service structures
cargo run --package qdrant --bin schema_generator > ./openapi/schemas/AllDefinitions.json

docker build tools/schema2openapi --tag schema2openapi

docker run --rm \
    -v "$PWD/openapi/schemas/AllDefinitions.json:/app/schema.json" \
    schema2openapi | sed -e 's%#/definitions/%#/components/schemas/%g' >./openapi/models.json

yq eval -o yaml -P ./openapi/models.json > ./openapi/models.yaml

# Merge all *.yaml files together into a single-file OpenAPI definition
yq eval-all '. as $item ireduce ({}; . *+ $item)' \
  ./openapi/openapi-shards.yaml \
  ./openapi/openapi-service.yaml \
  ./openapi/openapi-cluster.yaml \
  ./openapi/openapi-collections.yaml \
  ./openapi/openapi-snapshots.yaml \
  ./openapi/openapi-shard-snapshots.yaml \
  ./openapi/openapi-points.yaml \
  ./openapi/openapi-main.yaml \
  ./openapi/models.yaml > ./openapi/openapi-merged.yaml

docker run --rm -v "${PWD}"/openapi:/spec redocly/openapi-cli:v1.0.0-beta.88 lint openapi-merged.yaml

yq eval -o=json ./openapi/openapi-merged.yaml | jq > ./openapi/openapi-merged.json

cp ./openapi/openapi-merged.json ./docs/redoc/master/openapi.json