@@ -35,16 +35,64 @@ echo "Running OpenAPI 3.2.0 Petstore test..."
3535node dist/cli.js from_openapi to_sdk -i ../petstore_oas3.json -o .test_out_openapi || { echo " OpenAPI 3.2.0 Petstore test failed" ; exit 1; }
3636(cd .test_out_openapi && npm install && npm run build) || { echo " OpenAPI 3.2.0 SDK build failed" ; exit 1; }
3737
38- echo " Starting Prism mock servers (fallback non-JVM version) due to upstream/Docker issues..."
39- npx @stoplight/prism-cli mock ../petstore.json -p 4010 -d > /dev/null 2>&1 &
40- PRISM_SWAGGER=$!
38+ DOCKER_PORT=8080
39+ USE_PRISM=0
40+
41+ if command -v docker > /dev/null 2>&1 ; then
42+ echo " Starting JVM official petstore server in Docker..."
43+ docker run --rm -d -p $DOCKER_PORT :8080 --name petstore_server_precommit swaggerapi/petstore > /dev/null 2>&1 || USE_PRISM=1
44+ else
45+ USE_PRISM=1
46+ fi
47+
48+ if [ " $USE_PRISM " -eq 0 ]; then
49+ echo " Waiting for JVM Petstore server to be ready..."
50+ READY=0
51+ for i in {1..30}; do
52+ if curl -s -f http://127.0.0.1:$DOCKER_PORT /api/pet/findByStatus? status=available > /dev/null; then
53+ READY=1
54+ break
55+ fi
56+ sleep 2
57+ done
58+
59+ if [ " $READY " -eq 1 ]; then
60+ echo " JVM server is ready."
61+ cat << EOF > test-sdks.ts
62+ import { StoreClient as SwaggerStoreClient } from './.test_out_swagger/dist/services/store.client.js';
63+ import { StoreClient as OpenApiStoreClient } from './.test_out_openapi/dist/services/store.client.js';
64+
65+ async function run() {
66+ console.log("Testing Swagger 2.0 SDK against JVM Server...");
67+ const swaggerClient = new SwaggerStoreClient('http://127.0.0.1:$DOCKER_PORT /api');
68+ await swaggerClient.getInventory({ headers: { api_key: 'special-key' } });
69+ console.log("Swagger 2.0 OK");
70+
71+ console.log("Testing OpenAPI 3.0 SDK against JVM Server...");
72+ const openapiClient = new OpenApiStoreClient('http://127.0.0.1:$DOCKER_PORT /api');
73+ await openapiClient.getInventory({ headers: { api_key: 'special-key' } });
74+ console.log("OpenAPI 3.0 OK");
75+ }
76+ run().catch(e => { console.error(e); process.exit(1); });
77+ EOF
78+ else
79+ echo " JVM server failed to become ready. Falling back to Prism."
80+ docker stop petstore_server_precommit > /dev/null 2>&1 || true
81+ USE_PRISM=1
82+ fi
83+ fi
84+
85+ if [ " $USE_PRISM " -eq 1 ]; then
86+ echo " Starting Prism mock servers (fallback non-JVM version) due to upstream/Docker issues..."
87+ npx @stoplight/prism-cli mock ../petstore.json -p 4010 -d > /dev/null 2>&1 &
88+ PRISM_SWAGGER=$!
4189
42- npx @stoplight/prism-cli mock ../petstore_oas3.json -p 4011 -d > /dev/null 2>&1 &
43- PRISM_OAS3=$!
90+ npx @stoplight/prism-cli mock ../petstore_oas3.json -p 4011 -d > /dev/null 2>&1 &
91+ PRISM_OAS3=$!
4492
45- sleep 5
93+ sleep 5
4694
47- cat << 'EOF ' > test-sdks.ts
95+ cat << 'EOF ' > test-sdks.ts
4896import { StoreClient as SwaggerStoreClient } from './.test_out_swagger/dist/services/store.client.js';
4997import { StoreClient as OpenApiStoreClient } from './.test_out_openapi/dist/services/store.client.js';
5098
@@ -61,12 +109,17 @@ async function run() {
61109}
62110run().catch(e => { console.error(e); process.exit(1); });
63111EOF
112+ fi
64113
65114npx tsc test-sdks.ts --module NodeNext --moduleResolution NodeNext || { echo " test-sdks compilation failed" ; exit 1; }
66115node test-sdks.js || { echo " test-sdks execution failed" ; exit 1; }
67116
68- kill $PRISM_SWAGGER
69- kill $PRISM_OAS3
117+ if [ " $USE_PRISM " -eq 0 ]; then
118+ docker stop petstore_server_precommit > /dev/null 2>&1 || true
119+ else
120+ kill $PRISM_SWAGGER || true
121+ kill $PRISM_OAS3 || true
122+ fi
70123
71124rm -rf .test_out_swagger
72125rm -rf .test_out_openapi
0 commit comments