From c08e45bd82578bb929afc33eb009568aaa971981 Mon Sep 17 00:00:00 2001 From: Shubham Date: Thu, 12 Dec 2024 14:59:48 +0530 Subject: [PATCH] chore: handle versionless orgs api for node, ruby, python, php (#624) --- .gitignore | 3 +- examples/node/src/rest/PreviewIamBase.ts | 14 + examples/node/src/rest/Twilio.ts | 5 + examples/node/src/rest/api/v2010/account.ts | 10 + .../node/src/rest/api/v2010/account/call.ts | 8 + .../v2010/account/call/feedbackCallSummary.ts | 1 + examples/node/src/rest/flexApi/v1/call.ts | 4 + .../src/rest/flexApi/v1/credential/aws.ts | 9 + .../rest/flexApi/v1/credential/aws/history.ts | 1 + .../flexApi/v1/credential/newCredentials.ts | 1 + examples/node/src/rest/previewIam/V1.ts | 46 ++ .../node/src/rest/previewIam/v1/authorize.ts | 174 ++++++ examples/node/src/rest/previewIam/v1/token.ts | 203 +++++++ .../versionless/deployed_devices/fleet.ts | 5 + .../rest/versionless/understand/assistant.ts | 1 + examples/python/twilio/rest/__init__.py | 5 + .../twilio/rest/api/v2010/account/__init__.py | 72 ++- .../rest/api/v2010/account/call/__init__.py | 38 +- .../account/call/feedback_call_summary.py | 20 +- .../python/twilio/rest/flex_api/v1/call.py | 16 +- .../flex_api/v1/credential/aws/__init__.py | 64 +- .../flex_api/v1/credential/aws/history.py | 16 +- .../flex_api/v1/credential/new_credentials.py | 8 + .../twilio/rest/preview_iam/v1/__init__.py | 50 ++ .../twilio/rest/preview_iam/v1/authorize.py | 131 ++++ .../twilio/rest/preview_iam/v1/token.py | 171 ++++++ .../versionless/deployed_devices/fleet.py | 24 +- .../rest/versionless/understand/assistant.py | 14 +- .../lib/twilio-ruby/rest/api/v2010/account.rb | 7 +- .../rest/api/v2010/account/call.rb | 4 +- examples/ruby/lib/twilio-ruby/rest/client.rb | 4 + .../rest/flex_api/v1/credential/aws.rb | 3 +- .../flex_api/v1/credential/new_credentials.rb | 8 +- .../ruby/lib/twilio-ruby/rest/preview_iam.rb | 9 + .../lib/twilio-ruby/rest/preview_iam/v1.rb | 48 ++ .../rest/preview_iam/v1/authorize.rb | 138 +++++ .../twilio-ruby/rest/preview_iam/v1/token.rb | 176 ++++++ .../lib/twilio-ruby/rest/preview_iam_base.rb | 42 ++ .../rest/versionless/understand/assistant.rb | 3 +- .../spec/twilio_iam_organizations_v1.yaml | 572 ++++++++++++++++++ scripts/build_twilio_library.py | 36 +- scripts/generate.sh | 3 + scripts/process_orgs_api.py | 61 ++ .../twilio/oai/DirectoryStructureService.java | 14 + .../oai/api/NodeApiResourceBuilder.java | 1 + .../oai/api/PythonApiResourceBuilder.java | 4 +- .../oai/api/RubyApiResourceBuilder.java | 25 + .../python/PythonCodegenModelResolver.java | 3 +- .../resources/twilio-node/api-single.mustache | 14 +- src/main/resources/twilio-node/model.mustache | 2 +- .../resources/twilio-node/operation.mustache | 27 +- .../twilio-node/operationSignature.mustache | 3 +- .../twilio-python/context.handlebars | 100 ++- .../twilio-python/instance.handlebars | 1 + .../twilio-python/listOperations.handlebars | 82 ++- .../twilio-python/modelClasses.handlebars | 2 +- .../twilio-ruby/contextMethodParams.mustache | 6 +- src/main/resources/twilio-ruby/list.mustache | 5 +- .../resources/twilio-ruby/methods.mustache | 2 +- .../twilio-ruby/modelClasses.mustache | 4 +- twilio_am_temp.json | 143 +++++ 61 files changed, 2515 insertions(+), 151 deletions(-) create mode 100644 examples/node/src/rest/PreviewIamBase.ts create mode 100644 examples/node/src/rest/previewIam/V1.ts create mode 100644 examples/node/src/rest/previewIam/v1/authorize.ts create mode 100644 examples/node/src/rest/previewIam/v1/token.ts create mode 100644 examples/python/twilio/rest/preview_iam/v1/__init__.py create mode 100644 examples/python/twilio/rest/preview_iam/v1/authorize.py create mode 100644 examples/python/twilio/rest/preview_iam/v1/token.py create mode 100644 examples/ruby/lib/twilio-ruby/rest/preview_iam.rb create mode 100644 examples/ruby/lib/twilio-ruby/rest/preview_iam/v1.rb create mode 100644 examples/ruby/lib/twilio-ruby/rest/preview_iam/v1/authorize.rb create mode 100644 examples/ruby/lib/twilio-ruby/rest/preview_iam/v1/token.rb create mode 100644 examples/ruby/lib/twilio-ruby/rest/preview_iam_base.rb create mode 100644 examples/spec/twilio_iam_organizations_v1.yaml create mode 100644 scripts/process_orgs_api.py create mode 100644 twilio_am_temp.json diff --git a/.gitignore b/.gitignore index a430b245b..3663479a0 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ tmp **/execution-result.xml **/php_coverage.xml *.iml -generateFiles.py \ No newline at end of file +generateFiles.py +temp_specs/ diff --git a/examples/node/src/rest/PreviewIamBase.ts b/examples/node/src/rest/PreviewIamBase.ts new file mode 100644 index 000000000..bdbb2f2f9 --- /dev/null +++ b/examples/node/src/rest/PreviewIamBase.ts @@ -0,0 +1,14 @@ +import Domain from "../base/Domain"; +import V1 from "./previewIam/V1"; + +class PreviewIamBase extends Domain { + constructor(twilio: any) { + super(twilio, "https://preview-iam.twilio.com"); + } + + get v1(): V1 { + return new V1(this); + } +} + +export = PreviewIamBase; diff --git a/examples/node/src/rest/Twilio.ts b/examples/node/src/rest/Twilio.ts index 435f09a6b..6cf7f44a2 100644 --- a/examples/node/src/rest/Twilio.ts +++ b/examples/node/src/rest/Twilio.ts @@ -2,6 +2,7 @@ import { Client, ClientOpts } from "../base/BaseTwilio"; import ApiBase from "./ApiBase"; import FlexApiBase from "./FlexApiBase"; import VersionlessBase from "./VersionlessBase"; +import PreviewIamBase = require("./PreviewIamBase"); class Twilio extends Client { constructor(username?: string, password?: string, opts?: ClientOpts) { @@ -19,6 +20,10 @@ class Twilio extends Client { get versionless(): VersionlessBase { return new VersionlessBase(this); } + + get previewIam(): PreviewIamBase { + return new PreviewIamBase(this); + } } export = Twilio; diff --git a/examples/node/src/rest/api/v2010/account.ts b/examples/node/src/rest/api/v2010/account.ts index 64c92cdc1..bd64dc28f 100644 --- a/examples/node/src/rest/api/v2010/account.ts +++ b/examples/node/src/rest/api/v2010/account.ts @@ -197,11 +197,14 @@ export class AccountContextImpl implements AccountContext { remove( callback?: (error: Error | null, item?: boolean) => any, ): Promise { + const headers: any = {}; + const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.remove({ uri: instance._uri, method: "delete", + headers, }); operationPromise = instance._version.setPromiseCallback( @@ -214,11 +217,15 @@ export class AccountContextImpl implements AccountContext { fetch( callback?: (error: Error | null, item?: AccountInstance) => any, ): Promise { + const headers: any = {}; + headers["Accept"] = "application/json"; + const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get", + headers, }); operationPromise = operationPromise.then( @@ -254,6 +261,7 @@ export class AccountContextImpl implements AccountContext { const headers: any = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, @@ -607,6 +615,7 @@ export function AccountListInstance(version: V2010): AccountListInstance { const headers: any = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; if (params["xTwilioWebhookEnabled"] !== undefined) headers["X-Twilio-Webhook-Enabled"] = params["xTwilioWebhookEnabled"]; @@ -662,6 +671,7 @@ export function AccountListInstance(version: V2010): AccountListInstance { if (params.pageToken !== undefined) data["PageToken"] = params.pageToken; const headers: any = {}; + headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.page({ diff --git a/examples/node/src/rest/api/v2010/account/call.ts b/examples/node/src/rest/api/v2010/account/call.ts index 08edabcb0..fc6d59abe 100644 --- a/examples/node/src/rest/api/v2010/account/call.ts +++ b/examples/node/src/rest/api/v2010/account/call.ts @@ -106,11 +106,14 @@ export class CallContextImpl implements CallContext { remove( callback?: (error: Error | null, item?: boolean) => any, ): Promise { + const headers: any = {}; + const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.remove({ uri: instance._uri, method: "delete", + headers, }); operationPromise = instance._version.setPromiseCallback( @@ -123,11 +126,15 @@ export class CallContextImpl implements CallContext { fetch( callback?: (error: Error | null, item?: CallInstance) => any, ): Promise { + const headers: any = {}; + headers["Accept"] = "application/json"; + const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get", + headers, }); operationPromise = operationPromise.then( @@ -415,6 +422,7 @@ export function CallListInstance( const headers: any = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.create({ diff --git a/examples/node/src/rest/api/v2010/account/call/feedbackCallSummary.ts b/examples/node/src/rest/api/v2010/account/call/feedbackCallSummary.ts index f1edee7dc..0d11b1753 100644 --- a/examples/node/src/rest/api/v2010/account/call/feedbackCallSummary.ts +++ b/examples/node/src/rest/api/v2010/account/call/feedbackCallSummary.ts @@ -120,6 +120,7 @@ export class FeedbackCallSummaryContextImpl const headers: any = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, diff --git a/examples/node/src/rest/flexApi/v1/call.ts b/examples/node/src/rest/flexApi/v1/call.ts index 578b2d70c..331ea05c0 100644 --- a/examples/node/src/rest/flexApi/v1/call.ts +++ b/examples/node/src/rest/flexApi/v1/call.ts @@ -60,11 +60,15 @@ export class CallContextImpl implements CallContext { update( callback?: (error: Error | null, item?: CallInstance) => any, ): Promise { + const headers: any = {}; + headers["Accept"] = "application/json"; + const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.update({ uri: instance._uri, method: "post", + headers, }); operationPromise = operationPromise.then( diff --git a/examples/node/src/rest/flexApi/v1/credential/aws.ts b/examples/node/src/rest/flexApi/v1/credential/aws.ts index 343e72270..d74c9c601 100644 --- a/examples/node/src/rest/flexApi/v1/credential/aws.ts +++ b/examples/node/src/rest/flexApi/v1/credential/aws.ts @@ -152,11 +152,14 @@ export class AwsContextImpl implements AwsContext { remove( callback?: (error: Error | null, item?: boolean) => any, ): Promise { + const headers: any = {}; + const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.remove({ uri: instance._uri, method: "delete", + headers, }); operationPromise = instance._version.setPromiseCallback( @@ -169,11 +172,15 @@ export class AwsContextImpl implements AwsContext { fetch( callback?: (error: Error | null, item?: AwsInstance) => any, ): Promise { + const headers: any = {}; + headers["Accept"] = "application/json"; + const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get", + headers, }); operationPromise = operationPromise.then( @@ -210,6 +217,7 @@ export class AwsContextImpl implements AwsContext { const headers: any = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, @@ -485,6 +493,7 @@ export function AwsListInstance(version: V1): AwsListInstance { if (params.pageToken !== undefined) data["PageToken"] = params.pageToken; const headers: any = {}; + headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.page({ diff --git a/examples/node/src/rest/flexApi/v1/credential/aws/history.ts b/examples/node/src/rest/flexApi/v1/credential/aws/history.ts index 5905ba494..ad11e62e2 100644 --- a/examples/node/src/rest/flexApi/v1/credential/aws/history.ts +++ b/examples/node/src/rest/flexApi/v1/credential/aws/history.ts @@ -99,6 +99,7 @@ export class HistoryContextImpl implements HistoryContext { }; const headers: any = {}; + headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, diff --git a/examples/node/src/rest/flexApi/v1/credential/newCredentials.ts b/examples/node/src/rest/flexApi/v1/credential/newCredentials.ts index 0c662fd68..42d342f48 100644 --- a/examples/node/src/rest/flexApi/v1/credential/newCredentials.ts +++ b/examples/node/src/rest/flexApi/v1/credential/newCredentials.ts @@ -159,6 +159,7 @@ export function NewCredentialsListInstance( const headers: any = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.create({ diff --git a/examples/node/src/rest/previewIam/V1.ts b/examples/node/src/rest/previewIam/V1.ts new file mode 100644 index 000000000..6a27dc820 --- /dev/null +++ b/examples/node/src/rest/previewIam/V1.ts @@ -0,0 +1,46 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import PreviewIamBase from "../PreviewIamBase"; +import Version from "../../base/Version"; +import { AuthorizeListInstance } from "./v1/authorize"; +import { TokenListInstance } from "./v1/token"; + +export default class V1 extends Version { + /** + * Initialize the V1 version of PreviewIam + * + * @param domain - The Twilio (Twilio.PreviewIam) domain + */ + constructor(domain: PreviewIamBase) { + super(domain, "v1"); + } + + /** authorize - { Twilio.PreviewIam.V1.AuthorizeListInstance } resource */ + protected _authorize?: AuthorizeListInstance; + /** token - { Twilio.PreviewIam.V1.TokenListInstance } resource */ + protected _token?: TokenListInstance; + + /** Getter for authorize resource */ + get authorize(): AuthorizeListInstance { + this._authorize = this._authorize || AuthorizeListInstance(this); + return this._authorize; + } + + /** Getter for token resource */ + get token(): TokenListInstance { + this._token = this._token || TokenListInstance(this); + return this._token; + } +} diff --git a/examples/node/src/rest/previewIam/v1/authorize.ts b/examples/node/src/rest/previewIam/v1/authorize.ts new file mode 100644 index 000000000..476a4eb78 --- /dev/null +++ b/examples/node/src/rest/previewIam/v1/authorize.ts @@ -0,0 +1,174 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { inspect, InspectOptions } from "util"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + +/** + * Options to pass to fetch a AuthorizeInstance + */ +export interface AuthorizeListInstanceFetchOptions { + /** Response Type */ + responseType?: string; + /** The Client Identifier */ + clientId?: string; + /** The url to which response will be redirected to */ + redirectUri?: string; + /** The scope of the access request */ + scope?: string; + /** An opaque value which can be used to maintain state between the request and callback */ + state?: string; +} + +export interface AuthorizeSolution {} + +export interface AuthorizeListInstance { + _version: V1; + _solution: AuthorizeSolution; + _uri: string; + + /** + * Fetch a AuthorizeInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AuthorizeInstance + */ + fetch( + callback?: (error: Error | null, item?: AuthorizeInstance) => any, + ): Promise; + /** + * Fetch a AuthorizeInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AuthorizeInstance + */ + fetch( + params: AuthorizeListInstanceFetchOptions, + callback?: (error: Error | null, item?: AuthorizeInstance) => any, + ): Promise; + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function AuthorizeListInstance(version: V1): AuthorizeListInstance { + const instance = {} as AuthorizeListInstance; + + instance._version = version; + instance._solution = {}; + instance._uri = `/authorize`; + + instance.fetch = function fetch( + params?: + | AuthorizeListInstanceFetchOptions + | ((error: Error | null, items: AuthorizeInstance) => any), + callback?: (error: Error | null, items: AuthorizeInstance) => any, + ): Promise { + if (params instanceof Function) { + callback = params; + params = {}; + } else { + params = params || {}; + } + + let data: any = {}; + + if (params["responseType"] !== undefined) + data["response_type"] = params["responseType"]; + if (params["clientId"] !== undefined) + data["client_id"] = params["clientId"]; + if (params["redirectUri"] !== undefined) + data["redirect_uri"] = params["redirectUri"]; + if (params["scope"] !== undefined) data["scope"] = params["scope"]; + if (params["state"] !== undefined) data["state"] = params["state"]; + + const headers: any = {}; + headers["Accept"] = "application/json"; + + let operationVersion = version, + operationPromise = operationVersion.fetch({ + uri: instance._uri, + method: "get", + params: data, + headers, + }); + + operationPromise = operationPromise.then( + (payload) => new AuthorizeInstance(operationVersion, payload), + ); + + operationPromise = instance._version.setPromiseCallback( + operationPromise, + callback, + ); + return operationPromise; + }; + + instance.toJSON = function toJSON() { + return instance._solution; + }; + + instance[inspect.custom] = function inspectImpl( + _depth: any, + options: InspectOptions, + ) { + return inspect(instance.toJSON(), options); + }; + + return instance; +} + +interface AuthorizePayload extends AuthorizeResource {} + +interface AuthorizeResource { + redirect_to: string; +} + +export class AuthorizeInstance { + constructor( + protected _version: V1, + payload: AuthorizeResource, + ) { + this.redirectTo = payload.redirect_to; + } + + /** + * The callback URL + */ + redirectTo: string; + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + redirectTo: this.redirectTo, + }; + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} diff --git a/examples/node/src/rest/previewIam/v1/token.ts b/examples/node/src/rest/previewIam/v1/token.ts new file mode 100644 index 000000000..dccf7a7cf --- /dev/null +++ b/examples/node/src/rest/previewIam/v1/token.ts @@ -0,0 +1,203 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { inspect, InspectOptions } from "util"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + +/** + * Options to pass to create a TokenInstance + */ +export interface TokenListInstanceCreateOptions { + /** Grant type is a credential representing resource owner\\\'s authorization which can be used by client to obtain access token. */ + grantType: string; + /** A 34 character string that uniquely identifies this OAuth App. */ + clientId: string; + /** The credential for confidential OAuth App. */ + clientSecret?: string; + /** JWT token related to the authorization code grant type. */ + code?: string; + /** The redirect uri */ + redirectUri?: string; + /** The targeted audience uri */ + audience?: string; + /** JWT token related to refresh access token. */ + refreshToken?: string; + /** The scope of token */ + scope?: string; +} + +export interface TokenSolution {} + +export interface TokenListInstance { + _version: V1; + _solution: TokenSolution; + _uri: string; + + /** + * Create a TokenInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed TokenInstance + */ + create( + params: TokenListInstanceCreateOptions, + callback?: (error: Error | null, item?: TokenInstance) => any, + ): Promise; + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function TokenListInstance(version: V1): TokenListInstance { + const instance = {} as TokenListInstance; + + instance._version = version; + instance._solution = {}; + instance._uri = `/token`; + + instance.create = function create( + params: TokenListInstanceCreateOptions, + callback?: (error: Error | null, items: TokenInstance) => any, + ): Promise { + if (params === null || params === undefined) { + throw new Error('Required parameter "params" missing.'); + } + + if (params["grantType"] === null || params["grantType"] === undefined) { + throw new Error("Required parameter \"params['grantType']\" missing."); + } + + if (params["clientId"] === null || params["clientId"] === undefined) { + throw new Error("Required parameter \"params['clientId']\" missing."); + } + + let data: any = {}; + + data["grant_type"] = params["grantType"]; + + data["client_id"] = params["clientId"]; + if (params["clientSecret"] !== undefined) + data["client_secret"] = params["clientSecret"]; + if (params["code"] !== undefined) data["code"] = params["code"]; + if (params["redirectUri"] !== undefined) + data["redirect_uri"] = params["redirectUri"]; + if (params["audience"] !== undefined) data["audience"] = params["audience"]; + if (params["refreshToken"] !== undefined) + data["refresh_token"] = params["refreshToken"]; + if (params["scope"] !== undefined) data["scope"] = params["scope"]; + + const headers: any = {}; + headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; + + let operationVersion = version, + operationPromise = operationVersion.create({ + uri: instance._uri, + method: "post", + data, + headers, + }); + + operationPromise = operationPromise.then( + (payload) => new TokenInstance(operationVersion, payload), + ); + + operationPromise = instance._version.setPromiseCallback( + operationPromise, + callback, + ); + return operationPromise; + }; + + instance.toJSON = function toJSON() { + return instance._solution; + }; + + instance[inspect.custom] = function inspectImpl( + _depth: any, + options: InspectOptions, + ) { + return inspect(instance.toJSON(), options); + }; + + return instance; +} + +interface TokenPayload extends TokenResource {} + +interface TokenResource { + access_token: string; + refresh_token: string; + id_token: string; + token_type: string; + expires_in: number; +} + +export class TokenInstance { + constructor( + protected _version: V1, + payload: TokenResource, + ) { + this.accessToken = payload.access_token; + this.refreshToken = payload.refresh_token; + this.idToken = payload.id_token; + this.tokenType = payload.token_type; + this.expiresIn = payload.expires_in; + } + + /** + * Token which carries the necessary information to access a Twilio resource directly. + */ + accessToken: string; + /** + * Token which carries the information necessary to get a new access token. + */ + refreshToken: string; + /** + * Token which carries the information necessary of user profile. + */ + idToken: string; + /** + * Token type + */ + tokenType: string; + expiresIn: number; + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + accessToken: this.accessToken, + refreshToken: this.refreshToken, + idToken: this.idToken, + tokenType: this.tokenType, + expiresIn: this.expiresIn, + }; + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} diff --git a/examples/node/src/rest/versionless/deployed_devices/fleet.ts b/examples/node/src/rest/versionless/deployed_devices/fleet.ts index 637f88887..ad7935933 100644 --- a/examples/node/src/rest/versionless/deployed_devices/fleet.ts +++ b/examples/node/src/rest/versionless/deployed_devices/fleet.ts @@ -68,11 +68,15 @@ export class FleetContextImpl implements FleetContext { fetch( callback?: (error: Error | null, item?: FleetInstance) => any, ): Promise { + const headers: any = {}; + headers["Accept"] = "application/json"; + const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get", + headers, }); operationPromise = operationPromise.then( @@ -242,6 +246,7 @@ export function FleetListInstance(version: DeployedDevices): FleetListInstance { const headers: any = {}; headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.create({ diff --git a/examples/node/src/rest/versionless/understand/assistant.ts b/examples/node/src/rest/versionless/understand/assistant.ts index 45da858c5..5d875df02 100644 --- a/examples/node/src/rest/versionless/understand/assistant.ts +++ b/examples/node/src/rest/versionless/understand/assistant.ts @@ -169,6 +169,7 @@ export function AssistantListInstance( if (params.pageToken !== undefined) data["PageToken"] = params.pageToken; const headers: any = {}; + headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.page({ diff --git a/examples/python/twilio/rest/__init__.py b/examples/python/twilio/rest/__init__.py index 405592667..5682e57d6 100644 --- a/examples/python/twilio/rest/__init__.py +++ b/examples/python/twilio/rest/__init__.py @@ -43,3 +43,8 @@ def preview(self): from twilio.rest.versionless import Preview return Preview(self) + + def preview_iam(self): + from twilio.rest.preview.iam import PreviewIam + + return PreviewIam(self) diff --git a/examples/python/twilio/rest/api/v2010/account/__init__.py b/examples/python/twilio/rest/api/v2010/account/__init__.py index 57663135b..fb5367c89 100644 --- a/examples/python/twilio/rest/api/v2010/account/__init__.py +++ b/examples/python/twilio/rest/api/v2010/account/__init__.py @@ -231,10 +231,10 @@ def delete(self) -> bool: :returns: True if delete succeeds, False otherwise """ - return self._version.delete( - method="DELETE", - uri=self._uri, - ) + + headers = values.of({}) + + return self._version.delete(method="DELETE", uri=self._uri, headers=headers) async def delete_async(self) -> bool: """ @@ -243,9 +243,11 @@ async def delete_async(self) -> bool: :returns: True if delete succeeds, False otherwise """ + + headers = values.of({}) + return await self._version.delete_async( - method="DELETE", - uri=self._uri, + method="DELETE", uri=self._uri, headers=headers ) def fetch(self) -> AccountInstance: @@ -256,10 +258,11 @@ def fetch(self) -> AccountInstance: :returns: The fetched AccountInstance """ - payload = self._version.fetch( - method="GET", - uri=self._uri, - ) + headers = values.of({}) + + headers["Accept"] = "application/json" + + payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) return AccountInstance( self._version, @@ -275,9 +278,12 @@ async def fetch_async(self) -> AccountInstance: :returns: The fetched AccountInstance """ + headers = values.of({}) + + headers["Accept"] = "application/json" + payload = await self._version.fetch_async( - method="GET", - uri=self._uri, + method="GET", uri=self._uri, headers=headers ) return AccountInstance( @@ -299,17 +305,21 @@ def update( :returns: The updated AccountInstance """ + data = values.of( { "Status": status, "PauseBehavior": pause_behavior, } ) + headers = values.of({}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" payload = self._version.update( - method="POST", - uri=self._uri, - data=data, + method="POST", uri=self._uri, data=data, headers=headers ) return AccountInstance(self._version, payload, sid=self._solution["sid"]) @@ -327,17 +337,21 @@ async def update_async( :returns: The updated AccountInstance """ + data = values.of( { "Status": status, "PauseBehavior": pause_behavior, } ) + headers = values.of({}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" payload = await self._version.update_async( - method="POST", - uri=self._uri, - data=data, + method="POST", uri=self._uri, data=data, headers=headers ) return AccountInstance(self._version, payload, sid=self._solution["sid"]) @@ -430,6 +444,10 @@ def create( } ) + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + payload = self._version.create( method="POST", uri=self._uri, data=data, headers=headers ) @@ -472,6 +490,10 @@ async def create_async( } ) + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + payload = await self._version.create_async( method="POST", uri=self._uri, data=data, headers=headers ) @@ -669,7 +691,13 @@ def page( } ) - response = self._version.page(method="GET", uri=self._uri, params=data) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Accept"] = "application/json" + + response = self._version.page( + method="GET", uri=self._uri, params=data, headers=headers + ) return AccountPage(self._version, response) async def page_async( @@ -708,8 +736,12 @@ async def page_async( } ) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Accept"] = "application/json" + response = await self._version.page_async( - method="GET", uri=self._uri, params=data + method="GET", uri=self._uri, params=data, headers=headers ) return AccountPage(self._version, response) diff --git a/examples/python/twilio/rest/api/v2010/account/call/__init__.py b/examples/python/twilio/rest/api/v2010/account/call/__init__.py index 8bd4b5d7d..bfac5fda2 100644 --- a/examples/python/twilio/rest/api/v2010/account/call/__init__.py +++ b/examples/python/twilio/rest/api/v2010/account/call/__init__.py @@ -194,10 +194,10 @@ def delete(self) -> bool: :returns: True if delete succeeds, False otherwise """ - return self._version.delete( - method="DELETE", - uri=self._uri, - ) + + headers = values.of({}) + + return self._version.delete(method="DELETE", uri=self._uri, headers=headers) async def delete_async(self) -> bool: """ @@ -206,9 +206,11 @@ async def delete_async(self) -> bool: :returns: True if delete succeeds, False otherwise """ + + headers = values.of({}) + return await self._version.delete_async( - method="DELETE", - uri=self._uri, + method="DELETE", uri=self._uri, headers=headers ) def fetch(self) -> CallInstance: @@ -219,10 +221,11 @@ def fetch(self) -> CallInstance: :returns: The fetched CallInstance """ - payload = self._version.fetch( - method="GET", - uri=self._uri, - ) + headers = values.of({}) + + headers["Accept"] = "application/json" + + payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) return CallInstance( self._version, @@ -239,9 +242,12 @@ async def fetch_async(self) -> CallInstance: :returns: The fetched CallInstance """ + headers = values.of({}) + + headers["Accept"] = "application/json" + payload = await self._version.fetch_async( - method="GET", - uri=self._uri, + method="GET", uri=self._uri, headers=headers ) return CallInstance( @@ -308,6 +314,10 @@ def create( ) headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + payload = self._version.create( method="POST", uri=self._uri, data=data, headers=headers ) @@ -344,6 +354,10 @@ async def create_async( ) headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + payload = await self._version.create_async( method="POST", uri=self._uri, data=data, headers=headers ) diff --git a/examples/python/twilio/rest/api/v2010/account/call/feedback_call_summary.py b/examples/python/twilio/rest/api/v2010/account/call/feedback_call_summary.py index 3f962e341..dd4b2139c 100644 --- a/examples/python/twilio/rest/api/v2010/account/call/feedback_call_summary.py +++ b/examples/python/twilio/rest/api/v2010/account/call/feedback_call_summary.py @@ -206,6 +206,7 @@ def update( :returns: The updated FeedbackCallSummaryInstance """ + data = values.of( { "EndDate": serialize.iso8601_date(end_date), @@ -213,11 +214,14 @@ def update( "AccountSid": account_sid, } ) + headers = values.of({}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" payload = self._version.update( - method="POST", - uri=self._uri, - data=data, + method="POST", uri=self._uri, data=data, headers=headers ) return FeedbackCallSummaryInstance( @@ -242,6 +246,7 @@ async def update_async( :returns: The updated FeedbackCallSummaryInstance """ + data = values.of( { "EndDate": serialize.iso8601_date(end_date), @@ -249,11 +254,14 @@ async def update_async( "AccountSid": account_sid, } ) + headers = values.of({}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" payload = await self._version.update_async( - method="POST", - uri=self._uri, - data=data, + method="POST", uri=self._uri, data=data, headers=headers ) return FeedbackCallSummaryInstance( diff --git a/examples/python/twilio/rest/flex_api/v1/call.py b/examples/python/twilio/rest/flex_api/v1/call.py index a818b663a..4eb4fc989 100644 --- a/examples/python/twilio/rest/flex_api/v1/call.py +++ b/examples/python/twilio/rest/flex_api/v1/call.py @@ -105,12 +105,14 @@ def update(self) -> CallInstance: :returns: The updated CallInstance """ + data = values.of({}) + headers = values.of({}) + + headers["Accept"] = "application/json" payload = self._version.update( - method="POST", - uri=self._uri, - data=data, + method="POST", uri=self._uri, data=data, headers=headers ) return CallInstance(self._version, payload, sid=self._solution["sid"]) @@ -122,12 +124,14 @@ async def update_async(self) -> CallInstance: :returns: The updated CallInstance """ + data = values.of({}) + headers = values.of({}) + + headers["Accept"] = "application/json" payload = await self._version.update_async( - method="POST", - uri=self._uri, - data=data, + method="POST", uri=self._uri, data=data, headers=headers ) return CallInstance(self._version, payload, sid=self._solution["sid"]) diff --git a/examples/python/twilio/rest/flex_api/v1/credential/aws/__init__.py b/examples/python/twilio/rest/flex_api/v1/credential/aws/__init__.py index 14bb9647d..8c6ee892d 100644 --- a/examples/python/twilio/rest/flex_api/v1/credential/aws/__init__.py +++ b/examples/python/twilio/rest/flex_api/v1/credential/aws/__init__.py @@ -178,10 +178,10 @@ def delete(self) -> bool: :returns: True if delete succeeds, False otherwise """ - return self._version.delete( - method="DELETE", - uri=self._uri, - ) + + headers = values.of({}) + + return self._version.delete(method="DELETE", uri=self._uri, headers=headers) async def delete_async(self) -> bool: """ @@ -190,9 +190,11 @@ async def delete_async(self) -> bool: :returns: True if delete succeeds, False otherwise """ + + headers = values.of({}) + return await self._version.delete_async( - method="DELETE", - uri=self._uri, + method="DELETE", uri=self._uri, headers=headers ) def fetch(self) -> AwsInstance: @@ -203,10 +205,11 @@ def fetch(self) -> AwsInstance: :returns: The fetched AwsInstance """ - payload = self._version.fetch( - method="GET", - uri=self._uri, - ) + headers = values.of({}) + + headers["Accept"] = "application/json" + + payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) return AwsInstance( self._version, @@ -222,9 +225,12 @@ async def fetch_async(self) -> AwsInstance: :returns: The fetched AwsInstance """ + headers = values.of({}) + + headers["Accept"] = "application/json" + payload = await self._version.fetch_async( - method="GET", - uri=self._uri, + method="GET", uri=self._uri, headers=headers ) return AwsInstance( @@ -246,17 +252,21 @@ def update( :returns: The updated AwsInstance """ + data = values.of( { "TestString": test_string, "TestBoolean": serialize.boolean_to_string(test_boolean), } ) + headers = values.of({}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" payload = self._version.update( - method="POST", - uri=self._uri, - data=data, + method="POST", uri=self._uri, data=data, headers=headers ) return AwsInstance(self._version, payload, sid=self._solution["sid"]) @@ -274,17 +284,21 @@ async def update_async( :returns: The updated AwsInstance """ + data = values.of( { "TestString": test_string, "TestBoolean": serialize.boolean_to_string(test_boolean), } ) + headers = values.of({}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" payload = await self._version.update_async( - method="POST", - uri=self._uri, - data=data, + method="POST", uri=self._uri, data=data, headers=headers ) return AwsInstance(self._version, payload, sid=self._solution["sid"]) @@ -468,7 +482,13 @@ def page( } ) - response = self._version.page(method="GET", uri=self._uri, params=data) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Accept"] = "application/json" + + response = self._version.page( + method="GET", uri=self._uri, params=data, headers=headers + ) return AwsPage(self._version, response) async def page_async( @@ -495,8 +515,12 @@ async def page_async( } ) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Accept"] = "application/json" + response = await self._version.page_async( - method="GET", uri=self._uri, params=data + method="GET", uri=self._uri, params=data, headers=headers ) return AwsPage(self._version, response) diff --git a/examples/python/twilio/rest/flex_api/v1/credential/aws/history.py b/examples/python/twilio/rest/flex_api/v1/credential/aws/history.py index 80948bc89..5207f4769 100644 --- a/examples/python/twilio/rest/flex_api/v1/credential/aws/history.py +++ b/examples/python/twilio/rest/flex_api/v1/credential/aws/history.py @@ -126,9 +126,16 @@ def fetch( """ data = values.of({}) + data.update(serialize.prefixed_collapsible_map(add_ons_data, "AddOns")) - payload = self._version.fetch(method="GET", uri=self._uri, params=data) + headers = values.of({}) + + headers["Accept"] = "application/json" + + payload = self._version.fetch( + method="GET", uri=self._uri, params=data, headers=headers + ) return HistoryInstance( self._version, @@ -148,10 +155,15 @@ async def fetch_async( """ data = values.of({}) + data.update(serialize.prefixed_collapsible_map(add_ons_data, "AddOns")) + headers = values.of({}) + + headers["Accept"] = "application/json" + payload = await self._version.fetch_async( - method="GET", uri=self._uri, params=data + method="GET", uri=self._uri, params=data, headers=headers ) return HistoryInstance( diff --git a/examples/python/twilio/rest/flex_api/v1/credential/new_credentials.py b/examples/python/twilio/rest/flex_api/v1/credential/new_credentials.py index 55670de7f..d4a02e023 100644 --- a/examples/python/twilio/rest/flex_api/v1/credential/new_credentials.py +++ b/examples/python/twilio/rest/flex_api/v1/credential/new_credentials.py @@ -141,6 +141,10 @@ def create( ) headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + payload = self._version.create( method="POST", uri=self._uri, data=data, headers=headers ) @@ -218,6 +222,10 @@ async def create_async( ) headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + payload = await self._version.create_async( method="POST", uri=self._uri, data=data, headers=headers ) diff --git a/examples/python/twilio/rest/preview_iam/v1/__init__.py b/examples/python/twilio/rest/preview_iam/v1/__init__.py new file mode 100644 index 000000000..7167617fc --- /dev/null +++ b/examples/python/twilio/rest/preview_iam/v1/__init__.py @@ -0,0 +1,50 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + +from typing import Optional +from twilio.base.version import Version +from twilio.base.domain import Domain +from twilio.rest.preview_iam.v1.authorize import AuthorizeList +from twilio.rest.preview_iam.v1.token import TokenList + + +class V1(Version): + def __init__(self, domain: Domain): + """ + Initialize the V1 version of PreviewIam + + :param domain: The Twilio.preview_iam domain + """ + super().__init__(domain, "v1") + self._authorize: Optional[AuthorizeList] = None + self._token: Optional[TokenList] = None + + @property + def authorize(self) -> AuthorizeList: + if self._authorize is None: + self._authorize = AuthorizeList(self) + return self._authorize + + @property + def token(self) -> TokenList: + if self._token is None: + self._token = TokenList(self) + return self._token + + def __repr__(self) -> str: + """ + Provide a friendly representation + :returns: Machine friendly representation + """ + return "" diff --git a/examples/python/twilio/rest/preview_iam/v1/authorize.py b/examples/python/twilio/rest/preview_iam/v1/authorize.py new file mode 100644 index 000000000..cabda698c --- /dev/null +++ b/examples/python/twilio/rest/preview_iam/v1/authorize.py @@ -0,0 +1,131 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from typing import Any, Dict, Optional, Union +from twilio.base import values + +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version + + +class AuthorizeInstance(InstanceResource): + + """ + :ivar redirect_to: The callback URL + """ + + def __init__(self, version: Version, payload: Dict[str, Any]): + super().__init__(version) + + self.redirect_to: Optional[str] = payload.get("redirect_to") + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + + return "" + + +class AuthorizeList(ListResource): + def __init__(self, version: Version): + """ + Initialize the AuthorizeList + + :param version: Version that contains the resource + + """ + super().__init__(version) + + self._uri = "/authorize" + + def fetch( + self, + response_type: Union[str, object] = values.unset, + client_id: Union[str, object] = values.unset, + redirect_uri: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + state: Union[str, object] = values.unset, + ) -> AuthorizeInstance: + """ + Asynchronously fetch the AuthorizeInstance + + :param response_type: Response Type:param client_id: The Client Identifier:param redirect_uri: The url to which response will be redirected to:param scope: The scope of the access request:param state: An opaque value which can be used to maintain state between the request and callback + :returns: The fetched AuthorizeInstance + """ + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Accept"] = "application/json" + + params = values.of( + { + "response_type": response_type, + "client_id": client_id, + "redirect_uri": redirect_uri, + "scope": scope, + "state": state, + } + ) + + payload = self._version.fetch( + method="GET", uri=self._uri, headers=headers, params=params + ) + + return AuthorizeInstance(self._version, payload) + + async def fetch_async( + self, + response_type: Union[str, object] = values.unset, + client_id: Union[str, object] = values.unset, + redirect_uri: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + state: Union[str, object] = values.unset, + ) -> AuthorizeInstance: + """ + Asynchronously fetch the AuthorizeInstance + + :param response_type: Response Type:param client_id: The Client Identifier:param redirect_uri: The url to which response will be redirected to:param scope: The scope of the access request:param state: An opaque value which can be used to maintain state between the request and callback + :returns: The fetched AuthorizeInstance + """ + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Accept"] = "application/json" + + params = values.of( + { + "response_type": response_type, + "client_id": client_id, + "redirect_uri": redirect_uri, + "scope": scope, + "state": state, + } + ) + + payload = await self._version.fetch_async( + method="GET", uri=self._uri, headers=headers, params=params + ) + + return AuthorizeInstance(self._version, payload) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" diff --git a/examples/python/twilio/rest/preview_iam/v1/token.py b/examples/python/twilio/rest/preview_iam/v1/token.py new file mode 100644 index 000000000..e5b4f7da3 --- /dev/null +++ b/examples/python/twilio/rest/preview_iam/v1/token.py @@ -0,0 +1,171 @@ +r""" + This code was generated by + ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + + Organization Public API + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + NOTE: This class is auto generated by OpenAPI Generator. + https://openapi-generator.tech + Do not edit the class manually. +""" + + +from typing import Any, Dict, Optional, Union +from twilio.base import values + +from twilio.base.instance_resource import InstanceResource +from twilio.base.list_resource import ListResource +from twilio.base.version import Version + + +class TokenInstance(InstanceResource): + + """ + :ivar access_token: Token which carries the necessary information to access a Twilio resource directly. + :ivar refresh_token: Token which carries the information necessary to get a new access token. + :ivar id_token: Token which carries the information necessary of user profile. + :ivar token_type: Token type + :ivar expires_in: + """ + + def __init__(self, version: Version, payload: Dict[str, Any]): + super().__init__(version) + + self.access_token: Optional[str] = payload.get("access_token") + self.refresh_token: Optional[str] = payload.get("refresh_token") + self.id_token: Optional[str] = payload.get("id_token") + self.token_type: Optional[str] = payload.get("token_type") + self.expires_in: Optional[int] = payload.get("expires_in") + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + + return "" + + +class TokenList(ListResource): + def __init__(self, version: Version): + """ + Initialize the TokenList + + :param version: Version that contains the resource + + """ + super().__init__(version) + + self._uri = "/token" + + def create( + self, + grant_type: str, + client_id: str, + client_secret: Union[str, object] = values.unset, + code: Union[str, object] = values.unset, + redirect_uri: Union[str, object] = values.unset, + audience: Union[str, object] = values.unset, + refresh_token: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + ) -> TokenInstance: + """ + Create the TokenInstance + + :param grant_type: Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + :param client_id: A 34 character string that uniquely identifies this OAuth App. + :param client_secret: The credential for confidential OAuth App. + :param code: JWT token related to the authorization code grant type. + :param redirect_uri: The redirect uri + :param audience: The targeted audience uri + :param refresh_token: JWT token related to refresh access token. + :param scope: The scope of token + + :returns: The created TokenInstance + """ + + data = values.of( + { + "grant_type": grant_type, + "client_id": client_id, + "client_secret": client_secret, + "code": code, + "redirect_uri": redirect_uri, + "audience": audience, + "refresh_token": refresh_token, + "scope": scope, + } + ) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + + payload = self._version.create( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return TokenInstance(self._version, payload) + + async def create_async( + self, + grant_type: str, + client_id: str, + client_secret: Union[str, object] = values.unset, + code: Union[str, object] = values.unset, + redirect_uri: Union[str, object] = values.unset, + audience: Union[str, object] = values.unset, + refresh_token: Union[str, object] = values.unset, + scope: Union[str, object] = values.unset, + ) -> TokenInstance: + """ + Asynchronously create the TokenInstance + + :param grant_type: Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + :param client_id: A 34 character string that uniquely identifies this OAuth App. + :param client_secret: The credential for confidential OAuth App. + :param code: JWT token related to the authorization code grant type. + :param redirect_uri: The redirect uri + :param audience: The targeted audience uri + :param refresh_token: JWT token related to refresh access token. + :param scope: The scope of token + + :returns: The created TokenInstance + """ + + data = values.of( + { + "grant_type": grant_type, + "client_id": client_id, + "client_secret": client_secret, + "code": code, + "redirect_uri": redirect_uri, + "audience": audience, + "refresh_token": refresh_token, + "scope": scope, + } + ) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + + payload = await self._version.create_async( + method="POST", uri=self._uri, data=data, headers=headers + ) + + return TokenInstance(self._version, payload) + + def __repr__(self) -> str: + """ + Provide a friendly representation + + :returns: Machine friendly representation + """ + return "" diff --git a/examples/python/twilio/rest/versionless/deployed_devices/fleet.py b/examples/python/twilio/rest/versionless/deployed_devices/fleet.py index 453551733..2d226a1ca 100644 --- a/examples/python/twilio/rest/versionless/deployed_devices/fleet.py +++ b/examples/python/twilio/rest/versionless/deployed_devices/fleet.py @@ -110,10 +110,11 @@ def fetch(self) -> FleetInstance: :returns: The fetched FleetInstance """ - payload = self._version.fetch( - method="GET", - uri=self._uri, - ) + headers = values.of({}) + + headers["Accept"] = "application/json" + + payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) return FleetInstance( self._version, @@ -129,9 +130,12 @@ async def fetch_async(self) -> FleetInstance: :returns: The fetched FleetInstance """ + headers = values.of({}) + + headers["Accept"] = "application/json" + payload = await self._version.fetch_async( - method="GET", - uri=self._uri, + method="GET", uri=self._uri, headers=headers ) return FleetInstance( @@ -178,6 +182,10 @@ def create(self, name: Union[str, object] = values.unset) -> FleetInstance: ) headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + payload = self._version.create( method="POST", uri=self._uri, data=data, headers=headers ) @@ -202,6 +210,10 @@ async def create_async( ) headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + payload = await self._version.create_async( method="POST", uri=self._uri, data=data, headers=headers ) diff --git a/examples/python/twilio/rest/versionless/understand/assistant.py b/examples/python/twilio/rest/versionless/understand/assistant.py index 56a998849..18b4b06a2 100644 --- a/examples/python/twilio/rest/versionless/understand/assistant.py +++ b/examples/python/twilio/rest/versionless/understand/assistant.py @@ -202,7 +202,13 @@ def page( } ) - response = self._version.page(method="GET", uri=self._uri, params=data) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Accept"] = "application/json" + + response = self._version.page( + method="GET", uri=self._uri, params=data, headers=headers + ) return AssistantPage(self._version, response) async def page_async( @@ -229,8 +235,12 @@ async def page_async( } ) + headers = values.of({"Content-Type": "application/x-www-form-urlencoded"}) + + headers["Accept"] = "application/json" + response = await self._version.page_async( - method="GET", uri=self._uri, params=data + method="GET", uri=self._uri, params=data, headers=headers ) return AssistantPage(self._version, response) diff --git a/examples/ruby/lib/twilio-ruby/rest/api/v2010/account.rb b/examples/ruby/lib/twilio-ruby/rest/api/v2010/account.rb index 957169297..2ba539c11 100644 --- a/examples/ruby/lib/twilio-ruby/rest/api/v2010/account.rb +++ b/examples/ruby/lib/twilio-ruby/rest/api/v2010/account.rb @@ -45,8 +45,8 @@ def create( data = Twilio::Values.of({ 'RecordingStatusCallback' => recording_status_callback, 'RecordingStatusCallbackEvent' => Twilio.serialize_list(recording_status_callback_event) { |e| - e - }, + e + }, 'Twiml' => twiml, }) @@ -153,8 +153,9 @@ def page(date_created: :unset, date_test: :unset, date_created_before: :unset, 'Page' => page_number, 'PageSize' => page_size, }) + headers = Twilio::Values.of({}) - response = @version.page('GET', @uri, params: params) + response = @version.page('GET', @uri, params: params, headers: headers) AccountPage.new(@version, response, @solution) end diff --git a/examples/ruby/lib/twilio-ruby/rest/api/v2010/account/call.rb b/examples/ruby/lib/twilio-ruby/rest/api/v2010/account/call.rb index 0bd991e4b..be5fad79f 100644 --- a/examples/ruby/lib/twilio-ruby/rest/api/v2010/account/call.rb +++ b/examples/ruby/lib/twilio-ruby/rest/api/v2010/account/call.rb @@ -49,8 +49,8 @@ def create( 'RequiredStringProperty' => required_string_property, 'TestMethod' => test_method, 'TestArrayOfStrings' => Twilio.serialize_list(test_array_of_strings) { |e| - e - }, + e + }, 'TestArrayOfUri' => Twilio.serialize_list(test_array_of_uri) { |e| e }, }) diff --git a/examples/ruby/lib/twilio-ruby/rest/client.rb b/examples/ruby/lib/twilio-ruby/rest/client.rb index 61599e6f7..6dcc9980f 100644 --- a/examples/ruby/lib/twilio-ruby/rest/client.rb +++ b/examples/ruby/lib/twilio-ruby/rest/client.rb @@ -33,6 +33,10 @@ def versionless @versionless ||= Versionless.new self end + def preview_iam + @previewiam ||= PreviewIam.new self + end + ## # @param [integer] testInteger INTEGER ID param!!! diff --git a/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/aws.rb b/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/aws.rb index 8fc236a3b..c466053c0 100644 --- a/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/aws.rb +++ b/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/aws.rb @@ -95,8 +95,9 @@ def page(page_token: :unset, page_number: :unset, page_size: :unset) 'Page' => page_number, 'PageSize' => page_size, }) + headers = Twilio::Values.of({}) - response = @version.page('GET', @uri, params: params) + response = @version.page('GET', @uri, params: params, headers: headers) AwsPage.new(@version, response, @solution) end diff --git a/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/new_credentials.rb b/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/new_credentials.rb index a22123680..66b3106cc 100644 --- a/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/new_credentials.rb +++ b/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/new_credentials.rb @@ -83,12 +83,12 @@ def create( 'TestDate' => Twilio.serialize_iso8601_date(test_date), 'TestEnum' => test_enum, 'TestObjectArray' => Twilio.serialize_list(test_object_array) { |e| - Twilio.serialize_object(e) - }, + Twilio.serialize_object(e) + }, 'TestAnyType' => Twilio.serialize_object(test_any_type), 'TestAnyArray' => Twilio.serialize_list(test_any_array) { |e| - Twilio.serialize_object(e) - }, + Twilio.serialize_object(e) + }, 'Permissions' => Twilio.serialize_list(permissions) { |e| e }, 'SomeA2PThing' => some_a2p_thing, }) diff --git a/examples/ruby/lib/twilio-ruby/rest/preview_iam.rb b/examples/ruby/lib/twilio-ruby/rest/preview_iam.rb new file mode 100644 index 000000000..a9f6115ed --- /dev/null +++ b/examples/ruby/lib/twilio-ruby/rest/preview_iam.rb @@ -0,0 +1,9 @@ +module Twilio + module REST + class PreviewIam < PreviewIamBase + def organizations(organization_sid = nil) + @organizations ||= PreviewIam::Versionless.new(self).organization(organization_sid) + end + end + end +end diff --git a/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1.rb b/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1.rb new file mode 100644 index 000000000..fe901d7ec --- /dev/null +++ b/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1.rb @@ -0,0 +1,48 @@ +## +# This code was generated by +# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ +# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ +# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ +# +# Organization Public API +# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) +# +# NOTE: This class is auto generated by OpenAPI Generator. +# https://openapi-generator.tech +# Do not edit the class manually. +# + +module Twilio + module REST + class PreviewIam + class V1 < Version + ## + # Initialize the V1 version of PreviewIam + def initialize(domain) + super + @version = 'v1' + @authorize = nil + @token = nil + end + + ## + # @return [Twilio::REST::PreviewIam::V1::AuthorizeList] + def authorize + @authorize ||= AuthorizeList.new self + end + + ## + # @return [Twilio::REST::PreviewIam::V1::TokenList] + def token + @token ||= TokenList.new self + end + + ## + # Provide a user friendly representation + def to_s + ''; + end + end + end + end +end diff --git a/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1/authorize.rb b/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1/authorize.rb new file mode 100644 index 000000000..a75d0c280 --- /dev/null +++ b/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1/authorize.rb @@ -0,0 +1,138 @@ +## +# This code was generated by +# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ +# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ +# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ +# +# Organization Public API +# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) +# +# NOTE: This class is auto generated by OpenAPI Generator. +# https://openapi-generator.tech +# Do not edit the class manually. +# + +module Twilio + module REST + class PreviewIam < PreviewIamBase + class V1 < Version + class AuthorizeList < ListResource + ## + # Initialize the AuthorizeList + # @param [Version] version Version that contains the resource + # @return [AuthorizeList] AuthorizeList + def initialize(version) + super(version) + # Path Solution + @solution = {} + @uri = "/authorize" + end + + ## + # Fetch the AuthorizeInstance + # @param [String] response_type Response Type + # @param [String] client_id The Client Identifier + # @param [String] redirect_uri The url to which response will be redirected to + # @param [String] scope The scope of the access request + # @param [String] state An opaque value which can be used to maintain state between the request and callback + # @return [AuthorizeInstance] Fetched AuthorizeInstance + def fetch( + response_type: :unset, + client_id: :unset, + redirect_uri: :unset, + scope: :unset, + state: :unset + ) + + params = Twilio::Values.of({ + 'response_type' => response_type, + 'client_id' => client_id, + 'redirect_uri' => redirect_uri, + 'scope' => scope, + 'state' => state, + }) + headers = Twilio::Values.of({ 'Content-Type' => 'application/x-www-form-urlencoded', }) + + payload = @version.fetch('GET', @uri, params: params, headers: headers) + AuthorizeInstance.new( + @version, + payload, + ) + end + + # Provide a user friendly representation + def to_s + '#' + end + end + + class AuthorizePage < Page + ## + # Initialize the AuthorizePage + # @param [Version] version Version that contains the resource + # @param [Response] response Response from the API + # @param [Hash] solution Path solution for the resource + # @return [AuthorizePage] AuthorizePage + def initialize(version, response, solution) + super(version, response) + + # Path Solution + @solution = solution + end + + ## + # Build an instance of AuthorizeInstance + # @param [Hash] payload Payload response from the API + # @return [AuthorizeInstance] AuthorizeInstance + def get_instance(payload) + AuthorizeInstance.new(@version, payload) + end + + ## + # Provide a user friendly representation + def to_s + '' + end + end + + class AuthorizeInstance < InstanceResource + ## + # Initialize the AuthorizeInstance + # @param [Version] version Version that contains the resource + # @param [Hash] payload payload that contains response from Twilio + # @param [String] account_sid The SID of the + # {Account}[https://www.twilio.com/docs/iam/api/account] that created this Authorize + # resource. + # @param [String] sid The SID of the Call resource to fetch. + # @return [AuthorizeInstance] AuthorizeInstance + def initialize(version, payload) + super(version) + + # Marshaled Properties + @properties = { + 'redirect_to' => payload['redirect_to'], + } + end + + ## + # @return [String] The callback URL + def redirect_to + @properties['redirect_to'] + end + + ## + # Provide a user friendly representation + def to_s + "" + end + + ## + # Provide a detailed, user friendly representation + def inspect + "" + end + end + end + end + end +end diff --git a/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1/token.rb b/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1/token.rb new file mode 100644 index 000000000..28eb386ab --- /dev/null +++ b/examples/ruby/lib/twilio-ruby/rest/preview_iam/v1/token.rb @@ -0,0 +1,176 @@ +## +# This code was generated by +# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ +# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ +# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ +# +# Organization Public API +# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) +# +# NOTE: This class is auto generated by OpenAPI Generator. +# https://openapi-generator.tech +# Do not edit the class manually. +# + +module Twilio + module REST + class PreviewIam < PreviewIamBase + class V1 < Version + class TokenList < ListResource + ## + # Initialize the TokenList + # @param [Version] version Version that contains the resource + # @return [TokenList] TokenList + def initialize(version) + super(version) + # Path Solution + @solution = {} + @uri = "/token" + end + + ## + # Create the TokenInstance + # @param [String] grant_type Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + # @param [String] client_id A 34 character string that uniquely identifies this OAuth App. + # @param [String] client_secret The credential for confidential OAuth App. + # @param [String] code JWT token related to the authorization code grant type. + # @param [String] redirect_uri The redirect uri + # @param [String] audience The targeted audience uri + # @param [String] refresh_token JWT token related to refresh access token. + # @param [String] scope The scope of token + # @return [TokenInstance] Created TokenInstance + def create( + grant_type: nil, + client_id: nil, + client_secret: :unset, + code: :unset, + redirect_uri: :unset, + audience: :unset, + refresh_token: :unset, + scope: :unset + ) + + data = Twilio::Values.of({ + 'grant_type' => grant_type, + 'client_id' => client_id, + 'client_secret' => client_secret, + 'code' => code, + 'redirect_uri' => redirect_uri, + 'audience' => audience, + 'refresh_token' => refresh_token, + 'scope' => scope, + }) + + headers = Twilio::Values.of({ 'Content-Type' => 'application/x-www-form-urlencoded', }) + + payload = @version.create('POST', @uri, data: data, headers: headers) + TokenInstance.new( + @version, + payload, + ) + end + + # Provide a user friendly representation + def to_s + '#' + end + end + + class TokenPage < Page + ## + # Initialize the TokenPage + # @param [Version] version Version that contains the resource + # @param [Response] response Response from the API + # @param [Hash] solution Path solution for the resource + # @return [TokenPage] TokenPage + def initialize(version, response, solution) + super(version, response) + + # Path Solution + @solution = solution + end + + ## + # Build an instance of TokenInstance + # @param [Hash] payload Payload response from the API + # @return [TokenInstance] TokenInstance + def get_instance(payload) + TokenInstance.new(@version, payload) + end + + ## + # Provide a user friendly representation + def to_s + '' + end + end + + class TokenInstance < InstanceResource + ## + # Initialize the TokenInstance + # @param [Version] version Version that contains the resource + # @param [Hash] payload payload that contains response from Twilio + # @param [String] account_sid The SID of the + # {Account}[https://www.twilio.com/docs/iam/api/account] that created this Token + # resource. + # @param [String] sid The SID of the Call resource to fetch. + # @return [TokenInstance] TokenInstance + def initialize(version, payload) + super(version) + + # Marshaled Properties + @properties = { + 'access_token' => payload['access_token'], + 'refresh_token' => payload['refresh_token'], + 'id_token' => payload['id_token'], + 'token_type' => payload['token_type'], + 'expires_in' => payload['expires_in'], + } + end + + ## + # @return [String] Token which carries the necessary information to access a Twilio resource directly. + def access_token + @properties['access_token'] + end + + ## + # @return [String] Token which carries the information necessary to get a new access token. + def refresh_token + @properties['refresh_token'] + end + + ## + # @return [String] Token which carries the information necessary of user profile. + def id_token + @properties['id_token'] + end + + ## + # @return [String] Token type + def token_type + @properties['token_type'] + end + + ## + # @return [String] + def expires_in + @properties['expires_in'] + end + + ## + # Provide a user friendly representation + def to_s + "" + end + + ## + # Provide a detailed, user friendly representation + def inspect + "" + end + end + end + end + end +end diff --git a/examples/ruby/lib/twilio-ruby/rest/preview_iam_base.rb b/examples/ruby/lib/twilio-ruby/rest/preview_iam_base.rb new file mode 100644 index 000000000..2f9ae5488 --- /dev/null +++ b/examples/ruby/lib/twilio-ruby/rest/preview_iam_base.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +## +# This code was generated by +# ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ +# | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ +# | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ +# +# NOTE: This class is auto generated by OpenAPI Generator. +# https://openapi-generator.tech +# Do not edit the class manually. +# frozen_string_literal: true + +module Twilio + module REST + class PreviewIamBase < Domain + ## + # Initialize preview domain + # + # @param twilio - The twilio client + # + def initialize(twilio) + super(twilio) + @base_url = "https://preview-iam.twilio.com" + @host = "preview-iam.twilio.com" + @port = 443 + @organizations = nil + @v1 = nil + end + + def v1 + @v1 ||= PreviewIam::V1.new(self) + end + + ## + # Provide a user friendly representation + def to_s + ''; + end + end + end +end diff --git a/examples/ruby/lib/twilio-ruby/rest/versionless/understand/assistant.rb b/examples/ruby/lib/twilio-ruby/rest/versionless/understand/assistant.rb index 279b9a648..ea7d27c17 100644 --- a/examples/ruby/lib/twilio-ruby/rest/versionless/understand/assistant.rb +++ b/examples/ruby/lib/twilio-ruby/rest/versionless/understand/assistant.rb @@ -94,8 +94,9 @@ def page(page_token: :unset, page_number: :unset, page_size: :unset) 'Page' => page_number, 'PageSize' => page_size, }) + headers = Twilio::Values.of({}) - response = @version.page('GET', @uri, params: params) + response = @version.page('GET', @uri, params: params, headers: headers) AssistantPage.new(@version, response, @solution) end diff --git a/examples/spec/twilio_iam_organizations_v1.yaml b/examples/spec/twilio_iam_organizations_v1.yaml new file mode 100644 index 000000000..65e71658c --- /dev/null +++ b/examples/spec/twilio_iam_organizations_v1.yaml @@ -0,0 +1,572 @@ +openapi: 3.0.1 +security: + - oAuth2ClientCredentials: [] +info: + title: Organization Public API + contact: + name: Twilio Support + url: https://support.twilio.com + email: support@twilio.com + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html + version: 1.0.0 +tags: + - name: SCIM + description: SCIM 2.0 User endpoints + - name: OrganizationAccount + description: Organization Account operations + - name: RoleAssignments + description: Role assignment operations + - name: OauthV1Authorize + - name: OauthV1Token +paths: + "/v1/authorize": + servers: + - url: https://preview-iam.twilio.com + x-twilio: + defaultOutputProperties: + - redirect_to + pathType: list + get: + tags: + - OauthV1Authorize + security: [] + summary: Retrieves authorize uri + operationId: FetchAuthorize + parameters: + - name: response_type + in: query + description: Response Type + schema: + type: string + example: code + - name: client_id + in: query + description: The Client Identifier + schema: + type: string + example: OQ7cda1a615f05a95634e643aaaf7081d7 + - name: redirect_uri + in: query + description: The url to which response will be redirected to + schema: + type: string + example: www.twilio.com + - name: scope + in: query + description: The scope of the access request + schema: + type: string + example: offline_access + - name: state + in: query + description: An opaque value which can be used to maintain state between the + request and callback + schema: + type: string + example: xvz + responses: + '302': + content: + application/json: + schema: + "$ref": "#/components/schemas/oauth.v1.authorize" + examples: + fetch: + value: + redirect_to: https://www.twilio.com/authorize?response_type=code&client_id=OQ7cda1a615f05a95634e643aaaf7081d7&redirect_uri=www.twilio.com&scope=offline_access&state=xvz + description: Found + "/v1/token": + servers: + - url: https://preview-iam.twilio.com + x-twilio: + defaultOutputProperties: [] + pathType: list + post: + security: [] + tags: + - OauthV1Token + summary: Issues a new Access token (optionally identity_token & refresh_token) + in exchange of Oauth grant + operationId: CreateToken + responses: + '201': + content: + application/json: + schema: + "$ref": "#/components/schemas/oauth.v1.token" + examples: + create: + value: + access_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c + refresh_token: ghjbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c + id_token: eyJhbdGciOiIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c + expires_in: 1438315200000 + token_type: bearer + description: Created + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + title: CreateTokenRequest + properties: + grant_type: + type: string + description: Grant type is a credential representing resource owner's + authorization which can be used by client to obtain access token. + client_id: + type: string + description: A 34 character string that uniquely identifies this + OAuth App. + client_secret: + type: string + description: The credential for confidential OAuth App. + code: + type: string + description: JWT token related to the authorization code grant type. + redirect_uri: + type: string + description: The redirect uri + audience: + type: string + description: The targeted audience uri + refresh_token: + type: string + description: JWT token related to refresh access token. + scope: + type: string + description: The scope of token + required: + - grant_type + - client_id + examples: + create: + value: + client_id: OQ7cda1a615f05a95634e643aaaf7081d7 + client_secret: sUWblrQ4wx_aYkdAWjHXNvHinynkYOgBoiRyEQUeEntpgDEG47qnBFD98yoEzsTh + grant_type: client_credentials + redirect_uri: '' + audience: '' + code: '' + refresh_token: refresh_token + scope: scope + required: true +components: + securitySchemes: + oAuth2ClientCredentials: + type: oauth2 + flows: + clientCredentials: + tokenUrl: https://preview-iam.twilio.com/v1/token + scopes: {} + schemas: + ScimUser: + required: + - userName + type: object + properties: + id: + type: string + description: Unique Twilio user sid + externalId: + maxLength: 255 + minLength: 2 + type: string + description: External unique resource id defined by provisioning client + userName: + maxLength: 255 + minLength: 2 + type: string + description: Unique username, MUST be same as primary email address + displayName: + maxLength: 255 + minLength: 0 + type: string + description: User friendly display name + name: + "$ref": "#/components/schemas/ScimName" + emails: + maxItems: 2147483647 + minItems: 1 + type: array + description: Email address list of the user. Primary email must be defined + if there are more than 1 email. Primary email must match the username. + items: + "$ref": "#/components/schemas/ScimEmailAddress" + active: + type: boolean + description: Indicates whether the user is active + locale: + type: string + description: User's locale + timezone: + type: string + description: User's time zone + schemas: + type: array + description: An array of URIs that indicate the schemas supported for this + user resource + items: + type: string + description: An array of URIs that indicate the schemas supported for + this user resource + meta: + "$ref": "#/components/schemas/ScimMeta" + ScimUserPage: + type: object + properties: + Resources: + type: array + items: + "$ref": "#/components/schemas/ScimUser" + totalResults: + type: integer + format: int32 + schemas: + type: array + items: + type: string + description: Scim ListResponse schema + ScimEmailAddress: + type: object + properties: + primary: + type: boolean + description: Indicates if this email address is the primary one + value: + maxLength: 160 + minLength: 2 + type: string + description: The actual email address value + type: + maxLength: 64 + minLength: 0 + type: string + description: The type of email address (e.g., work, home, etc.) + description: Email address list of the user. Primary email must be defined if + there are more than 1 email. Primary email must match the username. + ScimMeta: + type: object + properties: + resourceType: + type: string + description: Indicates the type of the resource + created: + type: string + description: The date and time when the resource was created in the system + format: date-time + lastModified: + type: string + description: The date and time when the resource was last modified + format: date-time + version: + type: string + description: A version identifier for the resource. This can be used to + manage resource versioning and concurrency control. + description: Meta + ScimName: + type: object + properties: + givenName: + maxLength: 255 + minLength: 0 + type: string + description: The user's first or given name + familyName: + maxLength: 255 + minLength: 0 + type: string + description: The user's last or family name + description: User's name + ScimResourceTypes: + type: object + properties: + Resources: + type: array + items: + type: object + properties: + name: + type: string + description: Name of the resource type + description: + type: string + description: Description of the resource type + endpoint: + type: string + description: HTTP-addressable endpoint relative to the Base URL of + the service provider + schema: + type: string + description: Primary/base schema URI + JsonPatch: + type: object + properties: + op: + type: string + enum: + - add + - remove + - replace + path: + type: string + value: + type: string + PublicApiCreateAccountRequest: + required: + - friendlyName + type: object + properties: + friendlyName: + maxLength: 255 + minLength: 1 + type: string + description: Account friendly name + ownerSid: + pattern: US[0-9a-f]{32} + type: string + description: Optional owner sid. If not provided, the owner will be the + organization owner. + format: UserSid + example: USa4faef6467378082de67039e533b515a + PublicApiCreateAccountResponse: + type: object + properties: + accountSid: + pattern: AC[0-9a-f]{32} + type: string + description: Twilio account sid for the new account, creation is asynchronous + owner. + format: AccountSid + example: ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + PublicApiAccountResponse: + type: object + properties: + account_sid: + pattern: AC[0-9a-f]{32} + type: string + description: Twilio account sid + format: AccountSid + example: ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + friendly_name: + type: string + description: Account friendly name + status: + type: string + description: Account status + example: active + enum: + - active + - suspended + - pending_closure + - closed + owner_sid: + pattern: US[0-9a-f]{32} + type: string + description: Twilio account sid + format: UserSid + example: US9a6d63d00bdbb50aa1c1889b3066bd30 + date_created: + type: string + description: The date and time when the account was created in the system + format: date-time + description: Page content + PublicApiAccountResponsePage: + type: object + properties: + content: + type: array + description: Page content + items: + "$ref": "#/components/schemas/PublicApiAccountResponse" + meta: + properties: + first_page_url: + format: uri + type: string + key: + type: string + next_page_url: + format: uri + nullable: true + type: string + page: + type: integer + page_size: + type: integer + previous_page_url: + format: uri + nullable: true + type: string + url: + format: uri + type: string + type: object + PublicApiCreateRoleAssignmentRequest: + required: + - role_sid + - scope + - identity + type: object + properties: + role_sid: + pattern: IX[0-9a-f]{32} + type: string + description: Twilio Role Sid representing assigned role + format: IamRoleSid + example: IXc4ddb9d0befdb122b0eff334e3084544 + scope: + pattern: "^[A-Z]{2}[0-9a-fA-F]{32}$" + type: string + description: Twilio Sid representing scope of this assignment + format: Sid + example: ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + identity: + pattern: "^[A-Z]{2}[0-9a-fA-F]{32}$" + type: string + description: Twilio Sid representing identity of this assignment + format: Sid + example: USc4ddb9d0befdb122b0eff334e3084544 + PublicApiCreateRoleAssignmentResponsePage: + type: object + properties: + content: + type: array + description: Page content + items: + "$ref": "#/components/schemas/PublicApiRoleAssignmentResponse" + meta: + properties: + first_page_url: + format: uri + type: string + key: + type: string + next_page_url: + format: uri + nullable: true + type: string + page: + type: integer + page_size: + type: integer + previous_page_url: + format: uri + nullable: true + type: string + url: + format: uri + type: string + type: object + PublicApiRoleAssignmentResponse: + type: object + properties: + sid: + pattern: IY[0-9a-f]{32} + type: string + description: Twilio Role Assignment Sid representing this role assignment + format: IamRoleAssignmentSid + example: IYc4ddb9d0befdb122b0eff334e3084544 + role_sid: + pattern: IX[0-9a-f]{32} + type: string + description: Twilio Role Sid representing assigned role + format: IamRoleSid + example: IXc4ddb9d0befdb122b0eff334e3084544 + scope: + pattern: "^[A-Z]{2}[0-9a-fA-F]{32}$" + type: string + description: Twilio Sid representing identity of this assignment + format: Sid + example: ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + identity: + pattern: "^[A-Z]{2}[0-9a-fA-F]{32}$" + type: string + description: Twilio Sid representing scope of this assignment + format: Sid + example: USc4ddb9d0befdb122b0eff334e3084544 + TwilioServiceErrorResponse: + type: object + properties: + code: + description: Twilio-specific error code + type: integer + format: int32 + message: + description: Error message + type: string + moreInfo: + description: Link to Error Code References + type: string + status: + description: HTTP response status code + type: integer + format: int32 + ScimError: + type: object + properties: + schemas: + type: array + description: Schema URIs that define the contents of the error structure + items: + type: string + description: Schema URIs that define the contents of the error structure + detail: + type: string + description: A human-readable description of the error + scimType: + type: string + description: A scimType error code as defined in RFC7644 + enum: + - invalidFilter + - uniqueness + - mutability + - invalidValue + - invalidSyntax + status: + type: string + description: Http status code + code: + description: Twilio-specific error code + type: integer + format: int32 + moreInfo: + description: Link to Error Code References + type: string + oauth.v1.authorize: + type: object + properties: + redirect_to: + type: string + format: uri + nullable: true + description: The callback URL + oauth.v1.token: + type: object + properties: + access_token: + type: string + nullable: true + description: Token which carries the necessary information to access a Twilio + resource directly. + refresh_token: + type: string + nullable: true + description: Token which carries the information necessary to get a new + access token. + id_token: + type: string + nullable: true + description: Token which carries the information necessary of user profile. + token_type: + type: string + nullable: true + description: Token type + expires_in: + type: integer + format: int64 + nullable: true +servers: + - url: https://preview-iam.twilio.com diff --git a/scripts/build_twilio_library.py b/scripts/build_twilio_library.py index 13d248850..b63507b4b 100644 --- a/scripts/build_twilio_library.py +++ b/scripts/build_twilio_library.py @@ -7,6 +7,7 @@ from typing import List, Tuple from clean_unused_imports import remove_unused_imports, remove_duplicate_imports +from process_orgs_api import preprocess_orgs_spec ''' Subdirectories map for maintaining directory @@ -18,8 +19,9 @@ 'php': 'Rest' } generateForLanguages = { - 'twilio_iam_organizations.json' : ['java', 'csharp'] + 'twilio_iam_organizations.json' : ['java', 'csharp', 'python'] } +dynamic_languages = ['node', 'python', 'ruby'] CLEANUP_IMPORT_LANGUAGES = ['java', 'php'] REMOVE_DUPLICATE_IMPORT_LANGUAGES = ['node'] CONFIG_FOLDER = 'tmp' @@ -48,14 +50,20 @@ def generate(spec_folder: str, spec_files: List[str], output_path: str, language for spec_file in spec_files: if spec_file in generateForLanguages: + if language in dynamic_languages: + input_path_versioned, input_path_versionless, spec_dir = preprocess_orgs_spec(spec_folder, spec_file, parent_dir) + generate_domain_for_language(input_path_versioned, config_path, spec_dir, output_path, language, parent_dir) + generate_domain_for_language(input_path_versionless, config_path, spec_dir, output_path, language, parent_dir) if language in generateForLanguages.get(spec_file): generate_domain_for_language(spec_file, config_path, spec_folder, output_path, language, parent_dir) else: generate_domain_for_language(spec_file, config_path, spec_folder, output_path, language, parent_dir) - if spec_files[0] in generateForLanguages and language in generateForLanguages.get(spec_files[0]): - print(f'Generating {output_path} from {spec_folder}') - run_openapi_generator(parent_dir, language) - print(f'Code generation completed at {output_path}') - elif spec_files[0] not in generateForLanguages: + if spec_files[0] in generateForLanguages: + if language in generateForLanguages.get(spec_files[0]) or language in dynamic_languages: + print(f'Generating {output_path} from {spec_folder}') + run_openapi_generator(parent_dir, language) + print(f'Code generation completed at {output_path}') + + else: print(f'Generating {output_path} from {spec_folder}') run_openapi_generator(parent_dir, language) print(f'Code generation completed at {output_path}') @@ -64,6 +72,7 @@ def generate(spec_folder: str, spec_files: List[str], output_path: str, language if language in REMOVE_DUPLICATE_IMPORT_LANGUAGES: remove_duplicate_imports(output_path, language) + def generate_domain_for_language(spec_file: str, config_path: str, spec_folder: str, output_path: str, language: str, parent_dir: str) -> None: full_path = os.path.join(spec_folder, spec_file) full_config_path = os.path.join(config_path, spec_file) @@ -79,13 +88,6 @@ def generate_domain_for_language(spec_file: str, config_path: str, spec_folder: with open(full_config_path, 'w') as f: f.write(json.dumps(config)) - # print(f'Generating {output_path} from {spec_folder}') - # run_openapi_generator(parent_dir, language) - # print(f'Code generation completed at {output_path}') - # if language in CLEANUP_IMPORT_LANGUAGES: - # remove_unused_imports(output_path, language) - # if language in REMOVE_DUPLICATE_IMPORT_LANGUAGES: - # remove_duplicate_imports(output_path, language) def run_openapi_generator(parent_dir: Path, language: str) -> None: properties = '-DapiTests=false' @@ -105,14 +107,6 @@ def get_domain_info(oai_spec_location: str, domain: str, is_file: bool = False) parts = re.split(r'twilio_(.+?)_?(v\d+)?\.', domain, flags=re.IGNORECASE) domain_name = parts[1] api_version = parts[2] or '' - # special handling for files like twilio_lookups_bulk.json. - # This has to be removed when naming is made consistent across all languages - if api_version == '': - index = domain_name.find('_') - if index != -1: - domain_parts = re.split(r'(.+)_(.+)', domain_name, flags=re.IGNORECASE) - domain_name = domain_parts[1] - api_version = domain_parts[2] return full_path, domain_name, api_version diff --git a/scripts/generate.sh b/scripts/generate.sh index fcf9017ad..40ce7519e 100644 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -20,6 +20,9 @@ function generate() { if [ "$1" != "twilio-java" ] && [ "$1" != "twilio-csharp" ] && [[ $api_spec == "examples/spec/twilio_iam_organizations.yaml" ]]; then continue fi + if [ "$1" != "twilio-node" ] && [ "$1" != "twilio-ruby" ] && [ "$1" != "twilio-python" ] && [[ $api_spec == "examples/spec/twilio_iam_organizations_v1.yaml" ]]; then + continue + fi echo "generatorName: $1 inputSpec: $api_spec outputDir: $OUT_DIR diff --git a/scripts/process_orgs_api.py b/scripts/process_orgs_api.py new file mode 100644 index 000000000..20eae0f14 --- /dev/null +++ b/scripts/process_orgs_api.py @@ -0,0 +1,61 @@ +import json +import re +import os +from pathlib import Path + +parent_dir = Path(__file__).parent.parent +temp_spec_path = os.path.join(parent_dir, "twilio_am_temp.json") + +with open(temp_spec_path) as f: + specs = json.load(f) + missing_paths = specs.get("paths") + +def preprocess_orgs_spec(spec_folder:str, spec_file:str, parent_dir: str): + with open(os.path.join(spec_folder, spec_file)) as f: + specs = json.load(f) + paths = specs.get("paths") + for path, path_value in paths.items(): + x_twilio = path_value.get("x-twilio") + if not x_twilio: + x_twilio = {} + if not x_twilio.get("pathType"): + x_twilio["pathType"] = "instance" if path.endswith("}") else "list" + path_value["x-twilio"] = x_twilio + versioned_paths = {path: paths[path] for path in paths.keys() if re.match(r"/v\d+", path)} + version = list(versioned_paths.keys())[0].split("/")[1] + non_versioned_paths = missing_paths + existing_paths = {path: paths[path] for path in paths.keys() if path not in versioned_paths.keys()} + for path, path_value in existing_paths.items(): + x_twilio = path_value.get("x-twilio") + if not x_twilio: + x_twilio = {} + if not x_twilio.get("parent"): + x_twilio["parent"] = "/{OrganizationSid}" + path_value["x-twilio"] = x_twilio + non_versioned_paths.update(existing_paths) + non_versioned_paths.update(missing_paths) + versioned_specs = specs.copy() + versioned_specs["paths"] = versioned_paths + non_versioned_specs = specs.copy() + non_versioned_specs["paths"] = non_versioned_paths + temp_dir = os.path.join(parent_dir, "temp_specs") + if not os.path.exists(temp_dir): + os.makedirs(temp_dir) + spec_file_name = spec_file.split(".")[0] + spec_file_name_versioned = spec_file_name + "_" + version + ".json" + spec_file_name_versionless = spec_file_name + "_versionless.json" + with open(os.path.join(temp_dir, spec_file_name_versioned), 'w') as f: + f.write(json.dumps(versioned_specs, indent=2)) + with open(os.path.join(temp_dir, spec_file_name_versionless), 'w') as f: + f.write(json.dumps(non_versioned_specs, indent=2)) + + with open(os.path.join(temp_dir, spec_file_name_versionless), 'r') as f: + content = f.read() + + # fix param names + content = content.replace("UserSid", "Id") + content = content.replace("RoleAssignmentSid", "Sid") + + with open(os.path.join(temp_dir, spec_file_name_versionless), 'w') as file: + file.write(content) + return spec_file_name_versioned, spec_file_name_versionless, temp_dir diff --git a/src/main/java/com/twilio/oai/DirectoryStructureService.java b/src/main/java/com/twilio/oai/DirectoryStructureService.java index 9b43e51c7..339eda529 100644 --- a/src/main/java/com/twilio/oai/DirectoryStructureService.java +++ b/src/main/java/com/twilio/oai/DirectoryStructureService.java @@ -248,6 +248,20 @@ public List processOperations(final OperationsMap results) { final CodegenOperation firstOperation = operations.stream().findFirst().orElseThrow(); final String version = PathUtils.getFirstPathPart(firstOperation.path); + for(CodegenOperation co : operations){ + if(co.produces != null) + for(Map map : co.produces){ + Map.Entry firstEntry = map.entrySet().iterator().next(); + List> successProduce = new ArrayList<>(); + Map successMap = new HashMap<>(); + successMap.put(firstEntry.getKey(), firstEntry.getValue()); + successProduce.add(successMap); + co.vendorExtensions.put("successProduce", successProduce); + break; + + } + } + additionalProperties.put("version", version); additionalProperties.put("apiVersionPath", getRelativeRoot(firstOperation.baseName)); additionalProperties.put("apiFilename", diff --git a/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java index 59ca136e8..9a3061850 100644 --- a/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/NodeApiResourceBuilder.java @@ -50,6 +50,7 @@ public ApiResourceBuilder updateOperations(final Resolver code if (co.nickname.startsWith("delete")) { addOperationName(co, "Remove"); co.returnType = "boolean"; + co.produces = null; } else if (co.nickname.startsWith("list")) { addOperationName(co, "Page"); co.returnType = apiName + "Page"; diff --git a/src/main/java/com/twilio/oai/api/PythonApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/PythonApiResourceBuilder.java index 4918ed713..244863dd9 100644 --- a/src/main/java/com/twilio/oai/api/PythonApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/PythonApiResourceBuilder.java @@ -102,6 +102,7 @@ public ApiResourceBuilder updateResponseModel(Resolver codegenP model.setName(resourceName); model.getVars().forEach(variable -> { codegenPropertyResolver.resolve(variable, this); + variable.vendorExtensions.put("json-name", variable.baseName); instancePathParams .stream() @@ -138,7 +139,8 @@ public ApiResourceBuilder updateResponseModel(Resolver codegenP getModelByClassname(variable.complexType).ifPresent(model -> { variable.baseType = variable.baseType.replace(variable.datatypeWithEnum, "str"); variable.datatypeWithEnum = "str"; - model.vendorExtensions.put("part-of-response-model", true); + if(!model.vendorExtensions.containsKey("part-of-request-model")) + model.vendorExtensions.put("part-of-response-model", true); }); } }); diff --git a/src/main/java/com/twilio/oai/api/RubyApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/RubyApiResourceBuilder.java index bd0cb4b00..a06e15a38 100644 --- a/src/main/java/com/twilio/oai/api/RubyApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/RubyApiResourceBuilder.java @@ -387,4 +387,29 @@ private ApiResourceBuilder updateVersionData() { updateVersionResources(); return this; } + + protected void categorizeOperations() { + codegenOperationList.stream().filter(operation -> !operation.vendorExtensions.containsKey("x-ignore")).forEach(codegenOperation -> { + boolean isInstanceOperation = PathUtils.isInstanceOperation(codegenOperation); + if (!isInstanceOperation) { + listOperations.add(codegenOperation); + codegenOperation.vendorExtensions.put("listOperation", true); + metaAPIProperties.put("hasListOperation", true); + } else { + instanceOperations.add(codegenOperation); + codegenOperation.vendorExtensions.put("instanceOperation", true); + metaAPIProperties.put("hasInstanceOperation", true); + } + }); + codegenOperationList.stream().forEach(operation -> { + if (operation.hasProduces && operation.produces.size() > 1) + operation.vendorExtensions.put("multipleProduces", true); + else if(operation.hasProduces && operation.produces.get(0).containsKey("mediaType") && operation.produces.get(0).get("mediaType").equals("application/scim+json")) + operation.vendorExtensions.put("scimProduces", true); + }); + codegenOperationList.stream().forEach(operation -> { + if(operation.hasConsumes && operation.consumes.stream().anyMatch(consume -> consume.containsKey("mediaType") && consume.get("mediaType").equals("application/scim+json"))) + operation.vendorExtensions.put("scimConsumes", true); + }); + } } diff --git a/src/main/java/com/twilio/oai/resolver/python/PythonCodegenModelResolver.java b/src/main/java/com/twilio/oai/resolver/python/PythonCodegenModelResolver.java index 0767052fa..95f7d3c7b 100644 --- a/src/main/java/com/twilio/oai/resolver/python/PythonCodegenModelResolver.java +++ b/src/main/java/com/twilio/oai/resolver/python/PythonCodegenModelResolver.java @@ -45,7 +45,7 @@ public CodegenModel resolve(CodegenModel model, ApiResourceBuilder apiResourceBu if (model == null) { return null; } - + model.vendorExtensions.put("part-of-request-model", true); for (CodegenProperty property : model.vars) { CodegenModel nestedModel = resolveNestedModel(property, apiResourceBuilder); if(nestedModel != null) { @@ -63,6 +63,7 @@ public CodegenModel resolve(CodegenModel model, ApiResourceBuilder apiResourceBu else { model.vendorExtensions.put(key, value); } + return value; }); } diff --git a/src/main/resources/twilio-node/api-single.mustache b/src/main/resources/twilio-node/api-single.mustache index 086c0b1e3..b0da46dd3 100644 --- a/src/main/resources/twilio-node/api-single.mustache +++ b/src/main/resources/twilio-node/api-single.mustache @@ -16,6 +16,7 @@ import { {{importName}} } from "./{{apiFilename}}/{{filename}}"; {{>imports}} {{>model}} {{#operations}} +{{^vendorExtensions.x-twilio.ignoreOperation}} {{#vendorExtensions.x-is-read-operation}}{{>listOperationsOptions}}{{/vendorExtensions.x-is-read-operation}} {{#hasParams}} {{^vendorExtensions.x-is-read-operation}} @@ -30,6 +31,7 @@ export interface {{vendorExtensions.x-resource-name}}{{vendorExtensions.x-name}} } {{/vendorExtensions.x-is-read-operation}} {{/hasParams}} +{{/vendorExtensions.x-twilio.ignoreOperation}} {{/operations}} {{#instancePath}} @@ -41,7 +43,9 @@ export interface {{apiName}}Context { {{/dependents}} {{#operations}} +{{^vendorExtensions.x-twilio.ignoreOperation}} {{#vendorExtensions.x-is-context-operation}}{{>operationSignature}}{{/vendorExtensions.x-is-context-operation}} +{{/vendorExtensions.x-twilio.ignoreOperation}} {{/operations}} /** * Provide a user-friendly representation @@ -87,12 +91,14 @@ export class {{apiName}}ContextImpl implements {{apiName}}Context { {{/instanceDependent}} {{/dependents}} {{#operations}} + {{^vendorExtensions.x-twilio.ignoreOperation}} {{#vendorExtensions.x-is-context-operation}} - {{vendorExtensions.x-name-lower}}({{#hasParams}}params{{^hasRequiredParams}}?{{/hasRequiredParams}}: {{#bodyParam}}{{dataType}}{{/bodyParam}}{{^bodyParam}}{{vendorExtensions.x-resource-name}}{{vendorExtensions.x-name}}Options{{/bodyParam}}{{^hasRequiredParams}} | ((error: Error | null, item?: {{returnType}}) => any){{/hasRequiredParams}}, {{/hasParams}}callback?: (error: Error | null, item?: {{returnType}}) => any): Promise<{{returnType}}> { + {{vendorExtensions.x-name-lower}}({{#hasParams}}params{{^hasRequiredParams}}?{{/hasRequiredParams}}: {{#bodyParam}}{{dataType}}{{/bodyParam}}{{^bodyParam}}{{vendorExtensions.x-resource-name}}{{vendorExtensions.x-name}}Options{{/bodyParam}}{{^hasRequiredParams}} | ((error: Error | null, item?: {{returnType}}) => any){{/hasRequiredParams}}{{#bodyParams.0}}, headers?: any{{/bodyParams.0}},{{/hasParams}}callback?: (error: Error | null, item?: {{returnType}}) => any): Promise<{{returnType}}> { {{>operation}} } {{/vendorExtensions.x-is-context-operation}} + {{/vendorExtensions.x-twilio.ignoreOperation}} {{/operations}} /** * Provide a user-friendly representation @@ -135,8 +141,10 @@ export interface {{apiName}}ListInstance { {{/dependents}} {{#operations}} +{{^vendorExtensions.x-twilio.ignoreOperation}} {{^vendorExtensions.x-is-read-operation}}{{#vendorExtensions.x-is-list-operation}}{{>operationSignature}}{{/vendorExtensions.x-is-list-operation}}{{/vendorExtensions.x-is-read-operation}} {{#vendorExtensions.x-is-read-operation}}{{>listInterfaceFunctions}}{{/vendorExtensions.x-is-read-operation}} +{{/vendorExtensions.x-twilio.ignoreOperation}} {{/operations}} /** * Provide a user-friendly representation @@ -181,14 +189,16 @@ export function {{apiName}}ListInstance(version: {{apiVersionClass}}{{#listPathP {{/instanceDependent}} {{/dependents}} {{#operations}} +{{^vendorExtensions.x-twilio.ignoreOperation}} {{#vendorExtensions.x-is-list-operation}} - instance.{{vendorExtensions.x-name-lower}} = function {{vendorExtensions.x-name-lower}}({{#hasParams}}params{{^hasRequiredParams}}?{{/hasRequiredParams}}: {{#bodyParam}}{{dataType}}{{/bodyParam}}{{^bodyParam}}{{vendorExtensions.x-resource-name}}{{vendorExtensions.x-name}}Options{{/bodyParam}}{{^hasRequiredParams}} | ((error: Error | null, items: {{returnType}}) => any){{/hasRequiredParams}},{{/hasParams}} callback?: (error: Error | null, items: {{returnType}}) => any): Promise<{{returnType}}> { + instance.{{vendorExtensions.x-name-lower}} = function {{vendorExtensions.x-name-lower}}({{#hasParams}}params{{^hasRequiredParams}}?{{/hasRequiredParams}}: {{#bodyParam}}{{dataType}}{{/bodyParam}}{{^bodyParam}}{{vendorExtensions.x-resource-name}}{{vendorExtensions.x-name}}Options{{/bodyParam}}{{^hasRequiredParams}} | ((error: Error | null, items: {{returnType}}) => any){{/hasRequiredParams}}{{#bodyParams.0}}, headers?: any{{/bodyParams.0}},{{/hasParams}} callback?: (error: Error | null, items: {{returnType}}) => any): Promise<{{returnType}}> { {{>operation}} {{^vendorExtensions.x-is-read-operation}} } {{/vendorExtensions.x-is-read-operation}} {{/vendorExtensions.x-is-list-operation}} +{{/vendorExtensions.x-twilio.ignoreOperation}} {{/operations}} instance.toJSON = function toJSON() { return instance._solution; diff --git a/src/main/resources/twilio-node/model.mustache b/src/main/resources/twilio-node/model.mustache index d3ba41889..db56d6792 100644 --- a/src/main/resources/twilio-node/model.mustache +++ b/src/main/resources/twilio-node/model.mustache @@ -13,7 +13,7 @@ export class {{name}} {{#parent}}extends {{{parent}}} {{/parent}}{ * {{{description}}} */ {{/description}} - "{{name}}"{{^required}}?{{/required}}: {{{dataType}}}{{#isNullable}} | null{{/isNullable}}; + "{{baseName}}"{{^required}}?{{/required}}: {{{dataType}}}{{#isNullable}} | null{{/isNullable}}; {{/vars}} } diff --git a/src/main/resources/twilio-node/operation.mustache b/src/main/resources/twilio-node/operation.mustache index 0398a05c0..da5e1b88e 100644 --- a/src/main/resources/twilio-node/operation.mustache +++ b/src/main/resources/twilio-node/operation.mustache @@ -32,22 +32,45 @@ if (params.pageToken !== undefined) data["PageToken"] = params.pageToken; {{/vendorExtensions.x-is-read-operation}} - const headers: any = {}; + {{#bodyParams}}if(headers === null || headers === undefined) { + headers = {}; + }{{/bodyParams}} + {{^bodyParams}}const headers: any = {};{{/bodyParams}} {{#consumes}} {{#-first}} headers["Content-Type"] = "{{{mediaType}}}" {{/-first}} {{/consumes}} + {{#produces}} + {{#-first}} + headers["Accept"] = "{{{mediaType}}}" + {{/-first}} + {{/produces}} + {{^bodyParams}} {{#headerParams}} if (params["{{paramName}}"] !== undefined) headers["{{{baseName}}}"] = params["{{paramName}}"]; {{/headerParams}} + {{/bodyParams}} +{{/hasParams}} +{{^hasParams}} + const headers: any = {}; + {{#consumes}} + {{#-first}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/-first}} + {{/consumes}} + {{#produces}} + {{#-first}} + headers["Accept"] = "{{{mediaType}}}" + {{/-first}} + {{/produces}} {{/hasParams}} {{#vendorExtensions.x-is-context-operation}} const instance = this; {{/vendorExtensions.x-is-context-operation}} let operationVersion = {{#vendorExtensions.x-is-context-operation}}instance._version{{/vendorExtensions.x-is-context-operation}}{{#vendorExtensions.x-is-list-operation}}version{{/vendorExtensions.x-is-list-operation}}, - operationPromise = operationVersion.{{vendorExtensions.x-name-lower}}({ uri: instance._uri, method: "{{httpMethod}}"{{#hasParams}}, {{^isBodyAllowed}}params: {{/isBodyAllowed}}data, headers{{/hasParams}} }); + operationPromise = operationVersion.{{vendorExtensions.x-name-lower}}({ uri: instance._uri, method: "{{httpMethod}}"{{#hasParams}}, {{^isBodyAllowed}}params: {{/isBodyAllowed}}data{{/hasParams}}, headers}); {{^vendorExtensions.x-is-read-operation}}{{^vendorExtensions.x-is-delete-operation}} operationPromise = operationPromise.then(payload => new {{instanceName}}(operationVersion, payload{{#vendorExtensions.x-is-context-operation}}{{#instancePathParams}}, instance._solution.{{paramName}}{{/instancePathParams}}{{/vendorExtensions.x-is-context-operation}}{{#vendorExtensions.x-is-list-operation}}{{#listPathParams}}, instance._solution.{{paramName}}{{/listPathParams}}{{/vendorExtensions.x-is-list-operation}})); {{/vendorExtensions.x-is-delete-operation}}{{/vendorExtensions.x-is-read-operation}} diff --git a/src/main/resources/twilio-node/operationSignature.mustache b/src/main/resources/twilio-node/operationSignature.mustache index e85dc4c9d..359e99f22 100644 --- a/src/main/resources/twilio-node/operationSignature.mustache +++ b/src/main/resources/twilio-node/operationSignature.mustache @@ -14,6 +14,7 @@ * {{#bodyParam}} * @param params - Body for request + * @param headers - header params for request {{/bodyParam}} {{^bodyParam}} * @param params - Parameter for request @@ -22,5 +23,5 @@ * * @returns Resolves to processed {{instanceName}} */ - {{vendorExtensions.x-name-lower}}(params: {{#bodyParam}}{{dataType}}{{/bodyParam}}{{^bodyParam}}{{vendorExtensions.x-resource-name}}{{vendorExtensions.x-name}}Options{{/bodyParam}}, callback?: (error: Error | null, item?: {{returnType}}) => any): Promise<{{returnType}}>; + {{vendorExtensions.x-name-lower}}(params: {{#bodyParam}}{{dataType}}, headers?: any{{/bodyParam}}{{^bodyParam}}{{vendorExtensions.x-resource-name}}{{vendorExtensions.x-name}}Options{{/bodyParam}}, callback?: (error: Error | null, item?: {{returnType}}) => any): Promise<{{returnType}}>; {{/hasParams}} diff --git a/src/main/resources/twilio-python/context.handlebars b/src/main/resources/twilio-python/context.handlebars index 1f52ea3ed..b0f49be69 100644 --- a/src/main/resources/twilio-python/context.handlebars +++ b/src/main/resources/twilio-python/context.handlebars @@ -1,5 +1,5 @@ class {{apiName}}Context(InstanceContext): - +{{#if nestedModels}}{{>modelClasses}}{{/if}} def __init__(self, version: Version{{#instancePathParams}}, {{paramName}}: {{{dataType}}}{{/instancePathParams}}): """ Initialize the {{apiName}}Context @@ -18,7 +18,7 @@ class {{apiName}}Context(InstanceContext): {{#dependents}}{{#instanceDependent}} self._{{mountName}}: Optional[{{listName}}] = None{{/instanceDependent}}{{/dependents}} {{#operations}}{{#vendorExtensions.x-is-context-operation}} - {{#vendorExtensions.x-is-update-operation}} + {{#vendorExtensions.x-is-update-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: """ Update the {{instanceName}} @@ -27,12 +27,23 @@ class {{apiName}}Context(InstanceContext): :returns: The updated {{instanceName}} """ - data = values.of({ {{#allParams}}{{#isFormParam}} + {{#bodyParam}}data = {{paramName}}.to_dict(){{/bodyParam}} + {{^bodyParam}}data = values.of({ {{#allParams}}{{#isFormParam}} '{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/isFormParam}}{{/allParams}} - }) - {{#allParams}}{{^isFormParam}}headers = values.of({'{{{baseName}}}': {{paramName}}, }){{/isFormParam}}{{/allParams}} - - payload = self._version.update(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data,{{#allParams}}{{#if isFormParam}}{{else}} headers=headers{{/if}}{{/allParams}}) + }){{/bodyParam}} + headers = values.of({}) + {{#allParams}}{{#isHeaderParam}} + {{^if required}} + if not ({{paramName}} is values.unset or (isinstance({{paramName}}, str) and not {{paramName}})):{{/if}} + headers['{{{baseName}}}'] = {{paramName}}{{/isHeaderParam}}{{/allParams}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} + + payload = self._version.update(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers) return {{instanceName}}( self._version, @@ -48,19 +59,31 @@ class {{apiName}}Context(InstanceContext): :returns: The updated {{instanceName}} """ - data = values.of({ {{#allParams}}{{#isFormParam}} + {{#bodyParam}}data = {{paramName}}.to_dict(){{/bodyParam}} + {{^bodyParam}}data = values.of({ {{#allParams}}{{#isFormParam}} '{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/isFormParam}}{{/allParams}} - }) - {{#allParams}}{{^isFormParam}}headers = values.of({'{{{baseName}}}': {{paramName}}, }){{/isFormParam}}{{/allParams}} - - payload = await self._version.update_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data,{{#allParams}}{{#if isFormParam}}{{else}} headers=headers{{/if}}{{/allParams}}) + }){{/bodyParam}} + headers = values.of({}) + {{#allParams}}{{#isHeaderParam}} + {{^if required}} + if not ({{paramName}} is values.unset or (isinstance({{paramName}}, str) and not {{paramName}})):{{/if}} + headers['{{{baseName}}}'] = {{paramName}} + {{/isHeaderParam}}{{/allParams}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} + + payload = await self._version.update_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers) return {{instanceName}}( self._version, payload{{#instancePathParams}}, {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} ) - {{/vendorExtensions.x-is-update-operation}}{{#vendorExtensions.x-is-fetch-operation}} + {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-update-operation}}{{#vendorExtensions.x-is-fetch-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: """ Fetch the {{instanceName}} @@ -73,9 +96,18 @@ class {{apiName}}Context(InstanceContext): data = values.of({ {{#allParams}}{{#if vendorExtensions.x-prefixed-collapsible-map}}{{else}} '{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/if}}{{/allParams}} }) + {{#allParams}}{{#if vendorExtensions.x-prefixed-collapsible-map}}data.update({{vendorExtensions.x-serialize}}({{paramName}}, '{{vendorExtensions.x-prefixed-collapsible-map}}')) {{/if}}{{/allParams}}{{/if}} - payload = self._version.fetch(method='{{vendorExtensions.x-http-method}}', uri=self._uri, {{#if allParams}}params=data{{/if}}) + + headers = values.of({}) + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} + payload = self._version.fetch(method='{{vendorExtensions.x-http-method}}', uri=self._uri {{#if allParams}}, params=data{{/if}} , headers=headers) return {{instanceName}}( self._version, @@ -96,9 +128,18 @@ class {{apiName}}Context(InstanceContext): data = values.of({ {{#allParams}}{{#if vendorExtensions.x-prefixed-collapsible-map}}{{else}} '{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/if}}{{/allParams}} }) + {{#allParams}}{{#if vendorExtensions.x-prefixed-collapsible-map}}data.update({{vendorExtensions.x-serialize}}({{paramName}}, '{{vendorExtensions.x-prefixed-collapsible-map}}')) {{/if}}{{/allParams}}{{/if}} - payload = await self._version.fetch_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, {{#if allParams}}params=data{{/if}}) + + headers = values.of({}) + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} + payload = await self._version.fetch_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri {{#if allParams}}, params=data{{/if}}, headers=headers) return {{instanceName}}( self._version, @@ -106,7 +147,7 @@ class {{apiName}}Context(InstanceContext): {{#instancePathParams}}{{paramName}}=self._solution['{{paramName}}'], {{/instancePathParams}} ) - {{/vendorExtensions.x-is-fetch-operation}}{{#vendorExtensions.x-is-delete-operation}} + {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-fetch-operation}}{{#vendorExtensions.x-is-delete-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> bool: """ Deletes the {{apiName}}Instance @@ -117,7 +158,17 @@ class {{apiName}}Context(InstanceContext): """{{#if allParams}} headers = values.of({{#allParams}}{'{{{baseName}}}': {{paramName}}, }{{/allParams}}) {{/if}} - return self._version.delete(method='{{vendorExtensions.x-http-method}}', uri=self._uri,{{#if allParams}} headers=headers{{/if}}) + + {{^if allParams}} + headers = values.of({}) + {{/if}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} + return self._version.delete(method='{{vendorExtensions.x-http-method}}', uri=self._uri, headers=headers) async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> bool: """ @@ -129,8 +180,17 @@ class {{apiName}}Context(InstanceContext): """{{#if allParams}} headers = values.of({{#allParams}}{'{{{baseName}}}': {{paramName}}, }{{/allParams}}) {{/if}} - return await self._version.delete_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri,{{#if allParams}} headers=headers{{/if}}) - {{/vendorExtensions.x-is-delete-operation}}{{#vendorExtensions.x-is-create-operation}} + {{^if allParams}} + headers = values.of({}) + {{/if}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} + return await self._version.delete_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, headers=headers) + {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-delete-operation}}{{#vendorExtensions.x-is-create-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: """ Create the {{instanceName}} @@ -170,7 +230,7 @@ class {{apiName}}Context(InstanceContext): payload{{#instancePathParams}}, {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} ) - {{/vendorExtensions.x-is-create-operation}}{{/vendorExtensions.x-is-context-operation}}{{/operations}} + {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-create-operation}}{{/vendorExtensions.x-is-context-operation}}{{/operations}} {{#dependents}}{{#instanceDependent}} @property def {{mountName}}(self) -> {{listName}}: diff --git a/src/main/resources/twilio-python/instance.handlebars b/src/main/resources/twilio-python/instance.handlebars index f9e8dc750..9a2060866 100644 --- a/src/main/resources/twilio-python/instance.handlebars +++ b/src/main/resources/twilio-python/instance.handlebars @@ -1,4 +1,5 @@ class {{instanceName}}(InstanceResource): +{{#if nestedModels}}{{>modelClasses}}{{/if}} {{>model}} """{{#vars}} :ivar {{name}}: {{{description}}}{{/vars}} diff --git a/src/main/resources/twilio-python/listOperations.handlebars b/src/main/resources/twilio-python/listOperations.handlebars index 92713c7ec..9ac8e5ebc 100644 --- a/src/main/resources/twilio-python/listOperations.handlebars +++ b/src/main/resources/twilio-python/listOperations.handlebars @@ -16,7 +16,12 @@ {{#headerParams}}'{{{baseName}}}': {{paramName}}, {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' }) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} {{#queryParams.0}}params = values.of({ {{#queryParams}}'{{{baseName}}}': {{paramName}}, {{/queryParams}} @@ -42,7 +47,12 @@ {{#headerParams}}'{{{baseName}}}': {{paramName}}, {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' }) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} {{#queryParams.0}}params = values.of({ {{#queryParams}}'{{{baseName}}}': {{paramName}}, {{/queryParams}} @@ -63,7 +73,12 @@ {{#headerParams}}'{{{baseName}}}': {{paramName}}, {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' }) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} {{#queryParams.0}}params = values.of({ {{#queryParams}}'{{{baseName}}}': {{paramName}}, {{/queryParams}} @@ -84,7 +99,12 @@ {{#headerParams}}'{{{baseName}}}': {{paramName}}, {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' }) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} {{#queryParams.0}}params = values.of({ {{#queryParams}}'{{{baseName}}}': {{paramName}}, {{/queryParams}} @@ -104,7 +124,12 @@ {{#headerParams}}'{{{baseName}}}': {{paramName}}, {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' }) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} {{#queryParams.0}}params = values.of({ {{#queryParams}}'{{{baseName}}}': {{paramName}}, {{/queryParams}} @@ -122,7 +147,12 @@ {{#headerParams}}'{{{baseName}}}': {{paramName}}, {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' }) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} {{#queryParams.0}}params = values.of({ {{#queryParams}}'{{{baseName}}}': {{paramName}}, {{/queryParams}} @@ -145,7 +175,12 @@ {{#headerParams}}'{{{baseName}}}': {{paramName}}, {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' }) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} {{#queryParams.0}}params = values.of({ {{#queryParams}}'{{{baseName}}}': {{paramName}}, {{/queryParams}} @@ -171,7 +206,12 @@ {{#headerParams}}'{{{baseName}}}': {{paramName}}, {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' }) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} {{#queryParams.0}}params = values.of({ {{#queryParams}}'{{{baseName}}}': {{paramName}}, {{/queryParams}} @@ -314,7 +354,18 @@ 'PageSize': page_size, }) - response = self._version.page(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data) + headers = values.of({ + {{#headerParams}}'{{{baseName}}}': {{paramName}}, + {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' + }) + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}} + + response = self._version.page(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data, headers=headers) return {{apiName}}Page(self._version, response{{#if listPathParams}}, self._solution{{/if}}) async def page_async(self, {{#allParams}} @@ -341,7 +392,18 @@ 'PageSize': page_size, }) - response = await self._version.page_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data) + headers = values.of({ + {{#headerParams}}'{{{baseName}}}': {{paramName}}, + {{/headerParams}}'Content-Type': 'application/x-www-form-urlencoded' + }) + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#produces}} + headers["Accept"] = "{{{mediaType}}}" + {{/produces}} + + response = await self._version.page_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data, headers=headers) return {{apiName}}Page(self._version, response{{#if listPathParams}}, self._solution{{/if}}) def get_page(self, target_url: str) -> {{apiName}}Page: diff --git a/src/main/resources/twilio-python/modelClasses.handlebars b/src/main/resources/twilio-python/modelClasses.handlebars index 210863b2a..dc49eb21f 100644 --- a/src/main/resources/twilio-python/modelClasses.handlebars +++ b/src/main/resources/twilio-python/modelClasses.handlebars @@ -12,6 +12,6 @@ def to_dict(self): return { {{#vars}} - "{{{vendorExtensions.json-name}}}": {{#if complexType}}{{#containerType}}[{{name}}.to_dict() for {{name}} in self.{{name}}]{{/containerType}}{{^containerType}}self.{{name}}{{^vendorExtensions.x-enum-object}}.to_dict(){{/vendorExtensions.x-enum-object}}{{/containerType}}{{else}}self.{{name}}{{/if}},{{/vars}} + "{{{vendorExtensions.json-name}}}": {{#if complexType}}{{#containerType}}[{{name}}.to_dict() for {{name}} in self.{{name}}] if self.{{name}} is not None else None{{/containerType}}{{^containerType}}self.{{name}}{{^vendorExtensions.x-enum-object}}.to_dict() if self.{{name}} is not None else None {{/vendorExtensions.x-enum-object}}{{/containerType}}{{else}}self.{{name}}{{/if}},{{/vars}} } {{/hasVars}}{{/vendorExtensions.part-of-response-model}}{{/models}} diff --git a/src/main/resources/twilio-ruby/contextMethodParams.mustache b/src/main/resources/twilio-ruby/contextMethodParams.mustache index 070fda2b5..d08400293 100644 --- a/src/main/resources/twilio-ruby/contextMethodParams.mustache +++ b/src/main/resources/twilio-ruby/contextMethodParams.mustache @@ -101,8 +101,12 @@ {{/vendorExtensions.x-prefixed-collapsible-map}}{{/isFormParam}}{{/optionalParams}} {{/formParams.0}} headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', {{#headerParams}}{{#required}}'{{baseName}}' => {{paramName}}, {{/required}}{{/headerParams}}{{#headerParams}}{{^required}}'{{baseName}}' => {{paramName}}, {{/required}}{{/headerParams}}}) - {{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}} + {{^vendorExtensions.scimConsumes}}{{#bodyParams.0}}headers['Content-Type'] = 'application/json'{{/bodyParams.0}}{{/vendorExtensions.scimConsumes}} + {{#vendorExtensions.scimConsumes}}headers['Content-Type'] = 'application/scim+json'{{/vendorExtensions.scimConsumes}} + {{#vendorExtensions.x-is-delete-operation}}{{#vendorExtensions.scimProduces}}headers['Accept'] = '*/*'{{/vendorExtensions.scimProduces}}{{/vendorExtensions.x-is-delete-operation}} {{^vendorExtensions.x-is-delete-operation}} + {{#vendorExtensions.scimProduces}}headers['Accept'] = 'application/scim+json'{{/vendorExtensions.scimProduces}} + {{#vendorExtensions.multipleProduces}} headers['Accept'] = '*/*'{{/vendorExtensions.multipleProduces}} payload = @version.{{#lambda.camelcase}}{{vendorExtensions.x-name}}{{/lambda.camelcase}}('{{httpMethod}}', @uri{{#queryParams.0}}, params: params{{/queryParams.0}}{{#formParams.0}}, data: data{{/formParams.0}}, headers: headers{{#bodyParams.0}}, data: {{paramName}}.to_json{{/bodyParams.0}}) {{apiName}}Instance.new( @version, diff --git a/src/main/resources/twilio-ruby/list.mustache b/src/main/resources/twilio-ruby/list.mustache index 913457f3a..6a208c26c 100644 --- a/src/main/resources/twilio-ruby/list.mustache +++ b/src/main/resources/twilio-ruby/list.mustache @@ -109,8 +109,11 @@ 'Page' => page_number, 'PageSize' => page_size, }) + headers = Twilio::Values.of({}) + {{#vendorExtensions.scimConsumes}}headers['Content-Type'] = 'application/scim+json'{{/vendorExtensions.scimConsumes}} + {{#vendorExtensions.scimProduces}}headers['Accept'] = 'application/scim+json'{{/vendorExtensions.scimProduces}} - response = @version.page('{{httpMethod}}', @uri, params: params) + response = @version.page('{{httpMethod}}', @uri, params: params, headers: headers) {{apiName}}Page.new(@version, response, @solution) end diff --git a/src/main/resources/twilio-ruby/methods.mustache b/src/main/resources/twilio-ruby/methods.mustache index 82424b436..a74bd8799 100644 --- a/src/main/resources/twilio-ruby/methods.mustache +++ b/src/main/resources/twilio-ruby/methods.mustache @@ -21,5 +21,5 @@ def {{#lambda.camelcase}}{{vendorExtensions.x-name}}{{/lambda.camelcase}}{{#hasParams}}({{#queryParams}} {{paramName}}: {{#required}}nil{{/required}}{{^required}}:unset{{/required}}{{^-last}}, {{/-last}}{{/queryParams}}{{#formParams.0}}{{#queryParams.0}}, {{/queryParams.0}}{{/formParams.0}}{{#formParams}} {{paramName}}: {{#required}}nil{{/required}}{{^required}}:unset{{/required}}{{^-last}}, {{/-last}}{{/formParams}}{{#headerParams.0}}{{#queryParams.0}}, {{/queryParams.0}}{{^queryParams.0}}{{#formParams.0}}, {{/formParams.0}}{{/queryParams.0}}{{/headerParams.0}}{{#headerParams}} - {{paramName}}: {{#required}}nil{{/required}}{{^required}}:unset{{/required}}{{^-last}}, {{/-last}}{{/headerParams}}{{#bodyParams}}{{paramName}}: {{#required}}nil{{/required}}{{^required}}:unset{{/required}}{{^-last}}, {{/-last}}{{/bodyParams}} + {{paramName}}: {{#required}}nil{{/required}}{{^required}}:unset{{/required}}{{^-last}}, {{/-last}}{{/headerParams}}{{#bodyParams}}{{#headerParams.0}},{{/headerParams.0}}{{paramName}}: {{#required}}nil{{/required}}{{^required}}:unset{{/required}}{{^-last}}, {{/-last}}{{/bodyParams}} ){{/hasParams}} diff --git a/src/main/resources/twilio-ruby/modelClasses.mustache b/src/main/resources/twilio-ruby/modelClasses.mustache index 510e1088b..ff8573f31 100644 --- a/src/main/resources/twilio-ruby/modelClasses.mustache +++ b/src/main/resources/twilio-ruby/modelClasses.mustache @@ -12,9 +12,9 @@ def to_json(options = {}) { {{#vars}} - {{name}}: @{{name}}, + "{{baseName}}": @{{name}}, {{/vars}} }.to_json(options) end end -{{/hasVars}}{{/vendorExtensions.part-of-response-model}}{{/models}} \ No newline at end of file +{{/hasVars}}{{/vendorExtensions.part-of-response-model}}{{/models}} diff --git a/twilio_am_temp.json b/twilio_am_temp.json new file mode 100644 index 000000000..71886cae2 --- /dev/null +++ b/twilio_am_temp.json @@ -0,0 +1,143 @@ +{ + "openapi": "3.0.1", + "security": [ + { + "oAuth2ClientCredentials": [] + } + ], + "info": { + "title": "Organization Public API", + "contact": { + "name": "Twilio Support", + "url": "https://support.twilio.com", + "email": "support@twilio.com" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0.0" + }, + "paths": { + "/Organizations/{OrganizationSid}": { + "x-twilio": { + "dependentProperties": { + "users": { + "mapping": { + "organization_sid": "organization_sid" + }, + "resource_url": "/Organizations/{organization_sid}/scim/Users" + }, + "accounts": { + "mapping": { + "organization_sid": "organization_sid" + }, + "resource_url": "/Organizations/{organization_sid}/Accounts" + }, + "roleAssignments": { + "mapping": { + "organization_sid": "organization_sid" + }, + "resource_url": "/Organizations/{organization_sid}/RoleAssignments" + } + }, + "pathType": "instance", + "mountName": "organization" + }, + "servers": [ + { + "url": "https://preview-iam.twilio.com" + } + ], + "get": { + "summary": "List SCIM Users", + "operationId": "FetchOrganization", + "parameters": [ + { + "name": "OrganizationSid", + "in": "path", + "required": true, + "schema": { + "pattern": "OR[0-9a-f]{32}", + "type": "string", + "format": "OrganizationSid", + "example": "OR33f4f3aa6fffe840d000f8ef22e883db" + } + } + ], + "x-twilio": { + "ignoreOperation": true + }, + "responses": { + "403": { + "description": "Forbidden", + "content": { + "application/scim+json": { + "schema": { + + } + } + }, + "headers": { + "Access-Control-Allow-Origin": { + "description": "Specify the origin(s) allowed to access the resource", + "schema": { + "type": "string" + }, + "example": "*" + }, + "Access-Control-Allow-Methods": { + "description": "Specify the HTTP methods allowed when accessing the resource", + "schema": { + "type": "string" + }, + "example": "POST, OPTIONS" + }, + "Access-Control-Allow-Headers": { + "description": "Specify the headers allowed when accessing the resource", + "schema": { + "type": "string" + }, + "example": "Content-Type, Authorization" + }, + "Access-Control-Allow-Credentials": { + "description": "Indicates whether the browser should include credentials", + "schema": { + "type": "boolean" + } + }, + "Access-Control-Expose-Headers": { + "description": "Headers exposed to the client", + "schema": { + "type": "string", + "example": "X-Custom-Header1, X-Custom-Header2" + } + } + } + } + } + } + } + }, + "components": { + "securitySchemes": { + "oAuth2ClientCredentials": { + "type": "oauth2", + "flows": { + "clientCredentials": { + "tokenUrl": "https://preview-iam.twilio.com/v1/token", + "scopes": {} + } + } + } + }, + "schemas": { + + } + }, + "servers": [ + { + "url": "https://preview-iam.twilio.com" + } + ] +}