ecyrbe/zodios

[Feature Request] add ability to have example values for parameters and responses

NatoNathan opened this issue · 1 comments

It would be nice to have the ability to have example values for parameters and responses, as this could be used in the openapi specs.

Parameters could look like this

const onCallAnswerParameters = parametersBuilder()
    .addBody(
        z.object({
            to: z.string().optional(),
            from: z.string().optional(),
            uuid: z.string().uuid(),
            conversation_uuid: z.string().startsWith('CON-'),
            region_url: z.string().url().optional(),
            custom_data: customData({}).optional(),
        }),
        {
            to: '447700900000',
            from: '447700900001',
            uuid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
            conversation_uuid: 'CON-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
            region_url: 'https://api.nexmo.com',
            custom_data: {
                my_key: 'my_value'
            }
        }
      );
// or 

const onCallAnswerParameters2 = makeParameters([
    {
        name: 'body',
        type: 'Body',
        schema: z.object({
            to: z.string().optional(),
            from: z.string().optional(),
            uuid: z.string().uuid(),
            conversation_uuid: z.string().startsWith('CON-'),
            region_url: z.string().url().optional(),
            custom_data: customData({}).optional(),
        }),
        example: {
            to: '447700900000',
            from: '447700900001',
            uuid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
            conversation_uuid: 'CON-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
            region_url: 'https://api.nexmo.com',
            custom_data: {
                my_key: 'my_value'
            }
        }
    }
]);

Response's could look like this

export const webhooksApi = makeApi([
    {
        description: 'On Call Answer Webhook',
        method: 'post',
        path: '/on-call-answer',
        status: 200,
        parameters: onCallAnswerParameters.build(),
        response: NCCO,
        responseExample: {
            action: 'connect',
            endpoint: [{
                type: 'app',
                user: 'alice'
            }]
        }
    }
]);

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.