Skip to content

Commit 05367ca

Browse files
obs-gh-peterkollochgoodsonjr
authored andcommitted
Support simple patterned and default http status codes
Co-Authored-By: Jonathan Goodson <[email protected]> Co-Authored-By: Peter Kolloch <[email protected]>
1 parent 8f5f11f commit 05367ca

File tree

71 files changed

+1023
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1023
-140
lines changed

end_to_end_tests/__snapshots__/test_end_to_end.ambr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
WARNING parsing GET / within default.
88

9-
Invalid response status code abcdef (not a valid HTTP status code), response will be omitted from generated client
9+
Invalid response status code pattern: abcdef, response will be omitted from generated client
1010

1111

1212
If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose

end_to_end_tests/baseline_openapi_3.0.json

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@
402402
"some_nullable_object",
403403
"some_required_number"
404404
],
405-
"properties": {
406-
}
405+
"properties": {}
407406
}
408407
}
409408
},
@@ -975,6 +974,124 @@
975974
}
976975
}
977976
},
977+
"/responses/status-codes/default": {
978+
"get": {
979+
"tags": [
980+
"responses"
981+
],
982+
"summary": "Default Status Code Only",
983+
"operationId": "default_status_code",
984+
"responses": {
985+
"default": {
986+
"description": "Default response",
987+
"content": {
988+
"text/plain": {
989+
"schema": {
990+
"type": "string"
991+
}
992+
}
993+
}
994+
}
995+
}
996+
}
997+
},
998+
"/response/status-codes/patterns": {
999+
"get": {
1000+
"tags": [
1001+
"responses"
1002+
],
1003+
"summary": "Status Code Patterns",
1004+
"operationId": "status_code_patterns",
1005+
"responses": {
1006+
"2XX": {
1007+
"description": "Successful Response",
1008+
"content": {
1009+
"application/json": {
1010+
"schema": {
1011+
"type": "object",
1012+
"properties": {
1013+
"status": {
1014+
"type": "string",
1015+
"enum": [
1016+
"success",
1017+
"failure"
1018+
]
1019+
}
1020+
}
1021+
}
1022+
}
1023+
}
1024+
},
1025+
"4XX": {
1026+
"description": "Bad Request",
1027+
"content": {
1028+
"application/json": {
1029+
"schema": {
1030+
"type": "object",
1031+
"properties": {
1032+
"error": {
1033+
"type": "string"
1034+
}
1035+
}
1036+
}
1037+
}
1038+
}
1039+
}
1040+
}
1041+
}
1042+
},
1043+
"/response/status-codes/precedence": {
1044+
"get": {
1045+
"operationId": "status_code_precedence",
1046+
"tags": [
1047+
"responses"
1048+
],
1049+
"summary": "Status Codes Precedence",
1050+
"description": "Verify that specific status codes are always checked first, then ranges, then default",
1051+
"responses": {
1052+
"default": {
1053+
"description": "Default Response Should Be Last",
1054+
"content": {
1055+
"text/plain": {
1056+
"schema": {
1057+
"type": "string"
1058+
}
1059+
}
1060+
}
1061+
},
1062+
"4XX": {
1063+
"description": "Pattern should be after specific codes",
1064+
"content": {
1065+
"text/plain": {
1066+
"schema": {
1067+
"type": "string"
1068+
}
1069+
}
1070+
}
1071+
},
1072+
"404": {
1073+
"description": "Not Found",
1074+
"content": {
1075+
"text/plain": {
1076+
"schema": {
1077+
"type": "string"
1078+
}
1079+
}
1080+
}
1081+
},
1082+
"200": {
1083+
"description": "OK",
1084+
"content": {
1085+
"text/plain": {
1086+
"schema": {
1087+
"type": "string"
1088+
}
1089+
}
1090+
}
1091+
}
1092+
}
1093+
}
1094+
},
9781095
"/auth/token_with_cookie": {
9791096
"get": {
9801097
"tags": [
@@ -1133,7 +1250,10 @@
11331250
},
11341251
"/tag_with_number": {
11351252
"get": {
1136-
"tags": ["1", "2"],
1253+
"tags": [
1254+
"1",
1255+
"2"
1256+
],
11371257
"responses": {
11381258
"200": {
11391259
"description": "Success"
@@ -1668,7 +1788,9 @@
16681788
"type": "string"
16691789
}
16701790
},
1671-
"required": ["type"]
1791+
"required": [
1792+
"type"
1793+
]
16721794
},
16731795
{
16741796
"type": "object",
@@ -1680,7 +1802,9 @@
16801802
"type": "string"
16811803
}
16821804
},
1683-
"required": ["type"]
1805+
"required": [
1806+
"type"
1807+
]
16841808
}
16851809
]
16861810
}

