This is a template API implementation using Go and the Gin framework, with automatic Swagger documentation generation.
- Go - Programming language
- Gin - Web framework
- gin-swagger - Swagger/OpenAPI documentation generation
- RESTful API endpoints
- Automatic Swagger/OpenAPI documentation
- Automated Swagger 2.0 to OpenAPI 3.0.0 conversion (pure Go implementation)
- CORS support
- Health check endpoint
- Example integration with external API (JSONPlaceholder)
- Proper error handling and response formatting
- Go 1.21 or higher
- Internet connection (for external API calls)
-
Navigate to the API directory:
cd api -
Install dependencies:
go mod tidy
-
Install swag tool (for Swagger generation):
go install github.com/swaggo/swag/cmd/swag@latest
-
Ensure swag is in your PATH (add this to your shell profile if needed):
export PATH=$PATH:$(go env GOPATH)/bin
-
Generate OpenAPI 3.0.0 documentation:
# From repository root directory ./generate-openapi.sh -
Start the server:
# Manually from the api directory go run . # Makefile from root directory make run_api_dev
The API will be available at http://localhost:8080
GET /api/v1/health- Health checkGET /api/v1/posts- (Sample) Get all posts from JSONPlaceholderGET /api/v1/posts/{id}- (Sample) Get a specific post by IDGET /swagger/index.html- Swagger UI documentationPOST /api/v1/directions/bicycle- 自転車ルート検索GET /api/v1/search?q={検索キーワード}- 目的地候補取得
The API automatically generates OpenAPI/Swagger documentation through the following workflow:
- Swagger 2.0 Generation:
swag initgenerates Swagger 2.0 format indocs/swagger.json - Conversion to OpenAPI 3.0.0: A Go converter transforms it to OpenAPI 3.0.0 format
- Output: Final specification is placed in
../openapi-specifications/api.swagger.json
The documentation is:
- Served at
/swagger/index.htmlwhen the server is running (Swagger 2.0 format) - Available as OpenAPI 3.0.0 in
../openapi-specifications/api.swagger.jsonfor tooling
To regenerate OpenAPI 3.0.0 documentation after making changes:
Complete workflow (Recommended):
# From repository root
./generate-openapi.shThis script will:
- Run
swag initto generate Swagger 2.0 documentation inapi/docs/ - Test that
npm run gen-schemaandnpm run mockwork correctly
Manual steps:
# 1. Generate Swagger 2.0
cd api && swag init && cd ..
# 2. Test React Native tooling
cd mobile-app
npm run gen-schema # Generate TypeScript definitions
npm run mock # Start mock server on port 3001