Skip to content

Commit f13e353

Browse files
committed
feat: openapi generation testing with swag
1 parent d0219f5 commit f13e353

12 files changed

Lines changed: 657 additions & 861 deletions

File tree

apps/api/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ migrate-down:
99
generate:
1010
@sqlc generate
1111

12+
generate-openapi:
13+
swag init --dir cmd/api,internal/api/handlers --parseDependency -v3.1

apps/api/cmd/api/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ import (
1717
"github.com/swamphacks/core/apps/api/internal/storage"
1818
)
1919

20+
// @title SwampHacks Test API
21+
// @version 1.0
22+
// @description This is SwampHacks' OpenAPI documentation.
23+
// @termsOfService TODO
24+
25+
// @contact.name API Support
26+
// @contact.url http://www.swagger.io/support
27+
// @contact.email support@swagger.io
28+
29+
// @license.name Apache 2.0
30+
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
2031
func main() {
2132
logger := logger.New()
2233
cfg := config.Load()

apps/api/docs/docs.go

Lines changed: 169 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/api/docs/swagger.json

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"components": {
3+
"schemas": {
4+
"middleware.UserContext": {
5+
"description": "Information about the current user session.",
6+
"properties": {
7+
"email": {
8+
"description": "Primary email address (nullable)",
9+
"example": "user@example.com",
10+
"type": "string"
11+
},
12+
"emailConsent": {
13+
"description": "Whether the user agreed to receive emails",
14+
"example": false,
15+
"type": "boolean"
16+
},
17+
"image": {
18+
"description": "Optional profile image URL\n@nullable",
19+
"example": "https://cdn.example.com/avatar.png",
20+
"nullable": true,
21+
"type": "string"
22+
},
23+
"name": {
24+
"description": "Full display name",
25+
"example": "Jane Doe",
26+
"type": "string"
27+
},
28+
"onboarded": {
29+
"description": "Whether the user completed onboarding",
30+
"example": true,
31+
"type": "boolean"
32+
},
33+
"preferredEmail": {
34+
"description": "Preferred email address for communications",
35+
"example": "user.alt@example.com",
36+
"type": "string"
37+
},
38+
"role": {
39+
"$ref": "#/components/schemas/sqlc.AuthUserRole"
40+
},
41+
"userId": {
42+
"description": "Unique identifier for the user",
43+
"example": "550e8400-e29b-41d4-a716-446655440000",
44+
"format": "uuid",
45+
"type": "string"
46+
}
47+
},
48+
"type": "object"
49+
},
50+
"response.ErrorResponse": {
51+
"properties": {
52+
"error": {
53+
"type": "string"
54+
},
55+
"message": {
56+
"type": "string"
57+
}
58+
},
59+
"type": "object"
60+
},
61+
"sqlc.AuthUserRole": {
62+
"description": "Role assigned to the user",
63+
"enum": [
64+
"user",
65+
"superuser"
66+
],
67+
"type": "string",
68+
"x-enum-varnames": [
69+
"AuthUserRoleUser",
70+
"AuthUserRoleSuperuser"
71+
]
72+
}
73+
}
74+
},
75+
"info": {
76+
"contact": {
77+
"email": "support@swagger.io",
78+
"name": "API Support",
79+
"url": "http://www.swagger.io/support"
80+
},
81+
"description": "This is SwampHacks' OpenAPI documentation.",
82+
"license": {
83+
"name": "Apache 2.0",
84+
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
85+
},
86+
"termsOfService": "TODO",
87+
"title": "SwampHacks Test API",
88+
"version": "1.0"
89+
},
90+
"externalDocs": {
91+
"description": "",
92+
"url": ""
93+
},
94+
"paths": {
95+
"/auth/me": {
96+
"get": {
97+
"description": "get user from session",
98+
"requestBody": {
99+
"content": {
100+
"application/json": {
101+
"schema": {
102+
"type": "object"
103+
}
104+
}
105+
}
106+
},
107+
"responses": {
108+
"200": {
109+
"content": {
110+
"application/json": {
111+
"schema": {
112+
"$ref": "#/components/schemas/middleware.UserContext"
113+
}
114+
}
115+
},
116+
"description": "OK"
117+
},
118+
"400": {
119+
"content": {
120+
"application/json": {
121+
"schema": {
122+
"$ref": "#/components/schemas/response.ErrorResponse"
123+
}
124+
}
125+
},
126+
"description": "Bad Request"
127+
},
128+
"500": {
129+
"content": {
130+
"application/json": {
131+
"schema": {
132+
"$ref": "#/components/schemas/response.ErrorResponse"
133+
}
134+
}
135+
},
136+
"description": "Internal Server Error"
137+
}
138+
},
139+
"summary": "Get details of current user.",
140+
"tags": [
141+
"auth"
142+
]
143+
}
144+
}
145+
},
146+
"openapi": "3.1.0"
147+
}

0 commit comments

Comments
 (0)