doc-generate/test_respdoc.sh

51 lines
1.8 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 測試 respdoc 功能
set -e
echo "🧪 測試 @respdoc 多狀態碼回應功能"
echo "================================"
OUTPUT_DIR="example/test_output"
mkdir -p "$OUTPUT_DIR"
echo ""
echo "📝 測試 1: Swagger 2.0 with @respdoc"
./bin/go-doc -a example/example_respdoc.api -d "$OUTPUT_DIR" -f respdoc_swagger2
CODES=$(jq -r '.paths."/v1/query".get.responses | keys | join(", ")' "$OUTPUT_DIR/respdoc_swagger2.json")
echo "✅ 狀態碼: $CODES"
echo ""
echo "📝 測試 2: OpenAPI 3.0 with @respdoc"
./bin/go-doc -a example/example_respdoc.api -d "$OUTPUT_DIR" -f respdoc_openapi3 -s openapi3.0
CODES=$(jq -r '.paths."/v1/query".get.responses | keys | join(", ")' "$OUTPUT_DIR/respdoc_openapi3.json")
echo "✅ 狀態碼: $CODES"
echo ""
echo "📝 測試 3: 檢查 400 回應的 oneOfOpenAPI 3.0"
HAS_ONEOF=$(jq '.paths."/v1/query".get.responses."400".content."application/json".schema | has("oneOf")' "$OUTPUT_DIR/respdoc_openapi3.json")
if [ "$HAS_ONEOF" = "true" ]; then
TYPES=$(jq -r '.paths."/v1/query".get.responses."400".content."application/json".schema.oneOf | map(."$ref" | split("/") | last) | join(", ")' "$OUTPUT_DIR/respdoc_openapi3.json")
echo "✅ 使用 oneOf包含類型: $TYPES"
else
echo "❌ 沒有使用 oneOf"
exit 1
fi
echo ""
echo "📝 測試 4: 檢查所有錯誤類型的 schema"
SCHEMAS=$(jq -r '.components.schemas | keys | map(select(. | contains("Error"))) | join(", ")' "$OUTPUT_DIR/respdoc_openapi3.json")
echo "✅ 錯誤類型 schemas: $SCHEMAS"
echo ""
echo "📝 測試 5: Swagger 2.0 檢查業務錯誤碼描述"
DESC=$(jq -r '.paths."/v1/query".get.responses."400".description' "$OUTPUT_DIR/respdoc_swagger2.json" | head -3)
echo "✅ 400 描述:"
echo "$DESC"
echo ""
echo "🎉 所有 @respdoc 測試通過!"
echo ""
echo "生成的檔案:"
ls -lh "$OUTPUT_DIR"/respdoc_*