Development Environment Setup
Prerequisites
- Go 1.21 or later
- Git
Clone and Build
git clone https://github.com/andrianprasetya/open-swag-go.git
cd open-swag-go
go mod download
go build ./...Project Structure
open-swag-go/
├── config.go # Core Config, Docs, Endpoint types
├── adapters/
│ ├── chi/ # Chi adapter
│ ├── gin/ # Gin adapter
│ ├── echo/ # Echo adapter
│ ├── fiber/ # Fiber adapter
│ └── nethttp/ # net/http adapter
├── pkg/
│ ├── auth/ # Authentication schemes and playground
│ ├── tryit/ # Try-it console and code snippets
│ ├── versioning/ # Version diffing and breaking changes
│ ├── schema/ # Schema generation from structs
│ └── examples/ # Example value generation
├── examples/ # Example applications
└── docs/ # This documentation siteRunning Tests
All Tests
go test ./...Specific Package
go test ./pkg/schema/...
go test ./adapters/chi/...With Coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.outRace Detection
go test -race ./...Submitting Pull Requests
Workflow
- Fork the repository
- Create a feature branch from
main:git checkout -b feature/my-feature - Make your changes
- Run tests and linting:
go test ./... go vet ./... - Commit with a conventional commit message (see below)
- Push and open a pull request against
main
PR Requirements
- All tests must pass
- New code must include tests
- No decrease in test coverage
- Code must pass
go vetandgolangci-lint - PR description should explain what and why
Code Style
Go Conventions
- Follow Effective Go and the Go Code Review Comments
- Use
gofmtfor formatting (enforced by CI) - Run
golangci-lintbefore committing:golangci-lint run
Naming
- Use descriptive names:
GenerateSpecnotGenSpec - Exported types and functions must have doc comments
- Interface names should describe behavior:
Validator,Generator
Error Handling
- Return errors instead of panicking
- Wrap errors with context:
fmt.Errorf("failed to generate schema for %s: %w", typeName, err) - Use sentinel errors for expected conditions
Commit Message Conventions
Follow Conventional Commits:
<type>(<scope>): <description>
[optional body]Types
| Type | Description |
|---|---|
feat | New feature |
fix | Bug fix |
docs | Documentation changes |
test | Adding or updating tests |
refactor | Code change that neither fixes a bug nor adds a feature |
chore | Build process or tooling changes |
perf | Performance improvement |
Examples
feat(auth): add OAuth2 PKCE flow support
fix(schema): handle pointer types in nested structs
docs(adapters): add Fiber middleware example
test(versioning): add breaking change detection testsScope
Use the package or directory name as the scope: auth, schema, chi, gin, echo, fiber, nethttp, tryit, versioning, examples, docs.
Documentation Contributions
The docs site lives in the docs/ directory and uses Fumadocs with MDX.
Running the Docs Site Locally
cd docs
bun install
bun run devAdding a New Page
- Create an
.mdxfile in the appropriatecontent/docs/subdirectory - Add frontmatter with
titleanddescription - Add the page slug to the directory's
meta.json - Write your content using MDX