end_to_end_tests/baseline_openapi_3.1.yaml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,115 @@ info:
958958
}
959959
}
960960
},
961+
"/responses/status-codes/default": {
962+
"get": {
963+
"tags": ["responses"],
964+
"summary": "Default Status Code Only",
965+
"operationId": "default_status_code",
966+
"responses": {
967+
"default": {
968+
"description": "Default response",
969+
"content": {
970+
"text/plain": {
971+
"schema": {
972+
"type": "string"
973+
}
974+
}
975+
}
976+
}
977+
}
978+
}
979+
},
980+
"/response/status-codes/patterns": {
981+
"get": {
982+
"tags": ["responses"],
983+
"summary": "Status Code Patterns",
984+
"operationId": "status_code_patterns",
985+
"responses": {
986+
"2XX": {
987+
"description": "Successful Response",
988+
"content": {
989+
"application/json": {
990+
"schema": {
991+
"type": "object",
992+
"properties": {
993+
"status": {
994+
"type": "string",
995+
"enum": ["success", "failure"]
996+
}
997+
}
998+
}
999+
}
1000+
}
1001+
},
1002+
"4XX": {
1003+
"description": "Bad Request",
1004+
"content": {
1005+
"application/json": {
1006+
"schema": {
1007+
"type": "object",
1008+
"properties": {
1009+
"error": {
1010+
"type": "string"
1011+
}
1012+
}
1013+
}
1014+
}
1015+
}
1016+
}
1017+
}
1018+
}
1019+
},
1020+
"/response/status-codes/precedence": {
1021+
"get": {
1022+
"operationId": "status_code_precedence",
1023+
"tags": ["responses"],
1024+
"summary": "Status Codes Precedence",
1025+
"description": "Verify that specific status codes are always checked first, then ranges, then default",
1026+
"responses": {
1027+
"default": {
1028+
"description": "Default Response Should Be Last",
1029+
"content": {
1030+
"text/plain": {
1031+
"schema": {
1032+
"type": "string"
1033+
}
1034+
}
1035+
}
1036+
},
1037+
"4XX": {
1038+
"description": "Pattern should be after specific codes",
1039+
"content": {
1040+
"text/plain": {
1041+
"schema": {
1042+
"type": "string"
1043+
}
1044+
}
1045+
}
1046+
},
1047+
"404": {
1048+
"description": "Not Found",
1049+
"content": {
1050+
"text/plain": {
1051+
"schema": {
1052+
"type": "string"
1053+
}
1054+
}
1055+
}
1056+
},
1057+
"200": {
1058+
"description": "OK",
1059+
"content": {
1060+
"text/plain": {
1061+
"schema": {
1062+
"type": "string"
1063+
}
1064+
}
1065+
}
1066+
}
1067+
}
1068+
}
1069+
},
9611070
"/auth/token_with_cookie": {
9621071
"get": {
9631072
"tags": [

end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/responses/__init__.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import types
44

5-
from . import post_responses_unions_simple_before_complex, reference_response, text_response
5+
from . import (
6+
default_status_code,
7+
post_responses_unions_simple_before_complex,
8+
reference_response,
9+
status_code_patterns,
10+
status_code_precedence,
11+
text_response,
12+
)
613

714

815
class ResponsesEndpoints:
@@ -26,3 +33,24 @@ def reference_response(cls) -> types.ModuleType:
2633
Endpoint using predefined response
2734
"""
2835
return reference_response
36+
37+
@classmethod
38+
def default_status_code(cls) -> types.ModuleType:
39+
"""
40+
Default Status Code Only
41+
"""
42+
return default_status_code
43+
44+
@classmethod
45+
def status_code_patterns(cls) -> types.ModuleType:
46+
"""
47+
Status Code Patterns
48+
"""
49+
return status_code_patterns
50+
51+
@classmethod
52+
def status_code_precedence(cls) -> types.ModuleType:
53+
"""
54+
Verify that specific status codes are always checked first, then ranges, then default
55+
"""
56+
return status_code_precedence

end_to_end_tests/golden-record/my_test_api_client/api/bodies/json_like.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def _get_kwargs(
3131
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
3232
if response.status_code == 200:
3333
return None
34+
3435
if client.raise_on_unexpected_status:
3536
raise errors.UnexpectedStatus(response.status_code, response.content)
3637
else:

end_to_end_tests/golden-record/my_test_api_client/api/bodies/post_bodies_multiple.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def _get_kwargs(
5151
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
5252
if response.status_code == 200:
5353
return None
54+
5455
if client.raise_on_unexpected_status:
5556
raise errors.UnexpectedStatus(response.status_code, response.content)
5657
else:

end_to_end_tests/golden-record/my_test_api_client/api/bodies/refs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def _get_kwargs(
3131
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
3232
if response.status_code == 200:
3333
return None
34+
3435
if client.raise_on_unexpected_status:
3536
raise errors.UnexpectedStatus(response.status_code, response.content)
3637
else:

end_to_end_tests/golden-record/my_test_api_client/api/config/content_type_override.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def _parse_response(*, client: Union[AuthenticatedClient, Client], response: htt
3131
if response.status_code == 200:
3232
response_200 = cast(str, response.json())
3333
return response_200
34+
3435
if client.raise_on_unexpected_status:
3536
raise errors.UnexpectedStatus(response.status_code, response.content)
3637
else:

end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def _get_kwargs(
3030
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
3131
if response.status_code == 200:
3232
return None
33+
3334
if client.raise_on_unexpected_status:
3435
raise errors.UnexpectedStatus(response.status_code, response.content)
3536
else:

end_to_end_tests/golden-record/my_test_api_client/api/default/get_models_allof.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def _parse_response(
2525
response_200 = GetModelsAllofResponse200.from_dict(response.json())
2626

2727
return response_200
28+
2829
if client.raise_on_unexpected_status:
2930
raise errors.UnexpectedStatus(response.status_code, response.content)
3031
else:

0 commit comments

Comments
 (0)