|
| 1 | +#!/bin/bash |
| 2 | +# Update the bundled OpenAPI schema from mothership dev server |
| 3 | +set -e |
| 4 | + |
| 5 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 6 | +CLI_DIR="$(dirname "$SCRIPT_DIR")" |
| 7 | +SCHEMA_FILE="$CLI_DIR/smart_tests/schema/openapi-schema.json" |
| 8 | + |
| 9 | +echo "Fetching OpenAPI schema from local dev server..." |
| 10 | + |
| 11 | +# Check if mothership is running |
| 12 | +if ! curl -s -f http://localhost:8080/intake/v3/api-docs > /dev/null 2>&1; then |
| 13 | + echo "Error: Mothership dev server not running at localhost:8080" |
| 14 | + echo "Please start it with: cd mothership && bazel run //src/main/java/com/launchableinc/mercury/intake" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +# Create schema directory if it doesn't exist |
| 19 | +mkdir -p "$(dirname "$SCHEMA_FILE")" |
| 20 | + |
| 21 | +# Fetch and save schema |
| 22 | +curl -s http://localhost:8080/intake/v3/api-docs > "$SCHEMA_FILE" |
| 23 | + |
| 24 | +# Validate and format the JSON with proper indentation and trailing newline |
| 25 | +python3 << PYTHON_EOF |
| 26 | +import json |
| 27 | +
|
| 28 | +with open("$SCHEMA_FILE", 'r') as f: |
| 29 | + schema = json.load(f) |
| 30 | +
|
| 31 | +# Write back with proper formatting |
| 32 | +with open("$SCHEMA_FILE", 'w') as f: |
| 33 | + json.dump(schema, f, indent=2) |
| 34 | + f.write('\n') # Add trailing newline |
| 35 | +PYTHON_EOF |
| 36 | + |
| 37 | +echo "✓ Schema updated successfully: $SCHEMA_FILE" |
| 38 | +echo "" |
| 39 | + |
| 40 | +# Show what changed |
| 41 | +if git diff --quiet "$SCHEMA_FILE" 2>/dev/null; then |
| 42 | + echo "No changes detected in schema" |
| 43 | +else |
| 44 | + echo "Changes detected:" |
| 45 | + git diff --stat "$SCHEMA_FILE" 2>/dev/null || echo "(Not a git repository)" |
| 46 | + echo "" |
| 47 | + echo "Review with: git diff $SCHEMA_FILE" |
| 48 | + echo "Commit with: git add $SCHEMA_FILE && git commit -m 'Update OpenAPI schema'" |
| 49 | +fi |
0 commit comments