Skip to content

Commit 9450627

Browse files
author
Doug Borg
committed
test: add coverage for relaxed body param handling & operationId path param underscores
1 parent 8657cf1 commit 9450627

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/test_service_generator.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ def test_generate_services(model_data):
380380
result = generate_services(model_data.paths, library_config_dict[HTTPLibrary.httpx])
381381
for i in result:
382382
compile(i.content, "<string>", "exec")
383+
result2 = generate_services(model_data.paths, library_config_dict[HTTPLibrary.requests])
384+
for i in result2:
385+
compile(i.content, "<string>", "exec")
383386

384387
result = generate_services(
385388
model_data.paths, library_config_dict[HTTPLibrary.requests]
@@ -439,3 +442,56 @@ def test_204_skip_parsing_all_libraries(library):
439442
assert "204 No Content" in content or "== 204 else" in content
440443
# Should contain 'return None'
441444
assert "return None" in content
445+
446+
447+
def test_generate_body_param_missing_type_object_like():
448+
"""Schema with properties but no explicit type should not raise and returns 'data'."""
449+
op = Operation(
450+
responses=default_responses, # type: ignore[arg-type]
451+
requestBody=RequestBody(
452+
content={
453+
"application/json": MediaType(
454+
media_type_schema=Schema(properties={"a": Schema(type=DataType.STRING)}) # type: ignore[arg-type]
455+
)
456+
}
457+
),
458+
)
459+
assert generate_body_param(op) == "data"
460+
461+
462+
def test_generate_body_param_array_primitive():
463+
op = Operation(
464+
responses=default_responses, # type: ignore[arg-type]
465+
requestBody=RequestBody(
466+
content={
467+
"application/json": MediaType(
468+
media_type_schema=Schema(type=DataType.ARRAY, items=Schema(type=DataType.STRING)) # type: ignore[arg-type]
469+
)
470+
}
471+
),
472+
)
473+
assert generate_body_param(op) == "data"
474+
475+
476+
def test_generate_body_param_array_object_like():
477+
op = Operation(
478+
responses=default_responses, # type: ignore[arg-type]
479+
requestBody=RequestBody(
480+
content={
481+
"application/json": MediaType(
482+
media_type_schema=Schema(
483+
type=DataType.ARRAY,
484+
items=Schema(type=DataType.OBJECT, properties={"a": Schema(type=DataType.STRING)}), # type: ignore[arg-type]
485+
)
486+
)
487+
}
488+
),
489+
)
490+
assert generate_body_param(op) == "[i.dict() for i in data]"
491+
492+
493+
def test_generate_operation_id_path_param_separator():
494+
path_name = "/lists/{listId}"
495+
op = Operation(responses=default_responses, operationId=None) # type: ignore[arg-type]
496+
op_id = generate_operation_id(op, "get", path_name)
497+
assert op_id == "get_lists_listId"

0 commit comments

Comments
 (0)