ts-spec / tspec

Type-driven API Documentation library. Auto-generating REST API document based on TypeScript types.
https://ts-spec.github.io/tspec/
MIT License
108 stars 5 forks source link

According to the api spec, headers cannot be customized separately?? #14

Closed JEONGHWANMIN closed 1 year ago

JEONGHWANMIN commented 1 year ago

ISSUE

I use tspec to create an api spec, but there is nothing customizable in the headers area. Are there any options that I can customize now?

I want to specify in the header to put refreshToken or accessToken.

The code I wrote is below.

import { Tspec } from 'tspec';
import { LoginUserDto } from '../dto';
import { CreateUserDto } from '../dto';

export type UsersApiSpec = Tspec.DefineApiSpec<{
  basePath: 'users';
  tags: ['users'];
  paths: {
    '/signup': {
      post: {
        summary: '유저 회원가입';
        body: CreateUserDto;
        responses: {
          201: {
            message: string;
          };
        };
      };
    };
    '/signin': {
      post: {
        summary: '유저 로그인';
        body: LoginUserDto;
        responses: {
          201: {
            message: string;
            accessToken: string;
            refreshToken: string;
          };
        };
      };
    };
    '/check': {
      post: {
        summary: '이메일 중복체크';
        query: {
          email: string;
        };
        responses: {
          200: {
            message: string;
            isDuplicate: boolean;
          };
        };
      };
    };
    '/': {
      get: {
        summary: '유저 로그아웃';
        responses: {
          200: {
            message: string;
            isDuplicate: boolean;
          };
        };
      };
    };
  };
}>;
hyeonss0417 commented 1 year ago

As we update tspec version to 0.1.97, we support header and cookie params!🎉 You can see the example in https://github.com/ts-spec/tspec/blob/main/examples/tspec-basic-example/index.ts

USAGE

import { Tspec } from "tspec";

/** Schema description defined by JSDoc */
interface Book {
  /** Field description defined by JSDoc */
  id: number;
  title: string;
  description?: string;
}

export type BookApiSpec = Tspec.DefineApiSpec<{
  tags: ['Book']
  paths: {
    '/books/{id}': {
      get: {
        summary: 'Get book by id',
        path: { id: number },
        header: { 'X-Request-ID': string },
        cookie: { debug: 0 | 1 },
        responses: { 200: Book },
      },
    },
  }
}>;

Swagger UI

image