Skip to content

Commit 59a3bbb

Browse files
authored
docs: add missing swagger types and examples (#231)
Resolves #139.
1 parent 276d519 commit 59a3bbb

File tree

12 files changed

+460
-231
lines changed

12 files changed

+460
-231
lines changed

api/docs.go

Lines changed: 153 additions & 80 deletions
Large diffs are not rendered by default.

api/swagger.json

Lines changed: 153 additions & 80 deletions
Large diffs are not rendered by default.

api/swagger.yaml

Lines changed: 114 additions & 31 deletions
Large diffs are not rendered by default.

pkg/controllers/budget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type BudgetLinks struct {
3131
Accounts string `json:"accounts" example:"https://example.com/api/v1/accounts?budget=550dc009-cea6-4c12-b2a5-03446eb7b7cf"`
3232
Categories string `json:"categories" example:"https://example.com/api/v1/categories?budget=550dc009-cea6-4c12-b2a5-03446eb7b7cf"`
3333
Transactions string `json:"transactions" example:"https://example.com/api/v1/transactions?budget=550dc009-cea6-4c12-b2a5-03446eb7b7cf"`
34-
Month string `json:"month" example:"https://example.com/api/v1/budgets/550dc009-cea6-4c12-b2a5-03446eb7b7cf/2022-03"`
34+
Month string `json:"month" example:"https://example.com/api/v1/budgets/550dc009-cea6-4c12-b2a5-03446eb7b7cf/YYYY-MM"` // This will always end in 'YYYY-MM' for clients to use replace with actual numbers.
3535
}
3636

3737
type BudgetMonthResponse struct {

pkg/controllers/envelope.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type EnvelopeMonthResponse struct {
3232
type EnvelopeLinks struct {
3333
Self string `json:"self" example:"https://example.com/api/v1/envelopes/45b6b5b9-f746-4ae9-b77b-7688b91f8166"`
3434
Allocations string `json:"allocations" example:"https://example.com/api/v1/allocations?envelope=45b6b5b9-f746-4ae9-b77b-7688b91f8166"`
35-
Month string `json:"month" example:"https://example.com/api/v1/envelopes/45b6b5b9-f746-4ae9-b77b-7688b91f8166/2019-03"`
35+
Month string `json:"month" example:"https://example.com/api/v1/envelopes/45b6b5b9-f746-4ae9-b77b-7688b91f8166/YYYY-MM"` // This will always end in 'YYYY-MM' for clients to use replace with actual numbers.
3636
}
3737

3838
// RegisterEnvelopeRoutes registers the routes for envelopes with

pkg/models/account.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ type Account struct {
1212
Model
1313
AccountCreate
1414
Budget Budget `json:"-"`
15-
Balance decimal.Decimal `json:"balance" gorm:"-"`
16-
ReconciledBalance decimal.Decimal `json:"reconciledBalance" gorm:"-"`
15+
Balance decimal.Decimal `json:"balance" gorm:"-" example:"2735.17"`
16+
ReconciledBalance decimal.Decimal `json:"reconciledBalance" gorm:"-" example:"2539.57"`
1717
}
1818

1919
type AccountCreate struct {
20-
Name string `json:"name,omitempty" example:"Checking"`
21-
Note string `json:"note,omitempty" example:"My bank account"`
20+
Name string `json:"name,omitempty" example:"Cash" default:""`
21+
Note string `json:"note,omitempty" example:"Money in my wallet" default:""`
2222
BudgetID uuid.UUID `json:"budgetId" example:"550dc009-cea6-4c12-b2a5-03446eb7b7cf"`
23-
OnBudget bool `json:"onBudget" example:"false"` // Always false when external: true
24-
External bool `json:"external" example:"true"`
23+
OnBudget bool `json:"onBudget" example:"true" default:"false"` // Always false when external: true
24+
External bool `json:"external" example:"false" default:"false"`
2525
}
2626

2727
func (a Account) WithCalculations() Account {

pkg/models/allocation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type Allocation struct {
1313
}
1414

1515
type AllocationCreate struct {
16-
Month uint8 `json:"month" gorm:"uniqueIndex:year_month;check:month_valid,month >= 1 AND month <= 12"`
17-
Year uint `json:"year" gorm:"uniqueIndex:year_month"`
18-
Amount decimal.Decimal `json:"amount" gorm:"type:DECIMAL(20,8)"`
19-
EnvelopeID uuid.UUID `json:"envelopeId,omitempty"`
16+
Month uint8 `json:"month" gorm:"uniqueIndex:year_month;check:month_valid,month >= 1 AND month <= 12" minimum:"1" maximum:"12" example:"6"`
17+
Year uint `json:"year" gorm:"uniqueIndex:year_month" example:"2022"`
18+
Amount decimal.Decimal `json:"amount" gorm:"type:DECIMAL(20,8)" example:"22.01" minimum:"0.00000001" maximum:"999999999999.99999999" multipleOf:"0.00000001"` // The maximum value is "999999999999.99999999", swagger unfortunately rounds this.
19+
EnvelopeID uuid.UUID `json:"envelopeId,omitempty" example:"a0909e84-e8f9-4cb6-82a5-025dff105ff2"`
2020
}

pkg/models/budget.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ import (
1414
type Budget struct {
1515
Model
1616
BudgetCreate
17-
Balance decimal.Decimal `json:"balance" gorm:"-"`
17+
Balance decimal.Decimal `json:"balance" gorm:"-" example:"3423.42"`
1818
}
1919

2020
type BudgetCreate struct {
21-
Name string `json:"name,omitempty" example:"My First Budget"`
22-
Note string `json:"note,omitempty" example:"A description so I remember what this was for"`
23-
Currency string `json:"currency,omitempty" example:"€"`
21+
Name string `json:"name,omitempty" example:"Morre's Budget" default:""`
22+
Note string `json:"note,omitempty" example:"My personal expenses" default:""`
23+
Currency string `json:"currency,omitempty" example:"€" default:""`
2424
}
2525

2626
type BudgetMonth struct {
27-
ID uuid.UUID `json:"id" example:"23"`
28-
Name string `json:"name" example:"A test envelope"`
29-
Month time.Time `json:"month" example:"2006-05-04T15:02:01.000000Z"`
27+
ID uuid.UUID `json:"id" example:"1e777d24-3f5b-4c43-8000-04f65f895578"` // The ID of the Envelope
28+
Name string `json:"name" example:"Groceries"` // The name of the Envelope
29+
Month time.Time `json:"month" example:"2006-05-01T00:00:00.000000Z"` // This is always set to 00:00 UTC on the first of the month.
3030
Envelopes []EnvelopeMonth `json:"envelopes,omitempty"`
3131
}

pkg/models/category.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type Category struct {
1010
}
1111

1212
type CategoryCreate struct {
13-
Name string `json:"name,omitempty"`
14-
BudgetID uuid.UUID `json:"budgetId"`
15-
Note string `json:"note,omitempty"`
13+
Name string `json:"name,omitempty" example:"Saving" default:""`
14+
BudgetID uuid.UUID `json:"budgetId" example:"52d967d3-33f4-4b04-9ba7-772e5ab9d0ce"`
15+
Note string `json:"note,omitempty" example:"All envelopes for long-term saving" default:""`
1616
}

pkg/models/envelope.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ type Envelope struct {
1616
}
1717

1818
type EnvelopeCreate struct {
19-
Name string `json:"name,omitempty"`
20-
CategoryID uuid.UUID `json:"categoryId"`
21-
Note string `json:"note,omitempty"`
19+
Name string `json:"name,omitempty" example:"Groceries" default:""`
20+
CategoryID uuid.UUID `json:"categoryId" example:"878c831f-af99-4a71-b3ca-80deb7d793c1"`
21+
Note string `json:"note,omitempty" example:"For stuff bought at supermarkets and drugstores" default:""`
2222
}
2323

2424
// EnvelopeMonth contains data about an Envelope for a specific month.
2525
type EnvelopeMonth struct {
26-
ID uuid.UUID `json:"id"`
27-
Name string `json:"name"`
28-
Month time.Time `json:"month"`
29-
Spent decimal.Decimal `json:"spent"`
30-
Balance decimal.Decimal `json:"balance"`
31-
Allocation decimal.Decimal `json:"allocation"`
26+
ID uuid.UUID `json:"id" example:"10b9705d-3356-459e-9d5a-28d42a6c4547"` // The ID of the Envelope
27+
Name string `json:"name" example:"Groceries"` // The name of the Envelope
28+
Month time.Time `json:"month" example:"1969-06-01T00:00:00.000000Z"` // This is always set to 00:00 UTC on the first of the month.
29+
Spent decimal.Decimal `json:"spent" example:"73.12"`
30+
Balance decimal.Decimal `json:"balance" example:"12.32"`
31+
Allocation decimal.Decimal `json:"allocation" example:"85.44"`
3232
}
3333

3434
// Spent returns the amount spent for the month the time.Time instance is in.

0 commit comments

Comments
 (0)