chore: improve swagger markdown optional fields typing (#36247)

This commit is contained in:
chariri
2026-05-17 01:40:20 +09:00
committed by GitHub
parent 41b6f894c0
commit 9d0906c684
5 changed files with 991 additions and 933 deletions

View File

@ -47,6 +47,13 @@ class QueryModel(BaseModel):
ambiguous: int | str | None = Field(default=None, description="Ambiguous query parameter")
class NullableSchemaModel(BaseModel):
name: str | None = None
tags: list[str] | None = None
owner: UserModel | None = None
ambiguous: int | str | None = None
class ResponseAliasModel(BaseModel):
public_name: str = Field(validation_alias="internal_name")
@ -164,6 +171,27 @@ def test_register_response_schema_model_uses_serialized_field_names():
assert "internal_name" not in schema["properties"]
def test_register_schema_model_flattens_simple_nullable_any_of_for_swagger_2():
from controllers.common.schema import register_schema_model
namespace = MagicMock(spec=Namespace)
register_schema_model(namespace, NullableSchemaModel)
called_schemas = {call.args[0]: call.args[1] for call in namespace.schema_model.call_args_list}
properties = called_schemas["NullableSchemaModel"]["properties"]
assert properties["name"]["type"] == "string"
assert properties["name"]["x-nullable"] is True
assert "anyOf" not in properties["name"]
assert properties["tags"]["type"] == "array"
assert properties["tags"]["items"] == {"type": "string"}
assert properties["tags"]["x-nullable"] is True
assert properties["owner"]["$ref"] == "#/definitions/UserModel"
assert properties["owner"]["x-nullable"] is True
assert "anyOf" in properties["ambiguous"]
def test_get_or_create_model_returns_existing_model(mock_console_ns):
from controllers.common.schema import get_or_create_model