👩🏻💻 𝐋𝐚𝐧𝐠𝐮𝐚𝐠𝐞/⠀⠀⠀⠀ Nᴏᴅᴇ.Jꜱ
Swagger가 뭔가요
유리쯔의일상
2024. 2. 1. 23:34
반응형
API-Docs
- 사용하는 이유
프론트엔드 사람들에게 어떤 기능이고 어떻게 사용하는 것 인지를 명시해줘야 된다 - api만 만드는 것이 아닌 항상 docs를 같이 만들어야 한다
- 보통 API 위에다 정의하기도 하지만 그렇게 할 경우 소스코드가
너무 길어지기 때문에 별도의 파일이나 폴더를 생성하여 구분해 관리하기도 한다
별도의 파일로 관리 시 Import필요
라이브러리
swagger-ui-express
npm i swagger-ui-express yarn add swagger-ui-express
swagger-jsdoc
yarn add swagger-jsdoc
기본 템플릿
/*
@openapi
/ :
get :
descriptionb : Welcome to swagger-jsdoc
responses :
200 :
description : Return a mysterious string
*/
응용 템플릿
// boards.swagger.js
/**
* @swagger
* /boards:
* get:
* summary: 게시글 가져오기
* tags: [Board]
* parameters:
* - in: query
* name: number
* type: int
* responses:
* 200:
* description: 성공
* content:
* application/json:
* schema:
* type: array
* items:
* properties:
* number:
* type: int
* example: 1
* writer:
* type: string
* example: 철수
* title:
* type: string
* example: 좋은아침 입니다~
* contents:
* type: string
* example: 오늘 하루도 파이팅 하세요!
*/
/**
* @swagger
* /boards:
* post:
* summary: 게시글 등록하기
* tags: [Board]
* responses:
* 200:
* description: 성공
*/
💡 참고 사이트 💡
https://swagger.io/docs/specification/basic-structure/
Basic Structure
OAS 3 This page is about OpenAPI 3.0. If you use OpenAPI 2.0, visit OpenAPI 2.0 pages. Basic Structure You can write OpenAPI definitions in YAML or JSON. In this guide, we use only YAML examples but JSON works equally well. A sample OpenAPI 3.0 definitio
swagger.io
❤ 김춘장이의 위키백과 - 나만의 공부 기록 Tistory ❤
gayulz - Overview
개발자가 되고싶은 개발어린이💟. gayulz has 11 repositories available. Follow their code on GitHub.
github.com
반응형