Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"tslib": "^2.4.1"
},
"devDependencies": {
"@commerce-apps/raml-toolkit": "file:../raml-toolkit",
"@commerce-apps/raml-toolkit": "^0.7.0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "^4.3.0",
"@types/fs-extra": "^9.0.13",
Expand Down
264 changes: 264 additions & 0 deletions templatesOas/apis.endpoint.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
{{! This partial expects to be wrapped in operations/operation }}
{{! and renders the endpoint function for each operation, making the API fetch call }}
/**
* {{{unescapedNotes}}}
*
* If you would like to get a raw Response object use the other {{nickname}} function.
*
* @param options - An object containing the options for this method.
* @param options.parameters - An object containing the parameters for this method.
{{#allParams}}
{{^isBodyParam}}
{{^isHeaderParam}}
{{^isFormParam}}
* @param options.parameters.{{{paramName}}} - {{{unescapedDescription}}}
{{/isFormParam}}
{{/isHeaderParam}}
{{/isBodyParam}}
{{/allParams}}
* @param options.retrySettings - Retry options for the `node-retry` package
* @param options.fetchOptions - Fetch options for the `make-fetch-happen` package
* @param options.headers - An object literal of key value pairs of the headers to be sent with this request.
{{#hasBodyParam}}
* @param options.body - The data to send as the request body.
{{/hasBodyParam}}
{{^hasBodyParam}}
{{#hasFormParams}}
* @param options.body - The data to send as the request body.
{{#formParams}}
{{#isFormParam}}
* @param options.body.{{{paramName}}} - {{{unescapedDescription}}}
{{/isFormParam}}
{{/formParams}}
{{/hasFormParams}}
{{/hasBodyParam}}
*
* @returns A promise of type {{{returnType}}}{{^returnType}}void{{/returnType}}.
*/
{{nickname}}(
options{{^hasBodyParam}}?{{/hasBodyParam}}: RequireParametersUnlessAllAreOptional<{
parameters?: CompositeParameters<{
{{#allParams}}
{{^isBodyParam}}
{{^isHeaderParam}}
{{^isFormParam}}
{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{^isDateTime}}{{^isDate}}{{{dataType}}}{{/isDate}}{{/isDateTime}}{{#isDateTime}}string{{/isDateTime}}{{#isDate}}string{{/isDate}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
{{/isFormParam}}
{{/isHeaderParam}}
{{/isBodyParam}}
{{/allParams}}
} & QueryParameters, CommonParameters>,
retrySettings?: OperationOptions,
fetchOptions?: RequestInit,
headers?: { [key: string]: string },
{{#hasBodyParam}}
{{#bodyParam}}
body: {{{dataType}}}
{{/bodyParam}}
{{/hasBodyParam}}
{{^hasBodyParam}}
{{#hasFormParams}}
body: {{nickname}}BodyType
{{/hasFormParams}}
{{/hasBodyParam}}
}>
): Promise<{{{returnType}}}{{^returnType}}void{{/returnType}}>;

/**
* {{{unescapedNotes}}}
*
* @param options - An object containing the options for this method.
* @param options.parameters - An object containing the parameters for this method.
{{#allParams}}
{{^isBodyParam}}
{{^isHeaderParam}}
{{^isFormParam}}
* @param options.parameters.{{{paramName}}} - {{{unescapedDescription}}}
{{/isFormParam}}
{{/isHeaderParam}}
{{/isBodyParam}}
{{/allParams}}
* @param options.retrySettings - Retry options for the `node-retry` package
* @param options.fetchOptions - Fetch options for the `make-fetch-happen` package
* @param options.headers - An object literal of key value pairs of the headers to be sent with this request.
{{#hasBodyParam}}
* @param options.body - The data to send as the request body.
{{/hasBodyParam}}
{{^hasBodyParam}}
{{#hasFormParams}}
* @param options.body - The data to send as the request body.
{{#formParams}}
{{#isFormParam}}
* @param options.body.{{{paramName}}} - {{{unescapedDescription}}}
{{/isFormParam}}
{{/formParams}}
{{/hasFormParams}}
{{/hasBodyParam}}
* @param rawResponse - Set to true to return entire Response object instead of DTO.
*
* @returns A promise of type Response if rawResponse is true, a promise of type {{{returnType}}}{{^returnType}}void{{/returnType}} otherwise.
*/
{{nickname}}<T extends boolean>(
options{{^hasBodyParam}}?{{/hasBodyParam}}: RequireParametersUnlessAllAreOptional<{
parameters?: CompositeParameters<{
{{#allParams}}
{{^isBodyParam}}
{{^isHeaderParam}}
{{^isFormParam}}
{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{^isDateTime}}{{^isDate}}{{{dataType}}}{{/isDate}}{{/isDateTime}}{{#isDateTime}}string{{/isDateTime}}{{#isDate}}string{{/isDate}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
{{/isFormParam}}
{{/isHeaderParam}}
{{/isBodyParam}}
{{/allParams}}
} & QueryParameters, CommonParameters>,
retrySettings?: OperationOptions,
fetchOptions?: RequestInit,
headers?: { [key: string]: string },
{{#hasBodyParam}}
{{#bodyParam}}
body: {{{dataType}}}
{{/bodyParam}}
{{/hasBodyParam}}
{{^hasBodyParam}}
{{#hasFormParams}}
body: {{nickname}}BodyType
{{/hasFormParams}}
{{/hasBodyParam}}
}>,
rawResponse?: T
): Promise<T extends true ? Response : {{{returnType}}}{{^returnType}}void{{/returnType}}>;

/**
* {{{unescapedNotes}}}
*
* @param options - An object containing the options for this method.
* @param options.parameters - An object containing the parameters for this method.
{{#allParams}}
{{^isBodyParam}}
{{^isHeaderParam}}
{{^isFormParam}}
* @param options.parameters.{{{paramName}}} - {{{unescapedDescription}}}
{{/isFormParam}}
{{/isHeaderParam}}
{{/isBodyParam}}
{{/allParams}}
* @param options.retrySettings - Retry options for the `node-retry` package
* @param options.fetchOptions - Fetch options for the `make-fetch-happen` package
* @param options.headers - An object literal of key value pairs of the headers to be sent with this request.
{{#hasBodyParam}}
* @param options.body - The data to send as the request body.
{{/hasBodyParam}}
{{^hasBodyParam}}
{{#hasFormParams}}
* @param options.body - The data to send as the request body.
{{#formParams}}
{{#isFormParam}}
* @param options.body.{{{paramName}}} - {{{unescapedDescription}}}
{{/isFormParam}}
{{/formParams}}
{{/hasFormParams}}
{{/hasBodyParam}}
* @param rawResponse - Set to true to return entire Response object instead of DTO.
*
* @returns A promise of type Response if rawResponse is true, a promise of type {{{returnType}}}{{^returnType}}void{{/returnType}} otherwise.
*/
async {{nickname}}(
options{{^hasBodyParam}}?{{/hasBodyParam}}: RequireParametersUnlessAllAreOptional<{
parameters?: CompositeParameters<{
{{#allParams}}
{{^isBodyParam}}
{{^isHeaderParam}}
{{^isFormParam}}
{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{^isDateTime}}{{^isDate}}{{{dataType}}}{{/isDate}}{{/isDateTime}}{{#isDateTime}}string{{/isDateTime}}{{#isDate}}string{{/isDate}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
{{/isFormParam}}
{{/isHeaderParam}}
{{/isBodyParam}}
{{/allParams}}
} & QueryParameters, CommonParameters>,
retrySettings?: OperationOptions,
fetchOptions?: RequestInit,
headers?: { [key: string]: string },
{{#hasBodyParam}}
{{#bodyParam}}
body: {{{dataType}}}
{{/bodyParam}}
{{/hasBodyParam}}
{{^hasBodyParam}}
{{#hasFormParams}}
body: {{nickname}}BodyType
{{/hasFormParams}}
{{/hasBodyParam}}
}>,
rawResponse?: boolean
): Promise<Response | {{{returnType}}}{{^returnType}}void{{/returnType}}> {
const optionParams = options?.parameters || ({} as Partial<NonNullable<NonNullable<typeof options>["parameters"]>>);
const configParams = this.clientConfig.parameters as CommonParameters;

const pathParams = {};

{{#pathParams}}
if (optionParams["{{paramName}}"] !== undefined) {
pathParams["{{paramName}}"] = optionParams["{{paramName}}"];
} else if (configParams["{{paramName}}"] !== undefined) {
pathParams["{{paramName}}"] = configParams["{{paramName}}"];
}
{{#required}}
else {
throw new Error('Missing required path parameter: {{paramName}}');
}
{{/required}}
{{/pathParams}}

const queryParams: QueryParameters = {};

{{#queryParams}}
if (optionParams["{{paramName}}"] !== undefined) {
queryParams["{{paramName}}"] = optionParams["{{paramName}}"];
} else if (configParams["{{paramName}}"] !== undefined) {
queryParams["{{paramName}}"] = configParams["{{paramName}}"];
}
{{#required}}
else {
throw new Error('Missing required query parameter: {{paramName}}');
}
{{/required}}
{{/queryParams}}

Object.keys(optionParams).forEach((key) => {
const paramValue = optionParams[key as keyof typeof optionParams];
if(paramValue !== undefined && (key.startsWith('c_') || !((key in queryParams) || (key in pathParams)))) {
if(!key.startsWith('c_')) {
console.warn(`Found unknown parameter for {{{nickname}}}: ${key}, adding as query parameter anyway`);
}
queryParams[key as keyof typeof queryParams] = paramValue;
}
})

const headers = mergeHeaders(getHeaders(options), {
{{#hasConsumes}}
{{#consumes}}
"Content-Type": "{{mediaType}}",
{{/consumes}}
{{/hasConsumes}}
[USER_AGENT_HEADER]: USER_AGENT_VALUE
});

return StaticClient.{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}({
client: this,
rawResponse: rawResponse,
path: "{{path}}",
pathParameters: pathParams,
queryParameters: queryParams,
retrySettings: (options || {}).retrySettings,
headers: headers,
{{#hasBodyParam}}
body: (options || {}).body,
{{/hasBodyParam}}
{{^hasBodyParam}}
{{#hasFormParams}}
body: (options || {}).body,
{{/hasFormParams}}
{{/hasBodyParam}}
...(options{{^hasBodyParam}}?{{/hasBodyParam}}.fetchOptions && { fetchOptions: options.fetchOptions })
});
}
26 changes: 26 additions & 0 deletions templatesOas/apis.enum.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{! This partial expects to be wrapped in operations/operation }}
{{! and renders the enum types for a given operation }}
{{#allParams}}
{{#isEnum}}
{{#stringEnums}}
export enum {{operationIdCamelCase}}{{enumName}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}} = {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
}
{{/stringEnums}}
{{^stringEnums}}

export const {{operationIdCamelCase}}{{enumName}} = {
{{#allowableValues}}
{{#enumVars}}
{{{name}}}: {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
} as const;
export type {{operationIdCamelCase}}{{enumName}} = typeof {{operationIdCamelCase}}{{enumName}}[keyof typeof {{operationIdCamelCase}}{{enumName}}];
{{/stringEnums}}
{{/isEnum}}
{{/allParams}}
Loading
Loading