""" FastAPI application for the API Contract Validator Environment. Exposes the ValidatorEnvironment over HTTP and WebSocket endpoints using ``openenv.core.env_server.http_server.create_app``. Endpoints created automatically: - GET / — Landing page (this module) - POST /reset — Reset the environment - POST /step — Execute an action - GET /state — Get current environment state - GET /health — Health check - WS /ws — WebSocket for persistent sessions - GET /docs — Swagger UI (interactive — try every endpoint) """ from fastapi.responses import HTMLResponse try: from openenv.core.env_server.http_server import create_app except Exception as exc: raise ImportError( "openenv is required. Install with: pip install openenv-core" ) from exc try: from ..models import ValidatorAction, ValidatorObservation from .environment import ValidatorEnvironment from .logging_setup import configure_logging except (ImportError, ModuleNotFoundError): import sys import os sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from models import ValidatorAction, ValidatorObservation from server.environment import ValidatorEnvironment from server.logging_setup import configure_logging configure_logging() app = create_app( ValidatorEnvironment, ValidatorAction, ValidatorObservation, env_name="api_contract_validator", max_concurrent_envs=10, ) _LANDING_HTML = """ Enterprise Contract Guardian — OpenEnv

Enterprise Contract Guardian RUNNING

An OpenEnv RL environment that trains agents to detect API contract violations, trace downstream blast radius across microservices, and propose backward-compatible fixes.

Theme #3.1 Scaler AI Labs Bonus openenv-core 0.2.3 9 tasks · 3 phases · 14 reward signals

Endpoints

MethodPathPurpose
GET/healthLiveness check
GET/docs Interactive Swagger UI — click "Try it out" on any endpoint
POST/reset Start a new episode (optional task_name, seed)
POST/step Submit one ValidatorAction
GET/state Current environment state
WS/ws WebSocket session

Try it from your terminal

HOST=https://pushpam14-api-contract-validator.hf.space

curl $HOST/health
# {"status":"healthy"}

curl -X POST $HOST/reset -H "Content-Type: application/json" \\
     -d '{"task_name":"trace_downstream_blast_radius","seed":1}'

Tasks

Phase 1 — Detection
find_type_mismatches
validate_nested_objects
detect_breaking_changes
validate_response_schema
validate_cross_field_constraints
validate_auth_request
Phase 2 — Impact Tracing
trace_downstream_blast_radius

Phase 3 — Fix & Verify
propose_backward_compat_fix
multi_service_cascade_fix

Source & documentation

GitHub repo  ·  Swagger UI (interactive)  ·  ReDoc API spec

""" @app.get("/", response_class=HTMLResponse, include_in_schema=False) async def root() -> HTMLResponse: """Landing page — what the HF Space iframe shows by default.""" return HTMLResponse(content=_LANDING_HTML) def main(host: str = "0.0.0.0", port: int = 7860) -> None: """Entry point for ``uv run server`` or direct execution.""" import uvicorn uvicorn.run(app, host=host, port=port) if __name__ == "__main__": main()