From ede957f65980a1a16814b4a9749b690ed1118beb Mon Sep 17 00:00:00 2001 From: Evan Peterson Date: Thu, 21 Sep 2023 15:28:52 -0600 Subject: [PATCH] fix: include route description as ts comment --- src/generate-api-types.test.ts | 5 +++++ src/generate-axios-client.test.ts | 7 +++++++ src/generate-endpoints.ts | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/generate-api-types.test.ts b/src/generate-api-types.test.ts index f779fdc..818c946 100644 --- a/src/generate-api-types.test.ts +++ b/src/generate-api-types.test.ts @@ -156,6 +156,7 @@ export const Schema: OneSchema = { Endpoints: { 'GET /fruits': { Name: 'getPosts', + Description: 'Fetches an array of all fruits.', Request: {}, Response: { type: 'array', @@ -171,6 +172,9 @@ export const Schema: OneSchema = { import type { OneSchema } from "@lifeomic/one-schema"; export type Endpoints = { + /** + * Fetches an array of all fruits. + */ "GET /fruits": { Request: unknown; PathParams: {}; @@ -220,6 +224,7 @@ export const Schema: OneSchema = { Endpoints: { "GET /fruits": { Name: "getPosts", + Description: "Fetches an array of all fruits.", Request: {}, Response: { type: "array", items: { $ref: "#/definitions/Fruit" } }, }, diff --git a/src/generate-axios-client.test.ts b/src/generate-axios-client.test.ts index 22ed988..7289cb2 100644 --- a/src/generate-axios-client.test.ts +++ b/src/generate-axios-client.test.ts @@ -155,6 +155,13 @@ export type Endpoints = { output?: string; }; }; + /** + * This is a long description about a field. It contains lots of very long text. Sometimes the text might be over the desired line length. + * + * It contains newlines. + * + * ## It contains markdown. + */ "PUT /posts/:id": { Request: { message?: string; diff --git a/src/generate-endpoints.ts b/src/generate-endpoints.ts index 958a31b..b125c60 100644 --- a/src/generate-endpoints.ts +++ b/src/generate-endpoints.ts @@ -14,11 +14,12 @@ export const generateEndpointTypes = async ({ Endpoints, }: OneSchemaDefinition) => { const masterSchema: JSONSchema4 = Object.entries(Endpoints).reduce( - (accum, [key, { Request, Response }]) => ({ + (accum, [key, { Description, Request, Response }]) => ({ ...accum, properties: { ...accum.properties, [key]: { + description: Description, type: 'object', additionalProperties: false, required: ['Request', 'PathParams', 'Response'],