Skip to content

Commit

Permalink
doc: separate openapi.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
ken109 committed Oct 21, 2023
1 parent d661008 commit 13a8b02
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 112 deletions.
1 change: 1 addition & 0 deletions adapter/gateway/mysql/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mysql

import (
"context"

"go-gin-clean-arch/config"
"go-gin-clean-arch/domain"
"gorm.io/gorm"
Expand Down
4 changes: 3 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ services:
- "8081:8080"
volumes:
- ./doc/openapi.yaml:/openapi.yaml
- ./doc/paths:/paths
- ./doc/components:/components
environment:
SWAGGER_JSON: /openapi.yaml
SWAGGER_JSON: /openapi.yaml
26 changes: 26 additions & 0 deletions doc/components/examples/users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
create_request:
value:
email: 'example@example.com'
password: 'password'
password_confirm: 'password'

login_request:
value:
session: false
email: 'example@example.com'
password: 'password'

refresh_token_request:
value:
session: false
refresh_token: ''

reset_password_request_request:
value:
email: 'example@example.com'

reset_password_request:
value:
recovery_token: ''
password: 'password'
password_confirm: 'password'
69 changes: 69 additions & 0 deletions doc/components/schemas/users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
create_request:
type: object
properties:
email:
type: string
format: email
password:
type: string
password_confirm:
type: string

login_request:
type: object
properties:
session:
type: boolean
description: If true, the response will contain a session token
email:
type: string
password:
type: string

login_response:
type: object
properties:
token:
type: string
refresh_token:
type: string

refresh_token_request:
type: object
properties:
session:
type: boolean
refresh_token:
type: string

refresh_token_response:
type: object
properties:
token:
type: string
refresh_token:
type: string

reset_password_request_request:
type: object
properties:
email:
type: string

reset_password_request:
type: object
properties:
recovery_token:
type: string
password:
type: string
password_confirm:
type: string

me_response:
type: object
properties:
id:
type: string
email:
type: string
127 changes: 16 additions & 111 deletions doc/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,137 +1,42 @@
openapi: 3.1.0

info:
title: Go DDD
title: Go API
version: 1.0.0

servers:
- url: http://localhost:8080
description: Local server

tags:
- name: Health
description: ヘルスチェック
- name: User
description: ユーザー

paths:
/users:
post:
/health:
get:
tags:
- User
summary: Create
requestBody:
content:
application/json:
schema:
type: object
example:
email: 'example@example.com'
password: 'password'
password_confirm: 'password'
- Health
summary: Health
responses:
'200':
description: Successful response
content:
application/json: { }
/users:
$ref: './paths/users.yaml#/users'
/users/login:
post:
tags:
- User
summary: Login
requestBody:
content:
application/json:
schema:
type: object
example:
session: false
email: 'example@example.com'
password: 'password'
responses:
'200':
description: Successful response
content:
application/json: { }
$ref: './paths/users.yaml#/login'
/users/refresh-token:
post:
security:
- bearerAuth: [ ]
tags:
- User
summary: RefreshToken
requestBody:
content:
application/json:
schema:
type: object
example:
session: false
refresh_token: ''
responses:
'200':
description: Successful response
content:
application/json: { }
$ref: './paths/users.yaml#/refresh_token'
/users/reset-password-request:
patch:
security:
- bearerAuth: [ ]
tags:
- User
summary: ResetPasswordRequest
requestBody:
content:
application/json:
schema:
type: object
example:
email: 'example@example.com'
responses:
'200':
description: Successful response
content:
application/json: { }
$ref: './paths/users.yaml#/reset_password_request'
/users/reset-password:
patch:
security:
- bearerAuth: [ ]
tags:
- User
summary: ResetPassword
requestBody:
content:
application/json:
schema:
type: object
example:
recovery_token: ''
password: 'password'
password_confirm: 'password'
responses:
'200':
description: Successful response
content:
application/json: { }
$ref: './paths/users.yaml#/reset_password'
/users/me:
get:
security:
- bearerAuth: [ ]
tags:
- User
summary: Me
responses:
'200':
description: Successful response
content:
application/json: { }
/health:
get:
tags:
- default
summary: Health
responses:
'200':
description: Successful response
content:
application/json: { }

$ref: './paths/users.yaml#/me'

components:
securitySchemes:
Expand Down
113 changes: 113 additions & 0 deletions doc/paths/users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
users:
post:
tags:
- User
summary: Create
requestBody:
content:
application/json:
schema:
$ref: '../components/schemas/users.yaml#/create_request'
examples:
ok:
$ref: '../components/examples/users.yaml#/create_request'
responses:
'200':
description: Successful response

login:
post:
tags:
- User
summary: Login
requestBody:
content:
application/json:
schema:
$ref: '../components/schemas/users.yaml#/login_request'
examples:
ok:
$ref: '../components/examples/users.yaml#/login_request'
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '../components/schemas/users.yaml#/login_response'

refresh_token:
post:
security:
- bearerAuth: [ ]
tags:
- User
summary: RefreshToken
requestBody:
content:
application/json:
schema:
$ref: '../components/schemas/users.yaml#/refresh_token_request'
examples:
ok:
$ref: '../components/examples/users.yaml#/refresh_token_request'
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '../components/schemas/users.yaml#/refresh_token_response'

reset_password_request:
patch:
security:
- bearerAuth: [ ]
tags:
- User
summary: ResetPasswordRequest
requestBody:
content:
application/json:
schema:
$ref: '../components/schemas/users.yaml#/reset_password_request'
examples:
ok:
$ref: '../components/examples/users.yaml#/reset_password_request'
responses:
'200':
description: Successful response

reset_password:
patch:
security:
- bearerAuth: [ ]
tags:
- User
summary: ResetPassword
requestBody:
content:
application/json:
schema:
$ref: '../components/schemas/users.yaml#/reset_password_request'
examples:
ok:
$ref: '../components/examples/users.yaml#/reset_password_request'
responses:
'200':
description: Successful response

me:
get:
security:
- bearerAuth: [ ]
tags:
- User
summary: Me
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '../components/schemas/users.yaml#/me_response'

0 comments on commit 13a8b02

Please sign in to comment.