Bewinxed / svetch

Auto-Generated typesafe client & API docs generator for your Serverless Application (Svelte First)
https://svetch-dev.vercel.app/
67 stars 0 forks source link

Support for JSDocs on autogenerated docs #2

Closed EdenKahane closed 8 months ago

EdenKahane commented 10 months ago

Hello,

I would like to use JSDocs comments to describe an endpoint (even though I'm using typescript for type definition). The readme seems to say it's possible, but I cannot understand how.

Here is an example of a simple endpoint definition with the description This is an endpoint description with JSDocs, unfortunately, the description doesn't appears in the online /docs/ page.

type UserLoginRequest = {
    email: string,
    password: string
}
/**
 * This is an endpoint description
 */
export const POST: RequestHandler = async ({ request }) => {
    const payload = await request.json() as UserLoginRequest
    return json({sucess: true});
};

Version:

Thanks for your help !

Bewinxed commented 10 months ago

Hello! Thanks for using the library, I'm on mobile rn but try to put the jsdoc inside the code block and it will work.

So on the first line after =>

On Sat, 23 Dec 2023 at 1:26 PM Eden Kahane @.***> wrote:

Hello,

I would like to use JSDocs comments to describe an endpoint (even though I'm using typescript for type definition). The readme seems to say it's possible, but I cannot understand how.

Here is an example of a simple endpoint definition with the description This is an endpoint description with JSDocs, unfortunately, the description doesn't appears in the online /docs/ page.

type UserLoginRequest = { email: string, password: string}/* This is an endpoint description */export const POST: RequestHandler = async ({ request }) => { const payload = await request.json() as UserLoginRequest return json({sucess: true});};

Version:

  • Svetch: 1.0.47
  • Sveltekit: 2.0.4

Thanks for your help !

— Reply to this email directly, view it on GitHub https://github.com/Bewinxed/svetch/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACFY5BJEJABKYBDWMRNNEVTYK2WVZAVCNFSM6AAAAABBAWRCXGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA2TINZUGU2DEMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

EdenKahane commented 10 months ago

Unfortunately, I tried this and multiple other positions :

/**
 * This is an endpoint description 1
 */
export const POST: RequestHandler = 
/**
 * This is an endpoint description 2
 */
async ({ request }) => 
/**
 * This is an endpoint description 3
 */
{
/**
 * This is an endpoint description 4
 */

    const payload = await request.json() as UserLoginRequest
    return json({sucess: true});
};

None of them seems to work after regenerating the docs. I also tried each of them alone.

Thank you for making this library, it's very useful !

Bewinxed commented 9 months ago

Unfortunately, I tried this and multiple other positions :

/**
 * This is an endpoint description 1
 */
export const POST: RequestHandler = 
/**
 * This is an endpoint description 2
 */
async ({ request }) => 
/**
 * This is an endpoint description 3
 */
{
/**
 * This is an endpoint description 4
 */

  const payload = await request.json() as UserLoginRequest
  return json({sucess: true});
};

None of them seems to work after regenerating the docs. I also tried each of them alone.

Thank you for making this library, it's very useful !

Hey, just remembered, Put the jsdoc INSIDE the block, and in the first line. and make sure to add the tag @svetch to the jsdoc

then it will work

in the generated schema.json, it will be in the 'description' field

example

export const POST: RequestHandler = async ({request, params, url}) => {
    /**
     * @svetch
     * @description {{name: string, age: number, email: string}}
     * The payload from the request, expected to be in the format: {name: string, age: number, email: string}
     */

    const premium = url.searchParams.get('premium')

    const payload = await request.json() as {name: string, age: number, email: string}

    const user = {id: 1, ...payload}

    return json(user);
};

adding it to the client, i might have time for it in the future, I think this whole lib needs a proper rewrite, and changing it to fit openapi spec, but i don't have resources atm.

this also makes it appear in the docs!

image

EdenKahane commented 8 months ago

Thank you a lot for this information. Is there a documentation for this somewhere ? I looked on the README and on https://svetch-dev.vercel.app/ but didn't found anything about it.

An openapi support would be very good but I understand that this take a lot of time and work. Thank you for everything.

Bewinxed commented 8 months ago

I guess i forgot to include that bit :(

I would love to add openapi support soon need to clean up some stuff first.

On Thu, Jan 25, 2024 at 8:39 PM Eden Kahane @.***> wrote:

Thank you a lot for this information. Is there a documentation for this somewhere ? I looked on the README and on https://svetch-dev.vercel.app/ but didn't found anything about it.

An openapi support would be very good but I understand that this take a lot of time and work. Thank you for everything.

— Reply to this email directly, view it on GitHub https://github.com/Bewinxed/svetch/issues/2#issuecomment-1910689297, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACFY5BPQA5WOYZARX7A3TVTYQKKGBAVCNFSM6AAAAABBAWRCXGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJQGY4DSMRZG4 . You are receiving this because you commented.Message ID: @.***>