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

Commit ed6717b

Browse files
committed
Fixes bearer test
1 parent aeacdfe commit ed6717b

File tree

10 files changed

+226
-102
lines changed

10 files changed

+226
-102
lines changed

modules/openapi-json-schema-generator/src/main/resources/python/configuration.handlebars

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ class Configuration(object):
3737
The dict value is an API key prefix when generating the auth data.
3838
:param username: Username for HTTP basic authentication
3939
:param password: Password for HTTP basic authentication
40-
:param discard_unknown_keys: Boolean value indicating whether to discard
41-
unknown properties. A server may send a response that includes additional
42-
properties that are not known by the client in the following scenarios:
43-
1. The OpenAPI document is incomplete, i.e. it does not match the server
44-
implementation.
45-
2. The client was generated using an older version of the OpenAPI document
46-
and the server has been upgraded since then.
47-
If a schema in the OpenAPI document defines the additionalProperties attribute,
48-
then all undeclared properties received by the server are injected into the
49-
additional properties map. In that case, there are undeclared properties, and
50-
nothing to discard.
5140
:param disabled_client_side_validations (string): Comma-separated list of
5241
JSON schema validation keywords to disable JSON schema structural validation
5342
rules. The following keywords may be specified: multipleOf, maximum,
@@ -162,17 +151,29 @@ conf = {{{packageName}}}.Configuration(
162151

163152
_default = None
164153

165-
def __init__(self, host=None,
166-
api_key=None, api_key_prefix=None,
167-
username=None, password=None,
168-
discard_unknown_keys=False,
169-
disabled_client_side_validations="",
154+
def __init__(
155+
self,
156+
host=None,
157+
{{#if hasApiKeyMethods}}
158+
api_key=None,
159+
api_key_prefix=None,
160+
{{/if}}
161+
{{#if hasHttpBasicMethods}}
162+
username=None,
163+
password=None,
164+
{{/if}}
165+
disabled_client_side_validations="",
170166
{{#if hasHttpSignatureMethods}}
171-
signing_info=None,
167+
signing_info=None,
172168
{{/if}}
173-
server_index=None, server_variables=None,
174-
server_operation_index=None, server_operation_variables=None,
175-
):
169+
server_index=None,
170+
server_variables=None,
171+
server_operation_index=None,
172+
server_operation_variables=None,
173+
{{#or hasOAuthMethods hasBearerMethods}}
174+
access_token=None,
175+
{{/or}}
176+
):
176177
"""Constructor
177178
"""
178179
self._base_path = "{{{basePath}}}" if host is None else host
@@ -190,6 +191,7 @@ conf = {{{packageName}}}.Configuration(
190191
"""Temp file folder for downloading files
191192
"""
192193
# Authentication Settings
194+
{{#if hasApiKeyMethods}}
193195
self.api_key = {}
194196
if api_key:
195197
self.api_key = api_key
@@ -203,13 +205,15 @@ conf = {{{packageName}}}.Configuration(
203205
self.refresh_api_key_hook = None
204206
"""function hook to refresh API key if expired
205207
"""
208+
{{/if}}
209+
{{#if hasHttpBasicMethods}}
206210
self.username = username
207211
"""Username for HTTP basic authentication
208212
"""
209213
self.password = password
210214
"""Password for HTTP basic authentication
211215
"""
212-
self.discard_unknown_keys = discard_unknown_keys
216+
{{/if}}
213217
self.disabled_client_side_validations = disabled_client_side_validations
214218
{{#if hasHttpSignatureMethods}}
215219
if signing_info is not None:
@@ -218,18 +222,11 @@ conf = {{{packageName}}}.Configuration(
218222
"""The HTTP signing configuration
219223
"""
220224
{{/if}}
221-
{{#if hasOAuthMethods}}
222-
self.access_token = None
223-
"""access token for OAuth/Bearer
224-
"""
225-
{{/if}}
226-
{{#unless hasOAuthMethods}}
227-
{{#if hasBearerMethods}}
228-
self.access_token = None
225+
{{#or hasOAuthMethods hasBearerMethods}}
226+
self.access_token = access_token
229227
"""access token for OAuth/Bearer
230228
"""
231-
{{/if}}
232-
{{/unless}}
229+
{{/or}}
233230
self.logger = {}
234231
"""Logging Settings
235232
"""

modules/openapi-json-schema-generator/src/main/resources/python/doc_auth_partial.handlebars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ configuration.api_key['{{{name}}}'] = 'YOUR_API_KEY'
101101

102102
# Configure OAuth2 access token for authorization: {{{name}}}
103103
configuration = {{{packageName}}}.Configuration(
104-
host = "{{{basePath}}}"
104+
host = "{{{basePath}}}",
105+
access_token = 'YOUR_ACCESS_TOKEN'
105106
)
106-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
107107
{{/if}}
108108
{{/each}}
109109
{{/if}}

modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,16 @@ paths:
791791
description: Required String in group parameters
792792
required: true
793793
schema:
794-
type: integer
794+
type: string
795795
- name: required_boolean_group
796796
in: header
797797
description: Required Boolean in group parameters
798798
required: true
799799
schema:
800-
type: boolean
800+
type: string
801+
enum:
802+
- true
803+
- false
801804
- name: required_int64_group
802805
in: query
803806
description: Required Integer in group parameters
@@ -809,12 +812,15 @@ paths:
809812
in: query
810813
description: String in group parameters
811814
schema:
812-
type: integer
815+
type: string
813816
- name: boolean_group
814817
in: header
815818
description: Boolean in group parameters
816819
schema:
817-
type: boolean
820+
type: string
821+
enum:
822+
- true
823+
- false
818824
- name: int64_group
819825
in: query
820826
description: Integer in group parameters
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.2
1+
unset

samples/openapi3/client/petstore/python/docs/apis/tags/FakeApi.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,11 +1328,11 @@ with petstore_api.ApiClient(configuration) as api_client:
13281328

13291329
# example passing only required values which don't have defaults set
13301330
query_params = {
1331-
'required_string_group': 1,
1331+
'required_string_group': "required_string_group_example",
13321332
'required_int64_group': 1,
13331333
}
13341334
header_params = {
1335-
'required_boolean_group': True,
1335+
'required_boolean_group': "true",
13361336
}
13371337
try:
13381338
# Fake endpoint to test group parameters (optional)
@@ -1345,14 +1345,14 @@ with petstore_api.ApiClient(configuration) as api_client:
13451345

13461346
# example passing only optional values
13471347
query_params = {
1348-
'required_string_group': 1,
1348+
'required_string_group': "required_string_group_example",
13491349
'required_int64_group': 1,
1350-
'string_group': 1,
1350+
'string_group': "string_group_example",
13511351
'int64_group': 1,
13521352
}
13531353
header_params = {
1354-
'required_boolean_group': True,
1355-
'boolean_group': True,
1354+
'required_boolean_group': "true",
1355+
'boolean_group': "true",
13561356
}
13571357
try:
13581358
# Fake endpoint to test group parameters (optional)
@@ -1389,7 +1389,7 @@ int64_group | Int64GroupSchema | | optional
13891389
## Model Type Info
13901390
Input Type | Accessed Type | Description | Notes
13911391
------------ | ------------- | ------------- | -------------
1392-
decimal.Decimal, int, | decimal.Decimal, | |
1392+
str, | str, | |
13931393

13941394
# RequiredInt64GroupSchema
13951395

@@ -1403,7 +1403,7 @@ decimal.Decimal, int, | decimal.Decimal, | | value must be a 64 bit integer
14031403
## Model Type Info
14041404
Input Type | Accessed Type | Description | Notes
14051405
------------ | ------------- | ------------- | -------------
1406-
decimal.Decimal, int, | decimal.Decimal, | |
1406+
str, | str, | |
14071407

14081408
# Int64GroupSchema
14091409

@@ -1425,14 +1425,14 @@ boolean_group | BooleanGroupSchema | | optional
14251425
## Model Type Info
14261426
Input Type | Accessed Type | Description | Notes
14271427
------------ | ------------- | ------------- | -------------
1428-
bool, | BoolClass, | |
1428+
str, | str, | | must be one of ["true", "false", ]
14291429

14301430
# BooleanGroupSchema
14311431

14321432
## Model Type Info
14331433
Input Type | Accessed Type | Description | Notes
14341434
------------ | ------------- | ------------- | -------------
1435-
bool, | BoolClass, | |
1435+
str, | str, | | must be one of ["true", "false", ]
14361436

14371437
### Return Types, Responses
14381438

samples/openapi3/client/petstore/python/docs/apis/tags/PetApi.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ configuration = petstore_api.Configuration(
104104

105105
# Configure OAuth2 access token for authorization: petstore_auth
106106
configuration = petstore_api.Configuration(
107-
host = "http://petstore.swagger.io:80/v2"
107+
host = "http://petstore.swagger.io:80/v2",
108+
access_token = 'YOUR_ACCESS_TOKEN'
108109
)
109-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
110110
# Enter a context with an instance of the API client
111111
with petstore_api.ApiClient(configuration) as api_client:
112112
# Create an instance of the API class
@@ -218,9 +218,9 @@ configuration = petstore_api.Configuration(
218218

219219
# Configure OAuth2 access token for authorization: petstore_auth
220220
configuration = petstore_api.Configuration(
221-
host = "http://petstore.swagger.io:80/v2"
221+
host = "http://petstore.swagger.io:80/v2",
222+
access_token = 'YOUR_ACCESS_TOKEN'
222223
)
223-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
224224
# Enter a context with an instance of the API client
225225
with petstore_api.ApiClient(configuration) as api_client:
226226
# Create an instance of the API class
@@ -404,9 +404,9 @@ configuration = petstore_api.Configuration(
404404

405405
# Configure OAuth2 access token for authorization: petstore_auth
406406
configuration = petstore_api.Configuration(
407-
host = "http://petstore.swagger.io:80/v2"
407+
host = "http://petstore.swagger.io:80/v2",
408+
access_token = 'YOUR_ACCESS_TOKEN'
408409
)
409-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
410410
# Enter a context with an instance of the API client
411411
with petstore_api.ApiClient(configuration) as api_client:
412412
# Create an instance of the API class
@@ -598,9 +598,9 @@ configuration = petstore_api.Configuration(
598598

599599
# Configure OAuth2 access token for authorization: petstore_auth
600600
configuration = petstore_api.Configuration(
601-
host = "http://petstore.swagger.io:80/v2"
601+
host = "http://petstore.swagger.io:80/v2",
602+
access_token = 'YOUR_ACCESS_TOKEN'
602603
)
603-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
604604
# Enter a context with an instance of the API client
605605
with petstore_api.ApiClient(configuration) as api_client:
606606
# Create an instance of the API class
@@ -912,9 +912,9 @@ configuration = petstore_api.Configuration(
912912

913913
# Configure OAuth2 access token for authorization: petstore_auth
914914
configuration = petstore_api.Configuration(
915-
host = "http://petstore.swagger.io:80/v2"
915+
host = "http://petstore.swagger.io:80/v2",
916+
access_token = 'YOUR_ACCESS_TOKEN'
916917
)
917-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
918918
# Enter a context with an instance of the API client
919919
with petstore_api.ApiClient(configuration) as api_client:
920920
# Create an instance of the API class
@@ -1034,9 +1034,9 @@ configuration = petstore_api.Configuration(
10341034

10351035
# Configure OAuth2 access token for authorization: petstore_auth
10361036
configuration = petstore_api.Configuration(
1037-
host = "http://petstore.swagger.io:80/v2"
1037+
host = "http://petstore.swagger.io:80/v2",
1038+
access_token = 'YOUR_ACCESS_TOKEN'
10381039
)
1039-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
10401040
# Enter a context with an instance of the API client
10411041
with petstore_api.ApiClient(configuration) as api_client:
10421042
# Create an instance of the API class
@@ -1159,9 +1159,9 @@ configuration = petstore_api.Configuration(
11591159

11601160
# Configure OAuth2 access token for authorization: petstore_auth
11611161
configuration = petstore_api.Configuration(
1162-
host = "http://petstore.swagger.io:80/v2"
1162+
host = "http://petstore.swagger.io:80/v2",
1163+
access_token = 'YOUR_ACCESS_TOKEN'
11631164
)
1164-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
11651165
# Enter a context with an instance of the API client
11661166
with petstore_api.ApiClient(configuration) as api_client:
11671167
# Create an instance of the API class
@@ -1293,9 +1293,9 @@ configuration = petstore_api.Configuration(
12931293

12941294
# Configure OAuth2 access token for authorization: petstore_auth
12951295
configuration = petstore_api.Configuration(
1296-
host = "http://petstore.swagger.io:80/v2"
1296+
host = "http://petstore.swagger.io:80/v2",
1297+
access_token = 'YOUR_ACCESS_TOKEN'
12971298
)
1298-
configuration.access_token = 'YOUR_ACCESS_TOKEN'
12991299
# Enter a context with an instance of the API client
13001300
with petstore_api.ApiClient(configuration) as api_client:
13011301
# Create an instance of the API class

samples/openapi3/client/petstore/python/petstore_api/configuration.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,6 @@ class Configuration(object):
4242
The dict value is an API key prefix when generating the auth data.
4343
:param username: Username for HTTP basic authentication
4444
:param password: Password for HTTP basic authentication
45-
:param discard_unknown_keys: Boolean value indicating whether to discard
46-
unknown properties. A server may send a response that includes additional
47-
properties that are not known by the client in the following scenarios:
48-
1. The OpenAPI document is incomplete, i.e. it does not match the server
49-
implementation.
50-
2. The client was generated using an older version of the OpenAPI document
51-
and the server has been upgraded since then.
52-
If a schema in the OpenAPI document defines the additionalProperties attribute,
53-
then all undeclared properties received by the server are injected into the
54-
additional properties map. In that case, there are undeclared properties, and
55-
nothing to discard.
5645
:param disabled_client_side_validations (string): Comma-separated list of
5746
JSON schema validation keywords to disable JSON schema structural validation
5847
rules. The following keywords may be specified: multipleOf, maximum,
@@ -157,15 +146,21 @@ class Configuration(object):
157146

158147
_default = None
159148

160-
def __init__(self, host=None,
161-
api_key=None, api_key_prefix=None,
162-
username=None, password=None,
163-
discard_unknown_keys=False,
164-
disabled_client_side_validations="",
165-
signing_info=None,
166-
server_index=None, server_variables=None,
167-
server_operation_index=None, server_operation_variables=None,
168-
):
149+
def __init__(
150+
self,
151+
host=None,
152+
api_key=None,
153+
api_key_prefix=None,
154+
username=None,
155+
password=None,
156+
disabled_client_side_validations="",
157+
signing_info=None,
158+
server_index=None,
159+
server_variables=None,
160+
server_operation_index=None,
161+
server_operation_variables=None,
162+
access_token=None,
163+
):
169164
"""Constructor
170165
"""
171166
self._base_path = "http://petstore.swagger.io:80/v2" if host is None else host
@@ -202,14 +197,13 @@ def __init__(self, host=None,
202197
self.password = password
203198
"""Password for HTTP basic authentication
204199
"""
205-
self.discard_unknown_keys = discard_unknown_keys
206200
self.disabled_client_side_validations = disabled_client_side_validations
207201
if signing_info is not None:
208202
signing_info.host = host
209203
self.signing_info = signing_info
210204
"""The HTTP signing configuration
211205
"""
212-
self.access_token = None
206+
self.access_token = access_token
213207
"""access token for OAuth/Bearer
214208
"""
215209
self.logger = {}

0 commit comments

Comments
 (0)