Skip to content

correctly resolve references to a type that is itself just a single allOf reference #1103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
default: patch
---

# Correctly resolve references to a type that is itself just a single allOf reference

PR #1103 fixed issue #1091. Thanks @eli-bl!
44 changes: 44 additions & 0 deletions end_to_end_tests/baseline_openapi_3.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,33 @@
}
}
}
},
"/models/allof": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"aliased": {
"$ref": "#/components/schemas/Aliased"
},
"extended": {
"$ref": "#/components/schemas/Extended"
},
"model": {
"$ref": "#/components/schemas/AModel"
}
}
}
}
}
}
}
}
}
},
"components": {
Expand All @@ -1647,6 +1674,23 @@
"an_required_field"
]
},
"Aliased":{
"allOf": [
{"$ref": "#/components/schemas/AModel"}
]
},
"Extended": {
"allOf": [
{"$ref": "#/components/schemas/Aliased"},
{"type": "object",
"properties": {
"fromExtended": {
"type": "string"
}
}
}
]
},
"AModel": {
"title": "AModel",
"required": [
Expand Down
64 changes: 48 additions & 16 deletions end_to_end_tests/baseline_openapi_3.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,34 @@ info:
}
}
}
}
},
"/models/allof": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"aliased": {
"$ref": "#/components/schemas/Aliased"
},
"extended": {
"$ref": "#/components/schemas/Extended"
},
"model": {
"$ref": "#/components/schemas/AModel"
}
}
}
}
}
}
}
}
},
}
"components":
"schemas": {
Expand All @@ -1637,6 +1664,23 @@ info:
"an_required_field"
]
},
"Aliased": {
"allOf": [
{ "$ref": "#/components/schemas/AModel" }
]
},
"Extended": {
"allOf": [
{ "$ref": "#/components/schemas/Aliased" },
{ "type": "object",
"properties": {
"fromExtended": {
"type": "string"
}
}
}
]
},
"AModel": {
"title": "AModel",
"required": [
Expand Down Expand Up @@ -1667,11 +1711,7 @@ info:
"default": "overridden_default"
},
"an_optional_allof_enum": {
"allOf": [
{
"$ref": "#/components/schemas/AnAllOfEnum"
}
]
"$ref": "#/components/schemas/AnAllOfEnum",
},
"nested_list_of_enums": {
"title": "Nested List Of Enums",
Expand Down Expand Up @@ -1808,11 +1848,7 @@ info:
]
},
"model": {
"allOf": [
{
"$ref": "#/components/schemas/ModelWithUnionProperty"
}
]
"$ref": "#/components/schemas/ModelWithUnionProperty"
},
"nullable_model": {
"oneOf": [
Expand All @@ -1825,11 +1861,7 @@ info:
]
},
"not_required_model": {
"allOf": [
{
"$ref": "#/components/schemas/ModelWithUnionProperty"
}
]
"$ref": "#/components/schemas/ModelWithUnionProperty"
},
"not_required_nullable_model": {
"oneOf": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import types

from . import get_common_parameters, post_common_parameters, reserved_parameters
from . import get_common_parameters, get_models_allof, post_common_parameters, reserved_parameters


class DefaultEndpoints:
Expand All @@ -17,3 +17,7 @@ def post_common_parameters(cls) -> types.ModuleType:
@classmethod
def reserved_parameters(cls) -> types.ModuleType:
return reserved_parameters

@classmethod
def get_models_allof(cls) -> types.ModuleType:
return get_models_allof
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.get_models_allof_response_200 import GetModelsAllofResponse200
from ...types import Response


def _get_kwargs() -> Dict[str, Any]:
_kwargs: Dict[str, Any] = {
"method": "get",
"url": "/models/allof",
}

return _kwargs


def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[GetModelsAllofResponse200]:
if response.status_code == HTTPStatus.OK:
response_200 = GetModelsAllofResponse200.from_dict(response.json())

return response_200
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[GetModelsAllofResponse200]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: Union[AuthenticatedClient, Client],
) -> Response[GetModelsAllofResponse200]:
"""
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[GetModelsAllofResponse200]
"""

kwargs = _get_kwargs()

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
*,
client: Union[AuthenticatedClient, Client],
) -> Optional[GetModelsAllofResponse200]:
"""
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
GetModelsAllofResponse200
"""

return sync_detailed(
client=client,
).parsed


async def asyncio_detailed(
*,
client: Union[AuthenticatedClient, Client],
) -> Response[GetModelsAllofResponse200]:
"""
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[GetModelsAllofResponse200]
"""

kwargs = _get_kwargs()

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
*,
client: Union[AuthenticatedClient, Client],
) -> Optional[GetModelsAllofResponse200]:
"""
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
GetModelsAllofResponse200
"""

return (
await asyncio_detailed(
client=client,
)
).parsed
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
from .body_upload_file_tests_upload_post_some_object import BodyUploadFileTestsUploadPostSomeObject
from .body_upload_file_tests_upload_post_some_optional_object import BodyUploadFileTestsUploadPostSomeOptionalObject
from .different_enum import DifferentEnum
from .extended import Extended
from .free_form_model import FreeFormModel
from .get_location_header_types_int_enum_header import GetLocationHeaderTypesIntEnumHeader
from .get_location_header_types_string_enum_header import GetLocationHeaderTypesStringEnumHeader
from .get_models_allof_response_200 import GetModelsAllofResponse200
from .http_validation_error import HTTPValidationError
from .import_ import Import
from .json_like_body import JsonLikeBody
Expand Down Expand Up @@ -111,9 +113,11 @@
"BodyUploadFileTestsUploadPostSomeObject",
"BodyUploadFileTestsUploadPostSomeOptionalObject",
"DifferentEnum",
"Extended",
"FreeFormModel",
"GetLocationHeaderTypesIntEnumHeader",
"GetLocationHeaderTypesStringEnumHeader",
"GetModelsAllofResponse200",
"HTTPValidationError",
"Import",
"JsonLikeBody",
Expand Down
Loading
Loading