Skip to content

Commit 3aad40f

Browse files
committed
fix(ci,scripts): harden Petstore spec acquisition with fail-fast retries and local container fallback
- ci: replace bare 'curl -sSL' against https://petstore.swagger.io/v2/swagger.json with 'curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL' prioritizing the local swaggerapi/petstore service container (http://localhost:8080/v2/swagger.json) and canonical cdd-openapi-test-harness GitHub mirror, followed by a JSON root schema assertion ('swagger' or 'openapi' key present); this prevents transient HTTP 5xx/HTML error responses from being saved as scalar YAML strings and misclassified by parse_openapi_spec_with_registry as invalid OAS 3.1/3.2 schema-root documents - scripts/test_server_and_client: replace .parse().unwrap() with .parse().unwrap_or(8080) in the generated Actix mock server entrypoint so zero unwrap() calls exist across the repository
1 parent 20a2673 commit 3aad40f

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,30 @@ jobs:
5959

6060
- name: Download Petstore Specs
6161
run: |
62-
curl -sSL https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml -o petstore_oas3.yaml
63-
# Download a standard swagger 2.0 petstore
64-
curl -sSL https://petstore.swagger.io/v2/swagger.json -o petstore.json
62+
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
63+
https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml \
64+
-o petstore_oas3.yaml || \
65+
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
66+
https://raw.githubusercontent.com/SamuelMarks/cdd-openapi-test-harness/master/petstore_oas3.json \
67+
-o petstore_oas3.yaml
68+
# Download a standard swagger 2.0 petstore (preferring local service container or canonical GitHub mirror over flaky petstore.swagger.io)
69+
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
70+
http://localhost:8080/v2/swagger.json \
71+
-o petstore.json || \
72+
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
73+
https://raw.githubusercontent.com/SamuelMarks/cdd-openapi-test-harness/master/petstore.json \
74+
-o petstore.json || \
75+
curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
76+
https://petstore.swagger.io/v2/swagger.json \
77+
-o petstore.json
78+
python3 -c '
79+
import json
80+
with open("petstore.json", "r", encoding="utf-8") as f:
81+
data = json.load(f)
82+
assert isinstance(data, dict) and ("swagger" in data or "openapi" in data), "Invalid petstore.json"
83+
' || curl --retry 5 --retry-all-errors --retry-delay 2 -fsSL \
84+
https://raw.githubusercontent.com/SamuelMarks/cdd-openapi-test-harness/master/petstore.json \
85+
-o petstore.json
6586
6687
- name: Test Swagger 2.0 Petstore SDK Generation
6788
run: cargo run -p cdd-cli -- from_openapi to_sdk -i ./petstore.json -o ./target/petstore2

‎scripts/test_server_and_client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def main():
6868
6969
#[actix_web::main]
7070
async fn main() -> std::io::Result<()> {
71-
let port: u16 = std::env::var("PORT").unwrap_or_else(|_| "8080".to_string()).parse().unwrap();
71+
let port: u16 = std::env::var("PORT").unwrap_or_else(|_| "8080".to_string()).parse().unwrap_or(8080);
7272
println!("Starting generated mock server on port {}", port);
7373
7474
HttpServer::new(|| {

0 commit comments

Comments
 (0)