Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit cd0e960

Browse files
committed
Writes content_type on one line if there is only one
1 parent f3405fb commit cd0e960

File tree

62 files changed

+397
-413
lines changed

Some content is hidden

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

62 files changed

+397
-413
lines changed

modules/openapi-json-schema-generator/src/main/resources/python/paths/path/verb/_helper_operation_args.hbs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@
55
{{#with requestBody}}
66
{{#if refInfo}}
77
{{#with getDeepestRef}}
8+
{{#eq content.size 1}}
9+
content_type: typing_extensions.Literal[{{#each content}}"{{@key.original}}"{{/each}}] = {{#each content}}{{#if @first}}"{{@key.original}}"{{/if}}{{/each}},
10+
{{else}}
811
content_type: typing_extensions.Literal[
912
{{#each content}}
1013
"{{@key.original}}",
1114
{{/each}}
1215
] = {{#each content}}{{#if @first}}"{{@key.original}}"{{/if}}{{/each}},
16+
{{/eq}}
1317
{{/with}}
1418
{{else}}
19+
{{#eq content.size 1}}
20+
content_type: typing_extensions.Literal[{{#each content}}"{{@key.original}}"{{/each}}] = {{#each content}}{{#if @first}}"{{@key.original}}"{{/if}}{{/each}},
21+
{{else}}
1522
content_type: typing_extensions.Literal[
1623
{{#each content}}
1724
"{{@key.original}}",
1825
{{/each}}
1926
] = {{#each content}}{{#if @first}}"{{@key.original}}"{{/if}}{{/each}},
27+
{{/eq}}
2028
{{/if}}
2129
{{/with}}
2230
{{/if}}

modules/openapi-json-schema-generator/src/main/resources/python/paths/path/verb/operation.hbs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,14 @@ class BaseApi(api_client.Api):
300300
{{/if}}
301301
{{#if statusCodeResponses}}
302302
if status in _status_code_to_response:
303-
status: typing_extensions.Literal[
303+
status = typing.cast(
304+
typing_extensions.Literal[
304305
{{#each statusCodeResponses}}
305306
'{{@key}}',
306307
{{/each}}
307-
]
308+
],
309+
status
310+
)
308311
response = _status_code_to_response[status].deserialize(
309312
raw_response, self.api_client.schema_configuration)
310313
{{#if wildcardCodeResponses}}

samples/openapi3/client/petstore/python/src/petstore_api/paths/another_fake_dummy/patch/operation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def _call_123_test__special_tags(
3737
dict,
3838
frozendict.frozendict
3939
],
40-
content_type: typing_extensions.Literal[
41-
"application/json",
42-
] = "application/json",
40+
content_type: typing_extensions.Literal["application/json"] = "application/json",
4341
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4442
server_index: typing.Optional[int] = None,
4543
stream: bool = False,
@@ -55,9 +53,7 @@ def _call_123_test__special_tags(
5553
dict,
5654
frozendict.frozendict
5755
],
58-
content_type: typing_extensions.Literal[
59-
"application/json",
60-
] = "application/json",
56+
content_type: typing_extensions.Literal["application/json"] = "application/json",
6157
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
6258
server_index: typing.Optional[int] = None,
6359
stream: bool = False,
@@ -72,9 +68,7 @@ def _call_123_test__special_tags(
7268
dict,
7369
frozendict.frozendict
7470
],
75-
content_type: typing_extensions.Literal[
76-
"application/json",
77-
] = "application/json",
71+
content_type: typing_extensions.Literal["application/json"] = "application/json",
7872
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
7973
server_index: typing.Optional[int] = None,
8074
stream: bool = False,
@@ -117,9 +111,12 @@ class instances
117111
else:
118112
status = str(raw_response.status)
119113
if status in _status_code_to_response:
120-
status: typing_extensions.Literal[
114+
status = typing.cast(
115+
typing_extensions.Literal[
121116
'200',
122-
]
117+
],
118+
status
119+
)
123120
response = _status_code_to_response[status].deserialize(
124121
raw_response, self.api_client.schema_configuration)
125122
else:

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/operation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,12 @@ class instances
167167
else:
168168
status = str(raw_response.status)
169169
if status in _status_code_to_response:
170-
status: typing_extensions.Literal[
170+
status = typing.cast(
171+
typing_extensions.Literal[
171172
'200',
172-
]
173+
],
174+
status
175+
)
173176
response = _status_code_to_response[status].deserialize(
174177
raw_response, self.api_client.schema_configuration)
175178
else:

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/operation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ def _enum_parameters(
107107
] = schemas.unset,
108108
query_params: typing.Optional[RequestQueryParameters.Params] = None,
109109
header_params: typing.Optional[RequestHeaderParameters.Params] = None,
110-
content_type: typing_extensions.Literal[
111-
"application/x-www-form-urlencoded",
112-
] = "application/x-www-form-urlencoded",
110+
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
113111
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
114112
server_index: typing.Optional[int] = None,
115113
stream: bool = False,
@@ -128,9 +126,7 @@ def _enum_parameters(
128126
] = schemas.unset,
129127
query_params: typing.Optional[RequestQueryParameters.Params] = None,
130128
header_params: typing.Optional[RequestHeaderParameters.Params] = None,
131-
content_type: typing_extensions.Literal[
132-
"application/x-www-form-urlencoded",
133-
] = "application/x-www-form-urlencoded",
129+
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
134130
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
135131
server_index: typing.Optional[int] = None,
136132
stream: bool = False,
@@ -148,9 +144,7 @@ def _enum_parameters(
148144
] = schemas.unset,
149145
query_params: typing.Optional[RequestQueryParameters.Params] = None,
150146
header_params: typing.Optional[RequestHeaderParameters.Params] = None,
151-
content_type: typing_extensions.Literal[
152-
"application/x-www-form-urlencoded",
153-
] = "application/x-www-form-urlencoded",
147+
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
154148
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
155149
server_index: typing.Optional[int] = None,
156150
stream: bool = False,
@@ -203,10 +197,13 @@ class instances
203197
else:
204198
status = str(raw_response.status)
205199
if status in _status_code_to_response:
206-
status: typing_extensions.Literal[
200+
status = typing.cast(
201+
typing_extensions.Literal[
207202
'200',
208203
'404',
209-
]
204+
],
205+
status
206+
)
210207
response = _status_code_to_response[status].deserialize(
211208
raw_response, self.api_client.schema_configuration)
212209
else:

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/patch/operation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def _client_model(
3737
dict,
3838
frozendict.frozendict
3939
],
40-
content_type: typing_extensions.Literal[
41-
"application/json",
42-
] = "application/json",
40+
content_type: typing_extensions.Literal["application/json"] = "application/json",
4341
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4442
server_index: typing.Optional[int] = None,
4543
stream: bool = False,
@@ -55,9 +53,7 @@ def _client_model(
5553
dict,
5654
frozendict.frozendict
5755
],
58-
content_type: typing_extensions.Literal[
59-
"application/json",
60-
] = "application/json",
56+
content_type: typing_extensions.Literal["application/json"] = "application/json",
6157
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
6258
server_index: typing.Optional[int] = None,
6359
stream: bool = False,
@@ -72,9 +68,7 @@ def _client_model(
7268
dict,
7369
frozendict.frozendict
7470
],
75-
content_type: typing_extensions.Literal[
76-
"application/json",
77-
] = "application/json",
71+
content_type: typing_extensions.Literal["application/json"] = "application/json",
7872
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
7973
server_index: typing.Optional[int] = None,
8074
stream: bool = False,
@@ -117,9 +111,12 @@ class instances
117111
else:
118112
status = str(raw_response.status)
119113
if status in _status_code_to_response:
120-
status: typing_extensions.Literal[
114+
status = typing.cast(
115+
typing_extensions.Literal[
121116
'200',
122-
]
117+
],
118+
status
119+
)
123120
response = _status_code_to_response[status].deserialize(
124121
raw_response, self.api_client.schema_configuration)
125122
else:

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/post/operation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ def _endpoint_parameters(
4444
dict,
4545
frozendict.frozendict
4646
] = schemas.unset,
47-
content_type: typing_extensions.Literal[
48-
"application/x-www-form-urlencoded",
49-
] = "application/x-www-form-urlencoded",
47+
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
5048
security_index: typing.Optional[int] = None,
5149
server_index: typing.Optional[int] = None,
5250
stream: bool = False,
@@ -63,9 +61,7 @@ def _endpoint_parameters(
6361
dict,
6462
frozendict.frozendict
6563
] = schemas.unset,
66-
content_type: typing_extensions.Literal[
67-
"application/x-www-form-urlencoded",
68-
] = "application/x-www-form-urlencoded",
64+
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
6965
security_index: typing.Optional[int] = None,
7066
server_index: typing.Optional[int] = None,
7167
stream: bool = False,
@@ -81,9 +77,7 @@ def _endpoint_parameters(
8177
dict,
8278
frozendict.frozendict
8379
] = schemas.unset,
84-
content_type: typing_extensions.Literal[
85-
"application/x-www-form-urlencoded",
86-
] = "application/x-www-form-urlencoded",
80+
content_type: typing_extensions.Literal["application/x-www-form-urlencoded"] = "application/x-www-form-urlencoded",
8781
security_index: typing.Optional[int] = None,
8882
server_index: typing.Optional[int] = None,
8983
stream: bool = False,
@@ -132,10 +126,13 @@ class instances
132126
else:
133127
status = str(raw_response.status)
134128
if status in _status_code_to_response:
135-
status: typing_extensions.Literal[
129+
status = typing.cast(
130+
typing_extensions.Literal[
136131
'200',
137132
'404',
138-
]
133+
],
134+
status
135+
)
139136
response = _status_code_to_response[status].deserialize(
140137
raw_response, self.api_client.schema_configuration)
141138
else:

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_additional_properties_with_array_of_enums/get/operation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ def _additional_properties_with_array_of_enums(
3838
dict,
3939
frozendict.frozendict
4040
] = schemas.unset,
41-
content_type: typing_extensions.Literal[
42-
"application/json",
43-
] = "application/json",
41+
content_type: typing_extensions.Literal["application/json"] = "application/json",
4442
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
4543
server_index: typing.Optional[int] = None,
4644
stream: bool = False,
@@ -57,9 +55,7 @@ def _additional_properties_with_array_of_enums(
5755
dict,
5856
frozendict.frozendict
5957
] = schemas.unset,
60-
content_type: typing_extensions.Literal[
61-
"application/json",
62-
] = "application/json",
58+
content_type: typing_extensions.Literal["application/json"] = "application/json",
6359
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
6460
server_index: typing.Optional[int] = None,
6561
stream: bool = False,
@@ -75,9 +71,7 @@ def _additional_properties_with_array_of_enums(
7571
dict,
7672
frozendict.frozendict
7773
] = schemas.unset,
78-
content_type: typing_extensions.Literal[
79-
"application/json",
80-
] = "application/json",
74+
content_type: typing_extensions.Literal["application/json"] = "application/json",
8175
accept_content_types: typing.Tuple[str, ...] = _all_accept_content_types,
8276
server_index: typing.Optional[int] = None,
8377
stream: bool = False,
@@ -120,9 +114,12 @@ class instances
120114
else:
121115
status = str(raw_response.status)
122116
if status in _status_code_to_response:
123-
status: typing_extensions.Literal[
117+
status = typing.cast(
118+
typing_extensions.Literal[
124119
'200',
125-
]
120+
],
121+
status
122+
)
126123
response = _status_code_to_response[status].deserialize(
127124
raw_response, self.api_client.schema_configuration)
128125
else:

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_body_with_file_schema/put/operation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def _body_with_file_schema(
3333
dict,
3434
frozendict.frozendict
3535
],
36-
content_type: typing_extensions.Literal[
37-
"application/json",
38-
] = "application/json",
36+
content_type: typing_extensions.Literal["application/json"] = "application/json",
3937
server_index: typing.Optional[int] = None,
4038
stream: bool = False,
4139
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -50,9 +48,7 @@ def _body_with_file_schema(
5048
dict,
5149
frozendict.frozendict
5250
],
53-
content_type: typing_extensions.Literal[
54-
"application/json",
55-
] = "application/json",
51+
content_type: typing_extensions.Literal["application/json"] = "application/json",
5652
server_index: typing.Optional[int] = None,
5753
stream: bool = False,
5854
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -66,9 +62,7 @@ def _body_with_file_schema(
6662
dict,
6763
frozendict.frozendict
6864
],
69-
content_type: typing_extensions.Literal[
70-
"application/json",
71-
] = "application/json",
65+
content_type: typing_extensions.Literal["application/json"] = "application/json",
7266
server_index: typing.Optional[int] = None,
7367
stream: bool = False,
7468
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -109,9 +103,12 @@ class instances
109103
else:
110104
status = str(raw_response.status)
111105
if status in _status_code_to_response:
112-
status: typing_extensions.Literal[
106+
status = typing.cast(
107+
typing_extensions.Literal[
113108
'200',
114-
]
109+
],
110+
status
111+
)
115112
response = _status_code_to_response[status].deserialize(
116113
raw_response, self.api_client.schema_configuration)
117114
else:

samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_body_with_query_params/put/operation.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ def _body_with_query_params(
5858
frozendict.frozendict
5959
],
6060
query_params: RequestQueryParameters.Params,
61-
content_type: typing_extensions.Literal[
62-
"application/json",
63-
] = "application/json",
61+
content_type: typing_extensions.Literal["application/json"] = "application/json",
6462
server_index: typing.Optional[int] = None,
6563
stream: bool = False,
6664
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -76,9 +74,7 @@ def _body_with_query_params(
7674
frozendict.frozendict
7775
],
7876
query_params: RequestQueryParameters.Params,
79-
content_type: typing_extensions.Literal[
80-
"application/json",
81-
] = "application/json",
77+
content_type: typing_extensions.Literal["application/json"] = "application/json",
8278
server_index: typing.Optional[int] = None,
8379
stream: bool = False,
8480
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -93,9 +89,7 @@ def _body_with_query_params(
9389
frozendict.frozendict
9490
],
9591
query_params: RequestQueryParameters.Params,
96-
content_type: typing_extensions.Literal[
97-
"application/json",
98-
] = "application/json",
92+
content_type: typing_extensions.Literal["application/json"] = "application/json",
9993
server_index: typing.Optional[int] = None,
10094
stream: bool = False,
10195
timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
@@ -141,9 +135,12 @@ class instances
141135
else:
142136
status = str(raw_response.status)
143137
if status in _status_code_to_response:
144-
status: typing_extensions.Literal[
138+
status = typing.cast(
139+
typing_extensions.Literal[
145140
'200',
146-
]
141+
],
142+
status
143+
)
147144
response = _status_code_to_response[status].deserialize(
148145
raw_response, self.api_client.schema_configuration)
149146
else:

0 commit comments

Comments
 (0)