def test_parse_spec_with_circular_reference(openapi_spec_generator):
  """Test correct handling of circular $ref (important!)."""
  openapi_spec = {
      "openapi": "3.1.0",
      "info": {"title": "Circular Ref API", "version": "1.0.0"},
      "paths": {
          "/circular": {
              "get": {
                  "responses": {
                      "200": {
                          "description": "OK",
                          "content": {
                              "application/json": {
                                  "schema": {"$ref": "#/components/schemas/A"}
                              }
                          },
                      }
                  }
              }
          }
      },
      "components": {
          "schemas": {
              "A": {
                  "type": "object",
                  "properties": {"b": {"$ref": "#/components/schemas/B"}},
              },
              "B": {
                  "type": "object",
                  "properties": {"a": {"$ref": "#/components/schemas/A"}},
              },
          }
      },
  }

  parsed_operations = openapi_spec_generator.parse(openapi_spec)
  assert len(parsed_operations) == 1

  op = parsed_operations[0]
  assert op.return_value.type_value.__origin__ is dict
  assert op.return_value.type_hint == "Dict[str, Any]"
Test correct handling of circular $ref (important!).
tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py