Skip to content

Commit

Permalink
Define req & res schema (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
shunsei committed Sep 30, 2024
1 parent 9f64b98 commit 7262628
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 50 deletions.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion api/components/examples/book.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
book:
request:
value:
title: "計算機プログラムの構造と解釈"
author: "Harold Abelson, Gerald Jay Sussman, Julie Sussman"
publisher: "翔泳社"
isbn: "9784798135984"
stock: 1

response:
value:
id: 1
title: "計算機プログラムの構造と解釈"
Expand Down
8 changes: 7 additions & 1 deletion api/components/examples/user.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
user:
request:
value:
name: "比企谷八幡"
password: "password"

response:
value:
id: 1
name: "比企谷八幡"
passwordDigest: "d41d8cd98f00b204e9800998ecf8427e"
64 changes: 48 additions & 16 deletions api/components/schemas/book.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
type: object
properties:
id:
type: integer
title:
type: string
author:
type: string
publisher:
type: string
edition:
type: integer
isbn:
type: string
stock:
type: integer
request:
type: object
properties:
title:
type: string
author:
type: string
publisher:
type: string
edition:
type: integer
isbn:
type: string
pattern: '^\d{13}$'
stock:
type: integer
required:
- title
- author
- publisher
- isbn
- stock

response:
type: object
properties:
id:
type: integer
title:
type: string
author:
type: string
publisher:
type: string
edition:
type: integer
isbn:
type: string
pattern: '^\d{13}$'
stock:
type: integer
required:
- id
- title
- author
- publisher
- isbn
- stock
30 changes: 24 additions & 6 deletions api/components/schemas/user.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
type: object
properties:
id:
type: integer
name:
type: string
request:
type: object
properties:
name:
type: string
password:
type: string
format: password
required:
- name
- password

response:
type: object
properties:
id:
type: integer
name:
type: string
passwordDigest:
type: string
required:
- id
- name
9 changes: 7 additions & 2 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ paths:

# /loans:
# /loans/{loanId}:

# /login:
# /logout:

components:
securitySchemes:
Expand All @@ -42,5 +45,7 @@ components:
scheme: basic

schemas:
Book:
$ref: "./components/schemas/book.yml"
Book:
$ref: "./components/schemas/book.yml#/response"
User:
$ref: "./components/schemas/user.yml#/response"
5 changes: 5 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"lint": "npx @redocly/cli lint openapi.yml"
}
}
2 changes: 2 additions & 0 deletions api/paths/auth.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
login:

31 changes: 16 additions & 15 deletions api/paths/book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ books:
schema:
type: array
items:
$ref: "../components/schemas/book.yml"
$ref: "../components/schemas/book.yml#/response"
'500':
$ref: "../components/responses/5xx.yml#/InternalServerError"

Expand All @@ -39,19 +39,17 @@ books:
content:
application/json:
schema:
$ref: "../components/schemas/book.yml"
$ref: "../components/schemas/book.yml#/request"
examples:
book:
$ref: "../components/examples/book.yml#/request"
responses:
'201':
description: 書籍の追加に成功した
content:
application/json:
schema:
type: object
properties:
code:
type: integer
message:
type: string
$ref: "../components/schemas/response.yml"
example:
code: 201
message: "Created"
Expand Down Expand Up @@ -89,10 +87,10 @@ book:
content:
application/json:
schema:
$ref: "../components/schemas/book.yml"
$ref: "../components/schemas/book.yml#/response"
examples:
book:
$ref: "../components/examples/book.yml#/book"
$ref: "../components/examples/book.yml#/response"
'404':
$ref: "../components/responses/4xx.yml#/NotFound"
'500':
Expand All @@ -117,17 +115,20 @@ book:
content:
application/json:
schema:
$ref: "../components/schemas/book.yml"
$ref: "../components/schemas/book.yml#/request"
examples:
book:
$ref: "../components/examples/book.yml#/request"
responses:
'200':
description: 情報の更新に成功した
content:
application/json:
schema:
$ref: "../components/schemas/book.yml"
examples:
book:
$ref: "../components/examples/book.yml#/book"
$ref: "../components/schemas/response.yml"
example:
code: 200
message: "OK"
'400':
description: リクエストボディに書籍の情報が含まれていない
content:
Expand Down
24 changes: 15 additions & 9 deletions api/paths/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ users:
schema:
type: array
items:
$ref: "../components/schemas/user.yml"
$ref: "../components/schemas/user.yml#/response"
'500':
$ref: "../components/responses/5xx.yml#/InternalServerError"

Expand All @@ -39,7 +39,10 @@ users:
content:
application/json:
schema:
$ref: "../components/schemas/user.yml"
$ref: "../components/schemas/user.yml#/request"
examples:
user:
$ref: "../components/examples/user.yml#/request"
responses:
'201':
description: ユーザーの追加に成功した
Expand Down Expand Up @@ -89,10 +92,10 @@ user:
content:
application/json:
schema:
$ref: "../components/schemas/user.yml"
$ref: "../components/schemas/user.yml#/response"
examples:
user:
$ref: "../components/examples/user.yml#/user"
$ref: "../components/examples/user.yml#/response"
'404':
$ref: "../components/responses/4xx.yml#/NotFound"
'500':
Expand All @@ -117,17 +120,20 @@ user:
content:
application/json:
schema:
$ref: "../components/schemas/user.yml"
$ref: "../components/schemas/user.yml#/request"
examples:
user:
$ref: "../components/examples/user.yml#/request"
responses:
'200':
description: 情報の更新に成功した
content:
application/json:
schema:
$ref: "../components/schemas/user.yml"
examples:
user:
$ref: "../components/examples/user.yml#/user"
$ref: "../components/schemas/response.yml"
example:
code: 200
message: "OK"
'400':
description: リクエストボディにユーザーの情報が含まれていない
content:
Expand Down
File renamed without changes.

0 comments on commit 7262628

Please sign in to comment.