Skip to content

Commit

Permalink
Merge pull request #435 from kreneskyp/openapi_path_args
Browse files Browse the repository at this point in the history
OpenAPIRequest now handles paths with variables
  • Loading branch information
kreneskyp authored Feb 5, 2024
2 parents a939391 + 005119e commit d414f98
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 5 additions & 1 deletion ix/runnable/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

def build_httpx_kwargs(path: str, input: Input, **kwargs) -> dict[str, Any]:
"""Build kwargs for OpenAPI request with httpx"""
formatted_path = path.format(**input.get("path", {}))
path_args = input.get("path", {})
path_args = (
path_args.model_dump() if isinstance(path_args, BaseModel) else path_args
)
formatted_path = path.format(**path_args)
headers = kwargs.get("headers", {})
headers.update(input.get("headers", {}))
params = {}
Expand Down
8 changes: 2 additions & 6 deletions ix/runnable/tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,8 @@ def test_input_with_path_args(self, schema):
"type": "object",
}
},
"properties": {
"args": {
"anyOf": [{"$ref": "#/$defs/DynamicModel"}, {"type": "null"}],
"default": None,
}
},
"properties": {"path": {"$ref": "#/$defs/DynamicModel"}},
"required": ["path"],
"title": "DynamicModel",
"type": "object",
}
Expand Down
8 changes: 4 additions & 4 deletions ix/utils/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_input_schema(
) -> Dict[str, Any]:
"""
Extracts the JSON schema for the input of a specified HTTP method, converts it to a valid JSON schema,
and uses references for nested objects named 'query', 'args', and 'body' (using the schema title if available).
and uses references for nested objects named 'query', 'path', and 'body' (using the schema title if available).
"""

def resolve_reference(schema, ref):
Expand Down Expand Up @@ -65,21 +65,21 @@ def extract_nested_objects(schema, definitions, definition_name):
method_item = path_item.get(method.lower(), {})

path_properties, path_required = convert_to_json_schema(
method_item.get("parameters", []), "path", result["definitions"], "Args"
method_item.get("parameters", []), "path", result["definitions"], "Path"
)
query_properties, query_required = convert_to_json_schema(
method_item.get("parameters", []), "query", result["definitions"], "Query"
)

if path_properties:
result["properties"]["args"] = extract_nested_objects(
result["properties"]["path"] = extract_nested_objects(
{
"type": "object",
"properties": path_properties,
"required": path_required,
},
result["definitions"],
"Args",
"Path",
)

if query_properties:
Expand Down
4 changes: 2 additions & 2 deletions ix/utils/tests/mock_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,15 @@

GET_DETAIL_SCHEMA = {
"definitions": {
"Args": {
"Path": {
"properties": {
"chain_id": {"format": "uuid", "title": "Chain Id", "type": "string"}
},
"required": ["chain_id"],
"type": "object",
}
},
"properties": {"args": {"$ref": "#/definitions/Args"}},
"properties": {"path": {"$ref": "#/definitions/Path"}},
"required": ["path"],
"type": "object",
}

0 comments on commit d414f98

Please sign in to comment.