openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
export operation's options as type
Hey👋🏻
Thanks again @ferdikoomen for your amazing job on this library 🙏🏻
add exportOptions
The idea here is to export service operation's options to disk using a new option called --exportOptions.
- It has to be used alongside
--exportServices=trueand--useOptions. - option type will only be written if operation have at least one parameter
to be determined 🤔
- should we rename cli option to a more explicit one like
exportServiceOperationTypesorexportServiceFunctionParameters? - should we add a postfix option to change type postfix (here default to
Options) ?
Example without --exportOptions (current behavior) :
import type { ModelWithString } from '../models/ModelWithString';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class RequestBodyService {
/**
* @throws ApiError
*/
public static postApiRequestBody({
parameter,
requestBody,
}: {
/**
* This is a reusable parameter
*/
parameter?: string,
/**
* A reusable request body
*/
requestBody?: ModelWithString,
}): CancelablePromise<void> {
return __request(OpenAPI, {
method: 'POST',
url: '/api/v{api-version}/requestBody/',
query: {
'parameter': parameter,
},
body: requestBody,
mediaType: 'application/json',
});
}
}
Example with --exportOptions (see PostApiRequestBodyOptions exported type):
import type { ModelWithString } from '../models/ModelWithString';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export type PostApiRequestBodyOptions = {
/**
* This is a reusable parameter
*/
parameter?: string,
/**
* A reusable request body
*/
requestBody?: ModelWithString,
};
export class RequestBodyService {
/**
* @throws ApiError
*/
public static postApiRequestBody({
parameter,
requestBody,
}: PostApiRequestBodyOptions): CancelablePromise<void> {
return __request(OpenAPI, {
method: 'POST',
url: '/api/v{api-version}/requestBody/',
query: {
'parameter': parameter,
},
body: requestBody,
mediaType: 'application/json',
});
}
}
I remain at your disposal for any feedback on the implementation.
I wish you a great day ☀️
Best regards ☮️
This looks like a high quality PR that adds a very useful feature. Would definitely use if merged.