go.ketch.com/lib/goja@v0.0.1/scripts/gengateway.sh (about)

     1  #!/usr/bin/env sh
     2  
     3  # Code generated by shipbuilder init 1.21.2. DO NOT EDIT.
     4  
     5  if [ ! -f "./scripts/check.sh" ]; then
     6    cd $(command dirname -- "$(command readlink -f "$(command -v -- "$0")")")/..
     7  fi
     8  
     9  . ./scripts/check.sh
    10  
    11  if [ -d openapi ]; then
    12    check go jq yq swagger_cli shipbuilder
    13  
    14    export module=$($go mod edit -json | $jq -r .Module.Path)
    15  
    16    set -e
    17  
    18    echo "Merging all servers into openapi/servers/index.yaml..."
    19    $yq ea '. as $item ireduce ({}; . * $item )' openapi/servers/*.yaml openapi/servers/index.yaml > openapi/servers/index.yaml.bak
    20    mv openapi/servers/index.yaml.bak openapi/servers/index.yaml
    21  
    22    echo "Generating gateway indexes..."
    23    for i in parameters responses requestBodies schemas; do
    24      if [ -d "openapi/components/$i" ]; then
    25        echo "* openapi/components/$i/_index.yaml"
    26        find "openapi/components/$i" -type f -name '*.yaml' -not -name '_index.yaml' | xargs -I {} basename {} .yaml | xargs -I {} printf "{}:\n  \$ref: \"./{}.yaml\"\n" > "openapi/components/$i/_index.yaml"
    27      fi
    28    done
    29  
    30    servers=$(find openapi/servers -type f -name '*.yaml' -not -name 'index.yaml' | xargs -I {} basename {} .yaml)
    31  
    32    echo "Generating openapi definitions..."
    33    for i in $servers; do
    34      $swagger_cli bundle --outfile "openapi/${i}_gen.yaml" --type yaml "openapi/servers/$i.yaml"
    35    done
    36  
    37    $swagger_cli bundle --outfile openapi/index_gen.yaml --type yaml openapi/servers/index.yaml
    38  
    39    echo "Generating gateway stubs..."
    40    for i in $servers; do
    41      # Generate the gateway stub code
    42      echo "* openapi/${i}_gen.yaml -> gateway/${i}_{handlers,requests,responses}_gen.go"
    43      $shipbuilder generate \
    44        --go-handler "pkg/gateway/${i}_handlers_gen.go" --go-handler-package "${module}/pkg/gateway" \
    45        --go-requests "pkg/gateway/${i}_requests_gen.go" --go-requests-package "${module}/pkg/gateway" \
    46        --go-responses "pkg/gateway/${i}_responses_gen.go" --go-responses-package "${module}/pkg/gateway" \
    47        "openapi/${i}_gen.yaml"
    48    done
    49  
    50    echo "* openapi/index_gen.yaml -> gateway/types_gen.go"
    51    $shipbuilder generate \
    52      --go-types pkg/gateway/types_gen.go --go-types-package "${module}/pkg/gateway" \
    53      openapi/index_gen.yaml
    54  fi