Skip to content

Add OpenAPI specs decorator#33

Draft
gonzauy wants to merge 1 commit into
muralco:masterfrom
gonzauy:poc/eco-569-openapi
Draft

Add OpenAPI specs decorator#33
gonzauy wants to merge 1 commit into
muralco:masterfrom
gonzauy:poc/eco-569-openapi

Conversation

@gonzauy
Copy link
Copy Markdown
Collaborator

@gonzauy gonzauy commented Jun 12, 2023

Adds an OpenAPI specs decorator.

Endpoints could add a new decoration and send data to be consumed by the analyze method.

On the app side, we can add a new wrapper like:

import { specs } from 'async-app';
import { Middleware, Req } from './app';

export type SpecsMetadata = {
  operationId?: string;
};

const specsMiddleware: Middleware = (_req: Req<null>, _res, next) => {
  next();
};

export const openApi = (spec: SpecsMetadata) => specs(spec, specsMiddleware);

And then use it like:

app.get(
  '/todos/:todoId',
  'Returns the specified todo item',
  openApi({ operationId: 'getTodoById' }),
  ...

When we call the analyze, we'll be able to access to the specs of each Route.

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.

1 participant