Fix Basic Bearer auth examples for HTML2 Docs (#6579)

* add missing basic bearer auth examples

* fix basic bearer auth header

* add bearerFormat

* fix all template formats and whitespacing
This commit is contained in:
Pierre Bérubé 2020-06-10 03:38:22 -06:00 committed by GitHub
parent 104a2a39b8
commit a014915e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 85 additions and 51 deletions

View File

@ -243,7 +243,11 @@
<div class="tab-content">
<div class="tab-pane active" id="examples-{{baseName}}-{{nickname}}-0-curl">
<pre class="prettyprint"><code class="language-bsh">curl -X {{vendorExtensions.x-codegen-http-method-upper-case}}{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} -H "{{keyParamName}}: [[apiKey]]"{{/isKeyInHeader}}{{/isApiKey}}{{#isBasic}}{{#hasProduces}} -H "Accept: {{#produces}}{{{mediaType}}}{{#hasMore}},{{/hasMore}}{{/produces}}"{{/hasProduces}}{{#hasConsumes}} -H "Content-Type: {{#consumes}}{{{mediaType}}}{{#hasMore}},{{/hasMore}}{{/consumes}}"{{/hasConsumes}} -H "Authorization: Basic [[basicHash]]"{{/isBasic}}{{/authMethods}} "{{basePath}}{{path}}{{#hasQueryParams}}?{{#queryParams}}{{^-first}}&{{/-first}}{{baseName}}={{vendorExtensions.x-eg}}{{/queryParams}}{{/hasQueryParams}}"</code></pre>
<pre class="prettyprint"><code class="language-bsh">curl -X {{vendorExtensions.x-codegen-http-method-upper-case}}{{#authMethods}}\
{{#isApiKey}}{{#isKeyInHeader}}-H "{{keyParamName}}: [[apiKey]]"{{/isKeyInHeader}}{{/isApiKey}}{{^isBasicBearer}}{{#isBasic}} -H "Authorization: Basic [[basicHash]]"{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}} -H "Authorization: Bearer [[accessToken]]"{{/isBasicBearer}}{{/authMethods}}{{#hasProduces}}\
-H "Accept: {{#produces}}{{{mediaType}}}{{#hasMore}},{{/hasMore}}{{/produces}}"{{/hasProduces}}{{#hasConsumes}}\
-H "Content-Type: {{#consumes}}{{{mediaType}}}{{#hasMore}},{{/hasMore}}{{/consumes}}"{{/hasConsumes}}\
"{{basePath}}{{path}}{{#hasQueryParams}}?{{#queryParams}}{{^-first}}&{{/-first}}{{baseName}}={{vendorExtensions.x-eg}}{{/queryParams}}{{/hasQueryParams}}"</code></pre>
</div>
<div class="tab-pane" id="examples-{{baseName}}-{{nickname}}-0-java">
<pre class="prettyprint"><code class="language-java">{{>sample_java}}</code></pre>

View File

@ -1,12 +1,12 @@
import {{{invokerPackage}}}.api.{{{classname}}};
public class {{{classname}}}Example {
public static void main(String[] args) {
{{{classname}}} apiInstance = new {{{classname}}}();
{{#allParams}}
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{unescapedDescription}}}
{{/allParams}}
try {
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
System.out.println(result);{{/returnType}}

View File

@ -10,18 +10,20 @@ namespace Example
{
public void main()
{
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
{{#hasAuthMethods}}
{{#authMethods}}
{{^isBasicBearer}}{{#isBasic}}// Configure HTTP basic authorization: {{{name}}}
Configuration.Default.Username = "YOUR_USERNAME";
Configuration.Default.Password = "YOUR_PASSWORD";{{/isBasic}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
Configuration.Default.Password = "YOUR_PASSWORD";{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}}// Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";{{/isBasicBearer}}{{#isApiKey}}// Configure API key authorization: {{{name}}}
Configuration.Default.ApiKey.Add("{{{keyParamName}}}", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";{{/isOAuth}}{{/authMethods}}
// Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");{{/isApiKey}}{{#isOAuth}}// Configure OAuth2 access token for authorization: {{{name}}}
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
// Create an instance of the API class
var apiInstance = new {{classname}}();
{{#allParams}}
{{#isPrimitiveType}}
@ -32,16 +34,13 @@ namespace Example
{{/isPrimitiveType}}
{{/allParams}}
try
{
try {
{{#summary}}
// {{{.}}}
{{/summary}}
{{#returnType}}{{{.}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
Debug.WriteLine(result);{{/returnType}}
}
catch (Exception e)
{
} catch (Exception e) {
Debug.Print("Exception when calling {{classname}}.{{operationId}}: " + e.Message );
}
}

View File

@ -7,15 +7,16 @@ import java.io.File;
import java.util.*;
public class {{{classname}}}Example {
public static void main(String[] args) {
{{#hasAuthMethods}}ApiClient defaultClient = Configuration.getDefaultApiClient();
{{#authMethods}}{{#isBasic}}
{{#hasAuthMethods}}
ApiClient defaultClient = Configuration.getDefaultApiClient();
{{#authMethods}}
{{^isBasicBearer}}{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
HttpBasicAuth {{{name}}} = (HttpBasicAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setUsername("YOUR USERNAME");
{{{name}}}.setPassword("YOUR PASSWORD");{{/isBasic}}{{#isBasicBearer}}
// Configure HTTP bearer authorization: {{{name}}}
{{{name}}}.setPassword("YOUR PASSWORD");{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}}
// Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}}
HttpBearerAuth {{{name}}} = (HttpBearerAuth) defaultClient.getAuthentication("{{{name}}}");
{{{name}}}.setBearerToken("BEARER TOKEN");{{/isBasicBearer}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
@ -28,11 +29,13 @@ public class {{{classname}}}Example {
{{{name}}}.setAccessToken("YOUR ACCESS TOKEN");{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
// Create an instance of the API class
{{{classname}}} apiInstance = new {{{classname}}}();
{{#allParams}}
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{unescapedDescription}}}
{{/allParams}}
try {
{{#returnType}}{{{returnType}}} result = {{/returnType}}apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
System.out.println(result);{{/returnType}}

View File

@ -1,22 +1,26 @@
var {{{jsModuleName}}} = require('{{{jsProjectName}}}');
{{#hasAuthMethods}}
var defaultClient = {{{jsModuleName}}}.ApiClient.instance;
{{#authMethods}}{{#isBasic}}
{{#authMethods}}{{^isBasicBearer}}{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
{{{name}}}.username = 'YOUR USERNAME'
{{{name}}}.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
{{{name}}}.username = 'YOUR USERNAME';
{{{name}}}.password = 'YOUR PASSWORD';{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}}
// Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}}
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
{{{name}}}.accessToken = "YOUR ACCESS TOKEN";{{/isBasicBearer}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
{{{name}}}.apiKey = "YOUR API KEY"
{{{name}}}.apiKey = "YOUR API KEY";
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//{{{name}}}.apiKeyPrefix['{{{keyParamName}}}'] = "Token"{{/isApiKey}}{{#isOAuth}}
//{{{name}}}.apiKeyPrefix['{{{keyParamName}}}'] = "Token";{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
{{{name}}}.accessToken = "YOUR ACCESS TOKEN"{{/isOAuth}}
{{{name}}}.accessToken = "YOUR ACCESS TOKEN";{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
// Create an instance of the API class
var api = new {{{jsModuleName}}}.{{{classname}}}(){{#hasParams}}
{{#hasRequiredParams}}
{{#requiredParams}}

View File

@ -1,9 +1,12 @@
{{#hasAuthMethods}}
{{classPrefix}}Configuration *apiConfig = [{{classPrefix}}Configuration sharedConfig];
{{#authMethods}}{{#isBasic}}// Configure HTTP basic authorization (authentication scheme: {{{name}}})
{{#authMethods}}
{{^isBasicBearer}}{{#isBasic}}
// Configure HTTP basic authorization (authentication scheme: {{{name}}})
[apiConfig setUsername:@"YOUR_USERNAME"];
[apiConfig setPassword:@"YOUR_PASSWORD"];
{{/isBasic}}{{#isApiKey}}
[apiConfig setPassword:@"YOUR_PASSWORD"];{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}}
// Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}}
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];{{/isBasicBearer}}{{#isApiKey}}
// Configure API key authorization: (authentication scheme: {{{name}}})
[apiConfig setApiKey:@"YOUR_API_KEY" forApiKeyIdentifier:@"{{{keyParamName}}}"];
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
@ -11,23 +14,27 @@
{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: (authentication scheme: {{{name}}})
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
{{/isOAuth}}{{/authMethods}}
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
{{#allParams}}{{{dataType}}} *{{paramName}} = {{{example}}}; // {{{unescapedDescription}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
// Create an instance of the API class
{{classname}} *apiInstance = [[{{classname}} alloc] init];
{{#allParams}}
{{{dataType}}} *{{paramName}} = {{{example}}}; // {{{unescapedDescription}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}
{{#summary}}// {{{.}}}
{{/summary}}[apiInstance {{#vendorExtensions.x-objc-operationId}}{{vendorExtensions.x-objc-operationId}}{{/vendorExtensions.x-objc-operationId}}{{^vendorExtensions.x-objc-operationId}}{{nickname}}{{#hasParams}}With{{vendorExtensions.x-first-param-alt-name}}{{/hasParams}}{{^hasParams}}WithCompletionHandler: {{/hasParams}}{{/vendorExtensions.x-objc-operationId}}{{#allParams}}{{#secondaryParam}}
{{paramName}}{{/secondaryParam}}:{{paramName}}{{/allParams}}
{{#hasParams}}completionHandler: {{/hasParams}}^({{#returnBaseType}}{{{returnType}}} output, {{/returnBaseType}}NSError* error) {
{{#returnType}}
if (output) {
NSLog(@"%@", output);
}
if (output) {
NSLog(@"%@", output);
}
{{/returnType}}
if (error) {
NSLog(@"Error: %@", error);
}
}];
if (error) {
NSLog(@"Error: %@", error);
}
}];

View File

@ -1,18 +1,24 @@
use Data::Dumper;
use {{{perlModuleName}}}::Configuration;
use {{perlModuleName}}::{{classname}};
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
{{#hasAuthMethods}}
{{#authMethods}}
{{^isBasicBearer}}{{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
${{{perlModuleName}}}::Configuration::username = 'YOUR_USERNAME';
${{{perlModuleName}}}::Configuration::password = 'YOUR_PASSWORD';{{/isBasic}}{{#isApiKey}}
${{{perlModuleName}}}::Configuration::password = 'YOUR_PASSWORD';{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}}
# Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}}
${{{perlModuleName}}}::Configuration::access_token = 'YOUR_ACCESS_TOKEN';{{/isBasicBearer}}{{#isApiKey}}
# Configure API key authorization: {{{name}}}
${{{perlModuleName}}}::Configuration::api_key->{'{{{keyParamName}}}'} = 'YOUR_API_KEY';
# uncomment below to setup prefix (e.g. Bearer) for API key, if needed
#${{{perlModuleName}}}::Configuration::api_key_prefix->{'{{{keyParamName}}}'} = "Bearer";{{/isApiKey}}{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
${{{perlModuleName}}}::Configuration::access_token = 'YOUR_ACCESS_TOKEN';{{/isOAuth}}{{/authMethods}}
${{{perlModuleName}}}::Configuration::access_token = 'YOUR_ACCESS_TOKEN';{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
# Create an instance of the API class
my $api_instance = {{perlModuleName}}::{{classname}}->new();
{{#allParams}}my ${{paramName}} = {{#isListContainer}}[{{/isListContainer}}{{#isBodyParam}}{{{perlModuleName}}}::Object::{{dataType}}->new(){{/isBodyParam}}{{^isBodyParam}}{{{example}}}{{/isBodyParam}}{{#isListContainer}}]{{/isListContainer}}; # {{{dataType}}} | {{{unescapedDescription}}}
{{/allParams}}

View File

@ -1,17 +1,23 @@
<&#63;php
require_once(__DIR__ . '/vendor/autoload.php');
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
{{#hasAuthMethods}}
{{#authMethods}}
{{^isBasicBearer}}{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
{{phpInvokerPackage}}\Configuration::getDefaultConfiguration()->setUsername('YOUR_USERNAME');
{{phpInvokerPackage}}\Configuration::getDefaultConfiguration()->setPassword('YOUR_PASSWORD');{{/isBasic}}{{#isApiKey}}
{{phpInvokerPackage}}\Configuration::getDefaultConfiguration()->setPassword('YOUR_PASSWORD');{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}}
// Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}}
{{phpInvokerPackage}}\Configuration::getDefaultConfiguration()->setAccessToken('{{{keyParamName}}}', 'YOUR_ACCESS_TOKEN');{{/isBasicBearer}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
{{phpInvokerPackage}}\Configuration::getDefaultConfiguration()->setApiKey('{{{keyParamName}}}', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// {{phpInvokerPackage}}\Configuration::getDefaultConfiguration()->setApiKeyPrefix('{{{keyParamName}}}', 'Bearer');{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
{{phpInvokerPackage}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/isOAuth}}{{/authMethods}}
{{phpInvokerPackage}}\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
// Create an instance of the API class
$api_instance = new OpenAPITools\Client\Api\{{classname}}();
{{#allParams}}${{paramName}} = {{{example}}}; // {{{dataType}}} | {{{unescapedDescription}}}
{{/allParams}}

View File

@ -3,19 +3,24 @@ import time
import {{{pythonPackageName}}}
from {{{pythonPackageName}}}.rest import ApiException
from pprint import pprint
{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}
{{#hasAuthMethods}}
{{#authMethods}}
{{^isBasicBearer}}{{#isBasic}}
# Configure HTTP basic authorization: {{{name}}}
{{{pythonPackageName}}}.configuration.username = 'YOUR_USERNAME'
{{{pythonPackageName}}}.configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{#isApiKey}}
{{{pythonPackageName}}}.configuration.password = 'YOUR_PASSWORD'{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}}
# Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}}
{{{pythonPackageName}}}.configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isBasicBearer}}{{#isApiKey}}
# Configure API key authorization: {{{name}}}
{{{pythonPackageName}}}.configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# {{{pythonPackageName}}}.configuration.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
# Configure OAuth2 access token for authorization: {{{name}}}
{{{pythonPackageName}}}.configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}{{/authMethods}}
{{{pythonPackageName}}}.configuration.access_token = 'YOUR_ACCESS_TOKEN'{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
# create an instance of the API class
# Create an instance of the API class
api_instance = {{{pythonPackageName}}}.{{{classname}}}()
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{unescapedDescription}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}

View File

@ -6,6 +6,6 @@ pub fn main() {
let mut context = {{classname}}::Context::default();
let result = client.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}&context).wait();
println!("{:?}", result);
println!("{:?}", result);
}