Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export operation's options as type #1700

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

smarlhens
Copy link

@smarlhens smarlhens commented Aug 14, 2023

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=true and --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 exportServiceOperationTypes or exportServiceFunctionParameters ?
  • 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 โ˜ฎ๏ธ

@smarlhens smarlhens force-pushed the feat/export-service-function-s-options branch from 83878eb to 052cfdb Compare August 21, 2023 07:55
@radusuciu
Copy link

This looks like a high quality PR that adds a very useful feature. Would definitely use if merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants