Skip to content

Commit

Permalink
Merge pull request #4 from traPtitech/configure-oapi-codegen
Browse files Browse the repository at this point in the history
サーバー側のコードの自動生成
  • Loading branch information
akimon658 authored Dec 31, 2024
2 parents 00794fb + 6e72ff0 commit 95d7f19
Show file tree
Hide file tree
Showing 6 changed files with 794 additions and 152 deletions.
12 changes: 12 additions & 0 deletions docs/generate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 生成手順

## Server

`server` ディレクトリがなければ作成してください。
その後

```bash
go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest -config oapi-codegen.yaml openapi.yaml
```

を実行すると `server/gen.go` が生成されます。
31 changes: 31 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module github.com/traPtitech/Checkin-openapi

go 1.23.4

require (
github.com/getkin/kin-openapi v0.128.0
github.com/labstack/echo/v4 v4.13.3
github.com/oapi-codegen/runtime v1.1.1
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
73 changes: 73 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 6 additions & 0 deletions oapi-codegen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package: api
output: server/gen.go
generate:
echo-server: true
models: true
embedded-spec: true
170 changes: 18 additions & 152 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ paths:
description: OK
content:
application/json:
examples:
Customer:
$ref: '#/components/examples/Customer'
schema:
$ref: '#/components/schemas/Customer'
'404':
$ref: '#/components/responses/NotFound'
'500':
Expand All @@ -51,9 +50,8 @@ paths:
description: Created
content:
application/json:
examples:
Customer:
$ref: '#/components/examples/Customer'
schema:
$ref: '#/components/schemas/Customer'
'500':
$ref: '#/components/responses/InternalServerError'
patch:
Expand All @@ -71,9 +69,8 @@ paths:
description: OK
content:
application/json:
examples:
Customer:
$ref: '#/components/examples/Customer'
schema:
$ref: '#/components/schemas/Customer'
'500':
$ref: '#/components/responses/InternalServerError'
/invoice:
Expand All @@ -92,9 +89,8 @@ paths:
description: Created
content:
application/json:
examples:
Invoice:
$ref: '#/components/examples/Invoice'
schema:
$ref: '#/components/schemas/Invoice'
'500':
$ref: '#/components/responses/InternalServerError'
/webhook/invoice-paid:
Expand All @@ -113,9 +109,8 @@ paths:
requestBody:
content:
application/json:
examples:
Invoice:
$ref: '#/components/examples/Invoice'
schema:
$ref: '#/components/schemas/Invoice'
responses:
'204':
description: No content
Expand Down Expand Up @@ -160,7 +155,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/GetInvoicesResponse'
$ref: '#/components/schemas/Invoice'
'403':
$ref: '#/components/responses/Forbidden'
'500':
Expand Down Expand Up @@ -205,133 +200,6 @@ paths:
$ref: '#/components/responses/InternalServerError'

components:
examples:
Customer:
description: Customer オブジェクト
value:
id: cus_NffrFeUfNV2Hib
object: customer
address: null
balance: 0
created: 1680893993
currency: null
default_source: null
delinquent: false
description: null
discount: null
email: [email protected]
invoice_prefix: 0759376C
invoice_settings:
custom_fields: null
default_payment_method: null
footer: null
rendering_options: null
livemode: false
metadata: {}
name: Jenny Rosen
next_invoice_sequence: 1
phone: null
preferred_locales: []
shipping: null
tax_exempt: none
test_clock: null
Invoice:
description: Invoice オブジェクト
value:
id: in_1MtHbELkdIwHu7ixl4OzzPMv
object: invoice
account_country: US
account_name: Stripe Docs
account_tax_ids: null
amount_due: 0
amount_paid: 0
amount_remaining: 0
amount_shipping: 0
application: null
application_fee_amount: null
attempt_count: 0
attempted: false
auto_advance: false
automatic_tax:
enabled: false
liablity: null
status: null
billing_reason: manual
charge: null
collection_method: charge_automatically
created: 1680644467
currency: usd
custom_fields: null
customer: cus_NeZwdNtLEOXuvB
customer_address: null
customer_email: [email protected]
customer_name: Jenny Rosen
customer_phone: null
customer_shipping: null
customer_tax_exempt: none
customer_tax_ids: []
default_payment_method: null
default_source: null
default_tax_rates: []
description: null
discount: null
discounts: []
due_date: null
ending_balance: 0
footer: null
from_invoice: null
hosted_invoice_url: null
invoice_pdf: null
issuer:
type: self
last_finalization_error: null
latest_revision: null
lines:
object: list
data: []
has_more: false
total_count: 0
url: /v1/invoices/in_1MtHbELkdIwHu7ixl4OzzPMv/lines
livemode: false
metadata: {}
next_payment_attempt: null
number: null
on_behalf_of: null
paid: false
paid_out_of_band: false
payment_intent: null
payment_settings:
default_mandate: null
payment_method_options: null
payment_method_types: null
period_end: 1680644467
period_start: 1680644467
post_payment_credit_notes_amount: 0
pre_payment_credit_notes_amount: 0
quote: null
receipt_number: null
rendering_options: null
shipping_cost: null
shipping_details: null
shipping_balance: 0
statement_descriptor: null
status: draft
status_transitions:
finalized_at: null
marked_uncollectible_at: null
paid_at: null
voided_at: null
subscription: null
subtotal: 0
subtotal_excluding_tax: 0
tax: null
test_clock: null
total: 0
total_discount_amounts: []
total_excluding_tax: 0
total_tax_amounts: []
transfer_data: null
webhooks_delivered_at: 1680644467
parameters:
CustomerId:
name: customer_id
Expand Down Expand Up @@ -376,7 +244,7 @@ components:
InternalServerError:
description: Internal server error
schemas:
CustomerData:
Customer:
description: Customer の情報
type: object
properties:
Expand Down Expand Up @@ -425,8 +293,8 @@ components:
required:
- customer_id
- product_id
GetInvoicesResponse:
description: 請求書由来の入金一覧
Invoice:
description: Invoice の情報
type: object
properties:
has_more:
Expand Down Expand Up @@ -458,7 +326,7 @@ components:
description: 作成日時 (Unix 時間)
example: 1680644467
customer:
$ref: '#/components/schemas/CustomerData'
$ref: '#/components/schemas/Customer'
status:
type: string
description: 請求書ステータス
Expand All @@ -472,9 +340,8 @@ components:
payment_intent:
type:
- string
- "null"
description: この請求書に関連付けられた PaymentIntent
example: null
example: pi_3MtwBwLkdIwHu7ix28a3tqPa
product_id:
type: string
description: Product ID
Expand Down Expand Up @@ -508,7 +375,7 @@ components:
description: 作成日時 (Unix 時間)
example: 1679600215
customer:
$ref: '#/components/schemas/CustomerData'
$ref: '#/components/schemas/Customer'
status:
type: string
description: Checkout Session のステータス
Expand All @@ -520,9 +387,8 @@ components:
payment_intent:
type:
- string
- "null"
description: この Checkout Session に関連付けられた PaymentIntent
example: null
example: pi_3MtwBwLkdIwHu7ix28a3tqPa
product_id:
type: string
description: Product ID
Expand Down
Loading

0 comments on commit 95d7f19

Please sign in to comment.