@@ -795,164 +795,6 @@ def test_cache_normalization(self, discovery):
795795 assert api_spec1 is api_spec2
796796
797797
798- class TestSwagger2Support :
799- """Test Swagger 2.0 specification support."""
800-
801- @pytest .fixture
802- def discovery (self ):
803- """Create a schema discovery instance."""
804- return OCPSchemaDiscovery ()
805-
806- @pytest .fixture
807- def swagger2_spec (self ):
808- """Basic Swagger 2.0 specification."""
809- return {
810- "swagger" : "2.0" ,
811- "info" : {
812- "title" : "Swagger 2.0 API" ,
813- "version" : "1.0.0" ,
814- "description" : "A test API using Swagger 2.0"
815- },
816- "host" : "api.example.com" ,
817- "basePath" : "/v1" ,
818- "schemes" : ["https" ],
819- "paths" : {
820- "/users" : {
821- "get" : {
822- "operationId" : "getUsers" ,
823- "summary" : "List users" ,
824- "description" : "Get a list of all users" ,
825- "parameters" : [
826- {
827- "name" : "limit" ,
828- "in" : "query" ,
829- "type" : "integer" ,
830- "required" : False
831- }
832- ],
833- "responses" : {
834- "200" : {
835- "description" : "List of users" ,
836- "schema" : {
837- "type" : "array" ,
838- "items" : {
839- "type" : "object" ,
840- "properties" : {
841- "id" : {"type" : "integer" },
842- "name" : {"type" : "string" },
843- "email" : {"type" : "string" }
844- }
845- }
846- }
847- }
848- }
849- },
850- "post" : {
851- "operationId" : "createUser" ,
852- "summary" : "Create user" ,
853- "description" : "Create a new user" ,
854- "parameters" : [
855- {
856- "name" : "body" ,
857- "in" : "body" ,
858- "required" : True ,
859- "schema" : {
860- "type" : "object" ,
861- "properties" : {
862- "name" : {"type" : "string" },
863- "email" : {"type" : "string" }
864- },
865- "required" : ["name" , "email" ]
866- }
867- }
868- ],
869- "responses" : {
870- "201" : {
871- "description" : "User created" ,
872- "schema" : {
873- "type" : "object" ,
874- "properties" : {
875- "id" : {"type" : "integer" },
876- "name" : {"type" : "string" },
877- "email" : {"type" : "string" }
878- }
879- }
880- }
881- }
882- }
883- },
884- "/users/{id}" : {
885- "get" : {
886- "operationId" : "getUserById" ,
887- "summary" : "Get user" ,
888- "description" : "Get a specific user by ID" ,
889- "parameters" : [
890- {
891- "name" : "id" ,
892- "in" : "path" ,
893- "type" : "string" ,
894- "required" : True
895- }
896- ],
897- "responses" : {
898- "200" : {
899- "description" : "User details" ,
900- "schema" : {
901- "type" : "object" ,
902- "properties" : {
903- "id" : {"type" : "integer" },
904- "name" : {"type" : "string" },
905- "email" : {"type" : "string" }
906- }
907- }
908- }
909- }
910- }
911- }
912- }
913- }
914-
915- @patch ('ocp_agent.schema_discovery.requests.get' )
916- def test_discover_swagger2_api (self , mock_get , discovery , swagger2_spec ):
917- """Test full API discovery with Swagger 2.0 spec."""
918- mock_response = Mock ()
919- mock_response .json .return_value = swagger2_spec
920- mock_response .raise_for_status .return_value = None
921- mock_get .return_value = mock_response
922-
923- api_spec = discovery .discover_api ("https://api.example.com/swagger.json" )
924-
925- assert api_spec .title == "Swagger 2.0 API"
926- assert api_spec .version == "1.0.0"
927- assert api_spec .base_url == "https://api.example.com/v1"
928- assert len (api_spec .tools ) == 3
929-
930- # Check GET /users
931- get_users = next (t for t in api_spec .tools if t .name == "getUsers" )
932- assert get_users .method == "GET"
933- assert get_users .path == "/users"
934- assert "limit" in get_users .parameters
935- assert get_users .response_schema is not None
936- assert get_users .response_schema ["type" ] == "array"
937-
938- # Check POST /users
939- post_users = next (t for t in api_spec .tools if t .name == "createUser" )
940- assert post_users .method == "POST"
941- assert post_users .path == "/users"
942- assert "name" in post_users .parameters
943- assert "email" in post_users .parameters
944- assert post_users .parameters ["name" ]["required" ] == True
945- assert post_users .response_schema is not None
946-
947- # Check GET /users/{id}
948- get_user = next (t for t in api_spec .tools if t .name == "getUserById" )
949- assert get_user .method == "GET"
950- assert get_user .path == "/users/{id}"
951- assert "id" in get_user .parameters
952- assert get_user .parameters ["id" ]["location" ] == "path"
953- assert get_user .response_schema is not None
954-
955-
956798class TestResourceFiltering :
957799 """Test resource-based filtering functionality for discover_api method."""
958800
0 commit comments