diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenSecurity.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenSecurity.java index 9b2d161fa36..b0cbc09c88e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenSecurity.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenSecurity.java @@ -29,6 +29,7 @@ public class CodegenSecurity { public Boolean hasMore, isBasic, isOAuth, isApiKey; // is Basic is true for all http authentication type. Those are to differentiate basic and bearer authentication public Boolean isBasicBasic, isBasicBearer; + public String bearerFormat; public Map vendorExtensions = new HashMap(); // ApiKey specific public String keyParamName; @@ -58,6 +59,12 @@ public class CodegenSecurity { return false; if (isBasic != null ? !isBasic.equals(that.isBasic) : that.isBasic != null) return false; + if (isBasicBasic != null ? !isBasicBasic.equals(that.isBasicBasic) : that.isBasicBasic != null) + return false; + if (isBasicBearer != null ? !isBasicBearer.equals(that.isBasicBearer) : that.isBasicBearer != null) + return false; + if (bearerFormat != null ? !bearerFormat.equals(that.bearerFormat) : that.bearerFormat != null) + return false; if (isOAuth != null ? !isOAuth.equals(that.isOAuth) : that.isOAuth != null) return false; if (isApiKey != null ? !isApiKey.equals(that.isApiKey) : that.isApiKey != null) @@ -94,6 +101,9 @@ public class CodegenSecurity { result = 31 * result + (type != null ? type.hashCode() : 0); result = 31 * result + (hasMore != null ? hasMore.hashCode() : 0); result = 31 * result + (isBasic != null ? isBasic.hashCode() : 0); + result = 31 * result + (isBasicBasic != null ? isBasicBasic.hashCode() : 0); + result = 31 * result + (isBasicBearer != null ? isBasicBearer.hashCode() : 0); + result = 31 * result + (bearerFormat != null ? bearerFormat.hashCode() : 0); result = 31 * result + (isOAuth != null ? isOAuth.hashCode() : 0); result = 31 * result + (isApiKey != null ? isApiKey.hashCode() : 0); result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index efb7d8f8937..760a7462c6b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -3124,6 +3124,7 @@ public class DefaultCodegen implements CodegenConfig { } else if ("bearer".equals(securityScheme.getScheme())) { cs.isBasicBearer = true; + cs.bearerFormat = securityScheme.getBearerFormat(); } } else if (SecurityScheme.Type.OAUTH2.equals(securityScheme.getType())) { cs.isKeyInHeader = cs.isKeyInQuery = cs.isKeyInCookie = cs.isApiKey = cs.isBasic = false; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index 990172156f6..54059f23287 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -841,6 +841,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { bundle.put("hasOAuthMethods", true); bundle.put("oauthMethods", getOAuthMethods(authMethods)); } + + if (hasBearerMethods(authMethods)) { + bundle.put("hasBearerMethods", true); + } } List servers = config.fromServers(openAPI.getServers()); @@ -1194,6 +1198,16 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { return false; } + private boolean hasBearerMethods(List authMethods) { + for (CodegenSecurity cs : authMethods) { + if (cs.isBasicBearer) { + return true; + } + } + + return false; + } + private List getOAuthMethods(List authMethods) { List oauthMethods = new ArrayList<>(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ProcessUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ProcessUtils.java index 2963a4c821f..e4506b85d03 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ProcessUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ProcessUtils.java @@ -60,4 +60,28 @@ public class ProcessUtils { return false; } + /** + * Returns true if at least one operation has Bearer security schema defined + * + * @param objs Map of operations + * @return True if at least one operation has Bearer security schema defined + */ + public static boolean hasBearerMethods(Map objs) { + Map operations = (Map) objs.get("operations"); + if (operations != null) { + List ops = (List) operations.get("operation"); + for (CodegenOperation operation : ops) { + if (operation.authMethods != null && !operation.authMethods.isEmpty()) { + for (CodegenSecurity cs : operation.authMethods) { + if (cs.isBasicBearer) { + return true; + } + } + } + } + } + + return false; + } + } diff --git a/modules/openapi-generator/src/main/resources/python/api_doc.mustache b/modules/openapi-generator/src/main/resources/python/api_doc.mustache index c16779a5f96..210ac86d2e5 100644 --- a/modules/openapi-generator/src/main/resources/python/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_doc.mustache @@ -18,8 +18,23 @@ Method | HTTP request | Description {{{notes}}}{{/notes}} ### Example -{{#hasAuthMethods}}{{#authMethods}} -{{#isBasic}}* Basic Authentication ({{name}}): {{/isBasic }}{{#isApiKey}}* Api Key Authentication ({{name}}): {{/isApiKey }}{{#isOAuth}}* OAuth Authentication ({{name}}): {{/isOAuth }} + +{{#hasAuthMethods}} +{{#authMethods}} +{{#isBasic}} +{{^isBasicBearer}} +* Basic Authentication ({{name}}): +{{/isBasicBearer}} +{{#isBasicBearer}} +* Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} Authentication ({{name}}): +{{/isBasicBearer}} +{{/isBasic}} +{{#isApiKey}} +* Api Key Authentication ({{name}}): +{{/isApiKey }} +{{#isOAuth}} +* OAuth Authentication ({{name}}): +{{/isOAuth }} {{> api_doc_example }} {{/authMethods}} {{/hasAuthMethods}} diff --git a/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache b/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache index 282bacf69c2..c8f0d8b554a 100644 --- a/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_doc_example.mustache @@ -4,25 +4,14 @@ import time import {{{packageName}}} from {{{packageName}}}.rest import ApiException from pprint import pprint +{{> python_doc_auth_partial}} {{#hasAuthMethods}} -configuration = {{{packageName}}}.Configuration(){{#isBasic}} -# Configure HTTP basic authorization: {{{name}}} -configuration.username = 'YOUR_USERNAME' -configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}} -# Configure API key authorization: {{{name}}} -configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY' -# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed -# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} -# Configure OAuth2 access token for authorization: {{{name}}} -configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}} - # create an instance of the API class api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration)) {{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} {{/allParams}} {{/hasAuthMethods}} {{^hasAuthMethods}} - # create an instance of the API class api_instance = {{{packageName}}}.{{{classname}}}() {{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} diff --git a/modules/openapi-generator/src/main/resources/python/common_README.mustache b/modules/openapi-generator/src/main/resources/python/common_README.mustache index 194fb14b599..d8e9f94c584 100644 --- a/modules/openapi-generator/src/main/resources/python/common_README.mustache +++ b/modules/openapi-generator/src/main/resources/python/common_README.mustache @@ -4,19 +4,8 @@ import time import {{{packageName}}} from {{{packageName}}}.rest import ApiException from pprint import pprint -{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}} -configuration = {{{packageName}}}.Configuration(){{#isBasic}} -# Configure HTTP basic authorization: {{{name}}} -configuration.username = 'YOUR_USERNAME' -configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}} -# Configure API key authorization: {{{name}}} -configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY' -# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed -# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}} -# Configure OAuth2 access token for authorization: {{{name}}} -configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}{{/authMethods}} -{{/hasAuthMethods}} - +{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} +{{> python_doc_auth_partial}} # create an instance of the API class api_instance = {{{packageName}}}.{{{classname}}}({{{packageName}}}.ApiClient(configuration)) {{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} @@ -47,17 +36,28 @@ Class | Method | HTTP request | Description ## Documentation For Authorization -{{^authMethods}} All endpoints do not require authorization. -{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} -{{#authMethods}}## {{{name}}} +{{^authMethods}} + All endpoints do not require authorization. +{{/authMethods}} +{{#authMethods}} +{{#last}} Authentication schemes defined for the API:{{/last}} +## {{{name}}} -{{#isApiKey}}- **Type**: API key +{{#isApiKey}} +- **Type**: API key - **API key parameter name**: {{{keyParamName}}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} -{{#isBasic}}- **Type**: HTTP basic authentication +{{#isBasic}} +{{^isBasicBearer}} +- **Type**: HTTP basic authentication +{{/isBasicBearer}} +{{#isBasicBearer}} +- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} +{{/isBasicBearer}} {{/isBasic}} -{{#isOAuth}}- **Type**: OAuth +{{#isOAuth}} +- **Type**: OAuth - **Flow**: {{{flow}}} - **Authorization URL**: {{{authorizationUrl}}} - **Scopes**: {{^scopes}}N/A{{/scopes}} diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 562c036e9fc..2aaf9851d79 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -51,10 +51,16 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): self.username = "" # Password for HTTP basic authentication self.password = "" -{{#authMethods}}{{#isOAuth}} - # access token for OAuth +{{#hasOAuthMethods}} + # access token for OAuth/Bearer self.access_token = "" -{{/isOAuth}}{{/authMethods}} +{{/hasOAuthMethods}} +{{^hasOAuthMethods}} +{{#hasBearerMethods}} + # access token for OAuth/Bearer + self.access_token = "" +{{/hasBearerMethods}} +{{/hasOAuthMethods}} # Logging Settings self.logger = {} self.logger["package_logger"] = logging.getLogger("{{packageName}}") @@ -218,6 +224,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): }, {{/isApiKey}} {{#isBasic}} + {{^isBasicBearer}} '{{name}}': { 'type': 'basic', @@ -225,7 +232,21 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): 'key': 'Authorization', 'value': self.get_basic_auth_token() }, -{{/isBasic}}{{#isOAuth}} + {{/isBasicBearer}} + {{#isBasicBearer}} + '{{name}}': + { + 'type': 'bearer', + 'in': 'header', + {{#bearerFormat}} + 'format': '{{{.}}}', + {{/bearerFormat}} + 'key': 'Authorization', + 'value': 'Bearer ' + self.access_token + }, + {{/isBasicBearer}} +{{/isBasic}} +{{#isOAuth}} '{{name}}': { 'type': 'oauth2', @@ -233,7 +254,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): 'key': 'Authorization', 'value': 'Bearer ' + self.access_token }, -{{/isOAuth}}{{/authMethods}} +{{/isOAuth}} +{{/authMethods}} } def to_debug_report(self): diff --git a/modules/openapi-generator/src/main/resources/python/python_doc_auth_partial.mustache b/modules/openapi-generator/src/main/resources/python/python_doc_auth_partial.mustache new file mode 100644 index 00000000000..899e4b58b92 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/python/python_doc_auth_partial.mustache @@ -0,0 +1,26 @@ +{{#hasAuthMethods}} +{{#authMethods}} +configuration = {{{packageName}}}.Configuration() +{{#isBasic}} +{{^isBasicBearer}} +# Configure HTTP basic authorization: {{{name}}} +configuration.username = 'YOUR_USERNAME' +configuration.password = 'YOUR_PASSWORD' +{{/isBasicBearer}} +{{#isBasicBearer}} +# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} +configuration.access_token = 'YOUR_BEARER_TOKEN' +{{/isBasicBearer}} +{{/isBasic}} +{{#isApiKey}} +# Configure API key authorization: {{{name}}} +configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY' +# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +# configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer' +{{/isApiKey}} +{{#isOAuth}} +# Configure OAuth2 access token for authorization: {{{name}}} +configuration.access_token = 'YOUR_ACCESS_TOKEN' +{{/isOAuth}} +{{/authMethods}} +{{/hasAuthMethods}} diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml index 563ca99bc94..39668ac2732 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -768,6 +768,8 @@ paths: delete: tags: - fake + security: + - bearer_test: [] summary: Fake endpoint to test group parameters (optional) description: Fake endpoint to test group parameters (optional) operationId: testGroupParameters @@ -1096,6 +1098,10 @@ components: http_basic_test: type: http scheme: basic + bearer_test: + type: http + scheme: bearer + bearerFormat: JWT schemas: Foo: type: object diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index 218749c0433..4c67e17b44c 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -51,6 +51,7 @@ import petstore_api from petstore_api.rest import ApiException from pprint import pprint + # create an instance of the API class api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration)) body = petstore_api.Client() # Client | client model @@ -158,16 +159,19 @@ Class | Method | HTTP request | Description - **API key parameter name**: api_key - **Location**: HTTP header + ## api_key_query - **Type**: API key - **API key parameter name**: api_key_query - **Location**: URL query string + ## http_basic_test - **Type**: HTTP basic authentication + ## petstore_auth - **Type**: OAuth diff --git a/samples/client/petstore/python/docs/AnotherFakeApi.md b/samples/client/petstore/python/docs/AnotherFakeApi.md index 53d8da58f0c..c1c76a67fd6 100644 --- a/samples/client/petstore/python/docs/AnotherFakeApi.md +++ b/samples/client/petstore/python/docs/AnotherFakeApi.md @@ -15,6 +15,7 @@ To test special tags To test special tags and operation ID starting with number ### Example + ```python from __future__ import print_function import time diff --git a/samples/client/petstore/python/docs/FakeApi.md b/samples/client/petstore/python/docs/FakeApi.md index 144c662e53a..c46bf1e4974 100644 --- a/samples/client/petstore/python/docs/FakeApi.md +++ b/samples/client/petstore/python/docs/FakeApi.md @@ -27,6 +27,7 @@ creates an XmlItem this route creates an XmlItem ### Example + ```python from __future__ import print_function import time @@ -74,6 +75,7 @@ No authorization required Test serialization of outer boolean types ### Example + ```python from __future__ import print_function import time @@ -121,6 +123,7 @@ No authorization required Test serialization of object with outer number type ### Example + ```python from __future__ import print_function import time @@ -168,6 +171,7 @@ No authorization required Test serialization of outer number types ### Example + ```python from __future__ import print_function import time @@ -215,6 +219,7 @@ No authorization required Test serialization of outer string types ### Example + ```python from __future__ import print_function import time @@ -262,6 +267,7 @@ No authorization required For this test, the body for this request much reference a schema named `File`. ### Example + ```python from __future__ import print_function import time @@ -306,6 +312,7 @@ No authorization required ### Example + ```python from __future__ import print_function import time @@ -354,6 +361,7 @@ To test \"client\" model To test \"client\" model ### Example + ```python from __future__ import print_function import time @@ -403,7 +411,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン ### Example -* Basic Authentication (http_basic_test): +* Basic Authentication (http_basic_test): ```python from __future__ import print_function import time @@ -481,6 +489,7 @@ To test enum parameters To test enum parameters ### Example + ```python from __future__ import print_function import time @@ -542,6 +551,7 @@ Fake endpoint to test group parameters (optional) Fake endpoint to test group parameters (optional) ### Example + ```python from __future__ import print_function import time @@ -597,6 +607,7 @@ No authorization required test inline additionalProperties ### Example + ```python from __future__ import print_function import time @@ -642,6 +653,7 @@ No authorization required test json serialization of form data ### Example + ```python from __future__ import print_function import time diff --git a/samples/client/petstore/python/docs/FakeClassnameTags123Api.md b/samples/client/petstore/python/docs/FakeClassnameTags123Api.md index 91e813c88b6..aed30cb56db 100644 --- a/samples/client/petstore/python/docs/FakeClassnameTags123Api.md +++ b/samples/client/petstore/python/docs/FakeClassnameTags123Api.md @@ -16,7 +16,7 @@ To test class name in snake case ### Example -* Api Key Authentication (api_key_query): +* Api Key Authentication (api_key_query): ```python from __future__ import print_function import time diff --git a/samples/client/petstore/python/docs/PetApi.md b/samples/client/petstore/python/docs/PetApi.md index 0dc747ffc0f..227fa2ada13 100644 --- a/samples/client/petstore/python/docs/PetApi.md +++ b/samples/client/petstore/python/docs/PetApi.md @@ -22,7 +22,7 @@ Add a new pet to the store ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -72,7 +72,7 @@ Deletes a pet ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -126,7 +126,7 @@ Multiple status values can be provided with comma separated strings ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -179,7 +179,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -232,7 +232,7 @@ Returns a single pet ### Example -* Api Key Authentication (api_key): +* Api Key Authentication (api_key): ```python from __future__ import print_function import time @@ -285,7 +285,7 @@ Update an existing pet ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -335,7 +335,7 @@ Updates a pet in the store with form data ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -389,7 +389,7 @@ uploads an image ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -444,7 +444,7 @@ uploads an image (required) ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time diff --git a/samples/client/petstore/python/docs/StoreApi.md b/samples/client/petstore/python/docs/StoreApi.md index 084bf2b2f14..af190f931d2 100644 --- a/samples/client/petstore/python/docs/StoreApi.md +++ b/samples/client/petstore/python/docs/StoreApi.md @@ -18,6 +18,7 @@ Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors ### Example + ```python from __future__ import print_function import time @@ -66,7 +67,7 @@ Returns a map of status codes to quantities ### Example -* Api Key Authentication (api_key): +* Api Key Authentication (api_key): ```python from __future__ import print_function import time @@ -116,6 +117,7 @@ Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions ### Example + ```python from __future__ import print_function import time @@ -162,6 +164,7 @@ No authorization required Place an order for a pet ### Example + ```python from __future__ import print_function import time diff --git a/samples/client/petstore/python/docs/UserApi.md b/samples/client/petstore/python/docs/UserApi.md index f0d9581779c..33e86f9e8fd 100644 --- a/samples/client/petstore/python/docs/UserApi.md +++ b/samples/client/petstore/python/docs/UserApi.md @@ -22,6 +22,7 @@ Create user This can only be done by the logged in user. ### Example + ```python from __future__ import print_function import time @@ -67,6 +68,7 @@ No authorization required Creates list of users with given input array ### Example + ```python from __future__ import print_function import time @@ -112,6 +114,7 @@ No authorization required Creates list of users with given input array ### Example + ```python from __future__ import print_function import time @@ -159,6 +162,7 @@ Delete user This can only be done by the logged in user. ### Example + ```python from __future__ import print_function import time @@ -204,6 +208,7 @@ No authorization required Get user by user name ### Example + ```python from __future__ import print_function import time @@ -250,6 +255,7 @@ No authorization required Logs user into the system ### Example + ```python from __future__ import print_function import time @@ -298,6 +304,7 @@ No authorization required Logs out current logged in user session ### Example + ```python from __future__ import print_function import time @@ -341,6 +348,7 @@ Updated user This can only be done by the logged in user. ### Example + ```python from __future__ import print_function import time diff --git a/samples/client/petstore/python/petstore_api/configuration.py b/samples/client/petstore/python/petstore_api/configuration.py index 99189566bde..d1d50e6517a 100644 --- a/samples/client/petstore/python/petstore_api/configuration.py +++ b/samples/client/petstore/python/petstore_api/configuration.py @@ -59,10 +59,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): self.username = "" # Password for HTTP basic authentication self.password = "" - - # access token for OAuth + # access token for OAuth/Bearer self.access_token = "" - # Logging Settings self.logger = {} self.logger["package_logger"] = logging.getLogger("petstore_api") @@ -236,7 +234,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): 'key': 'Authorization', 'value': self.get_basic_auth_token() }, - 'petstore_auth': { 'type': 'oauth2', @@ -244,7 +241,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): 'key': 'Authorization', 'value': 'Bearer ' + self.access_token }, - } def to_debug_report(self): diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/README.md b/samples/openapi3/client/petstore/php/OpenAPIClient-php/README.md index 34ffbd1ab45..e12458e161e 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/README.md +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/README.md @@ -178,6 +178,10 @@ Class | Method | HTTP request | Description - **API key parameter name**: api_key_query - **Location**: URL query string +## bearer_test + +- **Type**: HTTP basic authentication + ## http_basic_test - **Type**: HTTP basic authentication diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md b/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md index d428bf33f0b..136b65b7d2e 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/docs/Api/FakeApi.md @@ -513,10 +513,16 @@ Fake endpoint to test group parameters (optional) setUsername('YOUR_USERNAME') + ->setPassword('YOUR_PASSWORD'); + $apiInstance = new OpenAPI\Client\Api\FakeApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. - new GuzzleHttp\Client() + new GuzzleHttp\Client(), + $config ); $associate_array['required_string_group'] = 56; // int | Required String in group parameters $associate_array['required_boolean_group'] = True; // bool | Required Boolean in group parameters @@ -552,7 +558,7 @@ void (empty response body) ### Authorization -No authorization required +[bearer_test](../../README.md#bearer_test) ### HTTP request headers diff --git a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 99359ca9cc5..a5fa7abaef4 100644 --- a/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/openapi3/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -2791,6 +2791,10 @@ class FakeApi } } + // this endpoint requires HTTP basic authentication + if ($this->config->getUsername() !== null || $this->config->getPassword() !== null) { + $headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ":" . $this->config->getPassword()); + } $defaultHeaders = []; if ($this->config->getUserAgent()) { diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index 159f63da107..080ec68a505 100644 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -51,6 +51,7 @@ import petstore_api from petstore_api.rest import ApiException from pprint import pprint + # create an instance of the API class api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration)) client = petstore_api.Client() # Client | client model @@ -163,16 +164,24 @@ Class | Method | HTTP request | Description - **API key parameter name**: api_key - **Location**: HTTP header + ## api_key_query - **Type**: API key - **API key parameter name**: api_key_query - **Location**: URL query string + +## bearer_test + +- **Type**: Bearer authentication (JWT) + + ## http_basic_test - **Type**: HTTP basic authentication + ## petstore_auth - **Type**: OAuth diff --git a/samples/openapi3/client/petstore/python/docs/AnotherFakeApi.md b/samples/openapi3/client/petstore/python/docs/AnotherFakeApi.md index 447ce3edde3..836c8c9cd6e 100644 --- a/samples/openapi3/client/petstore/python/docs/AnotherFakeApi.md +++ b/samples/openapi3/client/petstore/python/docs/AnotherFakeApi.md @@ -15,6 +15,7 @@ To test special tags To test special tags and operation ID starting with number ### Example + ```python from __future__ import print_function import time diff --git a/samples/openapi3/client/petstore/python/docs/DefaultApi.md b/samples/openapi3/client/petstore/python/docs/DefaultApi.md index 097a4e1d8cb..0102690ac18 100644 --- a/samples/openapi3/client/petstore/python/docs/DefaultApi.md +++ b/samples/openapi3/client/petstore/python/docs/DefaultApi.md @@ -13,6 +13,7 @@ Method | HTTP request | Description ### Example + ```python from __future__ import print_function import time diff --git a/samples/openapi3/client/petstore/python/docs/FakeApi.md b/samples/openapi3/client/petstore/python/docs/FakeApi.md index a8534626822..6e4f1f2d310 100644 --- a/samples/openapi3/client/petstore/python/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python/docs/FakeApi.md @@ -26,6 +26,7 @@ Method | HTTP request | Description Test serialization of outer boolean types ### Example + ```python from __future__ import print_function import time @@ -73,6 +74,7 @@ No authorization required Test serialization of object with outer number type ### Example + ```python from __future__ import print_function import time @@ -120,6 +122,7 @@ No authorization required Test serialization of outer number types ### Example + ```python from __future__ import print_function import time @@ -167,6 +170,7 @@ No authorization required Test serialization of outer string types ### Example + ```python from __future__ import print_function import time @@ -214,6 +218,7 @@ No authorization required For this test, the body for this request much reference a schema named `File`. ### Example + ```python from __future__ import print_function import time @@ -258,6 +263,7 @@ No authorization required ### Example + ```python from __future__ import print_function import time @@ -306,6 +312,7 @@ To test \"client\" model To test \"client\" model ### Example + ```python from __future__ import print_function import time @@ -355,7 +362,7 @@ Fake endpoint for testing various parameters 假端點 偽のエンドポイン ### Example -* Basic Authentication (http_basic_test): +* Basic Authentication (http_basic_test): ```python from __future__ import print_function import time @@ -433,6 +440,7 @@ To test enum parameters To test enum parameters ### Example + ```python from __future__ import print_function import time @@ -494,15 +502,20 @@ Fake endpoint to test group parameters (optional) Fake endpoint to test group parameters (optional) ### Example + +* Bearer (JWT) Authentication (bearer_test): ```python from __future__ import print_function import time import petstore_api from petstore_api.rest import ApiException from pprint import pprint +configuration = petstore_api.Configuration() +# Configure Bearer authorization (JWT): bearer_test +configuration.access_token = 'YOUR_BEARER_TOKEN' # create an instance of the API class -api_instance = petstore_api.FakeApi() +api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration)) required_string_group = 56 # int | Required String in group parameters required_boolean_group = True # bool | Required Boolean in group parameters required_int64_group = 56 # int | Required Integer in group parameters @@ -534,7 +547,7 @@ void (empty response body) ### Authorization -No authorization required +[bearer_test](../README.md#bearer_test) ### HTTP request headers @@ -549,6 +562,7 @@ No authorization required test inline additionalProperties ### Example + ```python from __future__ import print_function import time @@ -594,6 +608,7 @@ No authorization required test json serialization of form data ### Example + ```python from __future__ import print_function import time diff --git a/samples/openapi3/client/petstore/python/docs/FakeClassnameTags123Api.md b/samples/openapi3/client/petstore/python/docs/FakeClassnameTags123Api.md index 9a37c461b60..946c438e855 100644 --- a/samples/openapi3/client/petstore/python/docs/FakeClassnameTags123Api.md +++ b/samples/openapi3/client/petstore/python/docs/FakeClassnameTags123Api.md @@ -16,7 +16,7 @@ To test class name in snake case ### Example -* Api Key Authentication (api_key_query): +* Api Key Authentication (api_key_query): ```python from __future__ import print_function import time diff --git a/samples/openapi3/client/petstore/python/docs/PetApi.md b/samples/openapi3/client/petstore/python/docs/PetApi.md index 4101863e356..a089aabc55b 100644 --- a/samples/openapi3/client/petstore/python/docs/PetApi.md +++ b/samples/openapi3/client/petstore/python/docs/PetApi.md @@ -22,7 +22,7 @@ Add a new pet to the store ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -72,7 +72,7 @@ Deletes a pet ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -126,7 +126,7 @@ Multiple status values can be provided with comma separated strings ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -179,7 +179,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -232,7 +232,7 @@ Returns a single pet ### Example -* Api Key Authentication (api_key): +* Api Key Authentication (api_key): ```python from __future__ import print_function import time @@ -285,7 +285,7 @@ Update an existing pet ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -335,7 +335,7 @@ Updates a pet in the store with form data ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -389,7 +389,7 @@ uploads an image ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time @@ -444,7 +444,7 @@ uploads an image (required) ### Example -* OAuth Authentication (petstore_auth): +* OAuth Authentication (petstore_auth): ```python from __future__ import print_function import time diff --git a/samples/openapi3/client/petstore/python/docs/StoreApi.md b/samples/openapi3/client/petstore/python/docs/StoreApi.md index 86e368b9342..f40a25a154e 100644 --- a/samples/openapi3/client/petstore/python/docs/StoreApi.md +++ b/samples/openapi3/client/petstore/python/docs/StoreApi.md @@ -18,6 +18,7 @@ Delete purchase order by ID For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors ### Example + ```python from __future__ import print_function import time @@ -66,7 +67,7 @@ Returns a map of status codes to quantities ### Example -* Api Key Authentication (api_key): +* Api Key Authentication (api_key): ```python from __future__ import print_function import time @@ -116,6 +117,7 @@ Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions ### Example + ```python from __future__ import print_function import time @@ -162,6 +164,7 @@ No authorization required Place an order for a pet ### Example + ```python from __future__ import print_function import time diff --git a/samples/openapi3/client/petstore/python/docs/UserApi.md b/samples/openapi3/client/petstore/python/docs/UserApi.md index cf5e653878c..da87cd282d1 100644 --- a/samples/openapi3/client/petstore/python/docs/UserApi.md +++ b/samples/openapi3/client/petstore/python/docs/UserApi.md @@ -22,6 +22,7 @@ Create user This can only be done by the logged in user. ### Example + ```python from __future__ import print_function import time @@ -67,6 +68,7 @@ No authorization required Creates list of users with given input array ### Example + ```python from __future__ import print_function import time @@ -112,6 +114,7 @@ No authorization required Creates list of users with given input array ### Example + ```python from __future__ import print_function import time @@ -159,6 +162,7 @@ Delete user This can only be done by the logged in user. ### Example + ```python from __future__ import print_function import time @@ -204,6 +208,7 @@ No authorization required Get user by user name ### Example + ```python from __future__ import print_function import time @@ -250,6 +255,7 @@ No authorization required Logs user into the system ### Example + ```python from __future__ import print_function import time @@ -298,6 +304,7 @@ No authorization required Logs out current logged in user session ### Example + ```python from __future__ import print_function import time @@ -341,6 +348,7 @@ Updated user This can only be done by the logged in user. ### Example + ```python from __future__ import print_function import time diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py index b29ea904dd0..7dbc1cdfc11 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py @@ -1127,7 +1127,7 @@ class FakeApi(object): body_params = None # Authentication setting - auth_settings = [] # noqa: E501 + auth_settings = ['bearer_test'] # noqa: E501 return self.api_client.call_api( '/fake', 'DELETE', diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index dee2fbabedd..abdb7294a23 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -59,10 +59,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): self.username = "" # Password for HTTP basic authentication self.password = "" - - # access token for OAuth + # access token for OAuth/Bearer self.access_token = "" - # Logging Settings self.logger = {} self.logger["package_logger"] = logging.getLogger("petstore_api") @@ -229,6 +227,14 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): 'key': 'api_key_query', 'value': self.get_api_key_with_prefix('api_key_query') }, + 'bearer_test': + { + 'type': 'bearer', + 'in': 'header', + 'format': 'JWT', + 'key': 'Authorization', + 'value': 'Bearer ' + self.access_token + }, 'http_basic_test': { 'type': 'basic', @@ -236,7 +242,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): 'key': 'Authorization', 'value': self.get_basic_auth_token() }, - 'petstore_auth': { 'type': 'oauth2', @@ -244,7 +249,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)): 'key': 'Authorization', 'value': 'Bearer ' + self.access_token }, - } def to_debug_report(self): diff --git a/samples/openapi3/client/petstore/ruby/README.md b/samples/openapi3/client/petstore/ruby/README.md index 7b52e5540a5..dceec8a4747 100644 --- a/samples/openapi3/client/petstore/ruby/README.md +++ b/samples/openapi3/client/petstore/ruby/README.md @@ -166,6 +166,10 @@ Class | Method | HTTP request | Description - **API key parameter name**: api_key_query - **Location**: URL query string +### bearer_test + +- **Type**: HTTP basic authentication + ### http_basic_test - **Type**: HTTP basic authentication diff --git a/samples/openapi3/client/petstore/ruby/docs/FakeApi.md b/samples/openapi3/client/petstore/ruby/docs/FakeApi.md index 3a26c4926c1..e4d8e11915c 100644 --- a/samples/openapi3/client/petstore/ruby/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/ruby/docs/FakeApi.md @@ -482,6 +482,12 @@ Fake endpoint to test group parameters (optional) ```ruby # load the gem require 'petstore' +# setup authorization +Petstore.configure do |config| + # Configure HTTP basic authorization: bearer_test + config.username = 'YOUR USERNAME' + config.password = 'YOUR PASSWORD' +end api_instance = Petstore::FakeApi.new required_string_group = 56 # Integer | Required String in group parameters @@ -518,7 +524,7 @@ nil (empty response body) ### Authorization -No authorization required +[bearer_test](../README.md#bearer_test) ### HTTP request headers diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/api/fake_api.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/api/fake_api.rb index 796a2c5b4d4..9dfdc4ad60b 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/api/fake_api.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/api/fake_api.rb @@ -686,7 +686,7 @@ module Petstore # http body (model) post_body = nil - auth_names = [] + auth_names = ['bearer_test'] data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, :header_params => header_params, :query_params => query_params, diff --git a/samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb b/samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb index 908147a4978..fe5524905c7 100644 --- a/samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb +++ b/samples/openapi3/client/petstore/ruby/lib/petstore/configuration.rb @@ -210,6 +210,13 @@ module Petstore key: 'api_key_query', value: api_key_with_prefix('api_key_query') }, + 'bearer_test' => + { + type: 'basic', + in: 'header', + key: 'Authorization', + value: basic_auth_token + }, 'http_basic_test' => { type: 'basic', diff --git a/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/api/FakeApi.java b/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/api/FakeApi.java index c47f03f0462..a7907d4a0a9 100644 --- a/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/api/FakeApi.java +++ b/samples/server/petstore/jaxrs-jersey/src/gen/java/org/openapitools/api/FakeApi.java @@ -204,7 +204,9 @@ public class FakeApi { - @io.swagger.annotations.ApiOperation(value = "Fake endpoint to test group parameters (optional)", notes = "Fake endpoint to test group parameters (optional)", response = Void.class, tags={ "fake", }) + @io.swagger.annotations.ApiOperation(value = "Fake endpoint to test group parameters (optional)", notes = "Fake endpoint to test group parameters (optional)", response = Void.class, authorizations = { + @io.swagger.annotations.Authorization(value = "bearer_test") + }, tags={ "fake", }) @io.swagger.annotations.ApiResponses(value = { @io.swagger.annotations.ApiResponse(code = 400, message = "Someting wrong", response = Void.class) }) public Response testGroupParameters(@ApiParam(value = "Required String in group parameters",required=true) @QueryParam("required_string_group") Integer requiredStringGroup diff --git a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php index 19e967e41ed..ecccdb3058c 100644 --- a/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php +++ b/samples/server/petstore/php-symfony/SymfonyBundle-php/Api/PetApiInterface.php @@ -43,15 +43,6 @@ use OpenAPI\Server\Model\Pet; interface PetApiInterface { - /** - * Sets authentication method petstore_auth - * - * @param string $value Value of the petstore_auth authentication method. - * - * @return void - */ - public function setpetstore_auth($value); - /** * Sets authentication method api_key * @@ -61,6 +52,15 @@ interface PetApiInterface */ public function setapi_key($value); + /** + * Sets authentication method petstore_auth + * + * @param string $value Value of the petstore_auth authentication method. + * + * @return void + */ + public function setpetstore_auth($value); + /** * Operation addPet *