Skip to content

Commit

Permalink
Merge pull request #82 from lifeomic/ep/endpoint-descriptions
Browse files Browse the repository at this point in the history
fix: include route description as ts comment
  • Loading branch information
epeters3 authored Sep 21, 2023
2 parents 1b72e84 + ede957f commit 21f664f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/generate-api-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const Schema: OneSchema<Endpoints> = {
Endpoints: {
'GET /fruits': {
Name: 'getPosts',
Description: 'Fetches an array of all fruits.',
Request: {},
Response: {
type: 'array',
Expand All @@ -171,6 +172,9 @@ export const Schema: OneSchema<Endpoints> = {
import type { OneSchema } from "@lifeomic/one-schema";
export type Endpoints = {
/**
* Fetches an array of all fruits.
*/
"GET /fruits": {
Request: unknown;
PathParams: {};
Expand Down Expand Up @@ -220,6 +224,7 @@ export const Schema: OneSchema<Endpoints> = {
Endpoints: {
"GET /fruits": {
Name: "getPosts",
Description: "Fetches an array of all fruits.",
Request: {},
Response: { type: "array", items: { $ref: "#/definitions/Fruit" } },
},
Expand Down
7 changes: 7 additions & 0 deletions src/generate-axios-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/generate-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 21f664f

Please sign in to comment.