Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,4 @@ Please check existing issues and discussions before starting work on new feature

## License

[MIT License](LICENSE) — Created with ❤️ by [Ahmad Faiz](https://github.com/akfaiz).
[MIT](LICENSE)
17 changes: 17 additions & 0 deletions adapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Framework Adapters

This directory contains framework-specific adapters for `oaswrap/spec` that provide seamless integration with popular Go web frameworks. Each adapter automatically generates OpenAPI 3.x specifications from your existing routes and handlers.

## Available Adapters

### Web Frameworks

| Framework | Adapter | Go Module | Description |
|-----------|---------|-----------|-------------|
| [Chi](https://github.com/go-chi/chi) | [`chiopenapi`](./chiopenapi) | `github.com/oaswrap/spec/adapter/chiopenapi` | Lightweight router with middleware support |
| [Echo](https://github.com/labstack/echo) | [`echoopenapi`](./echoopenapi) | `github.com/oaswrap/spec/adapter/echoopenapi` | High performance, extensible, minimalist framework |
| [Fiber](https://github.com/gofiber/fiber) | [`fiberopenapi`](./fiberopenapi) | `github.com/oaswrap/spec/adapter/fiberopenapi` | Express-inspired framework built on Fasthttp |
| [Gin](https://github.com/gin-gonic/gin) | [`ginopenapi`](./ginopenapi) | `github.com/oaswrap/spec/adapter/ginopenapi` | Fast HTTP web framework with zero allocation |
| [net/http](https://pkg.go.dev/net/http) | [`httpopenapi`](./httpopenapi) | `github.com/oaswrap/spec/adapter/httpopenapi` | Standard library HTTP package |
| [HttpRouter](https://github.com/julienschmidt/httprouter) | [`httprouteropenapi`](./httprouteropenapi) | `github.com/oaswrap/spec/adapter/httprouteropenapi` | High performance HTTP request router |
| [Gorilla Mux](https://github.com/gorilla/mux) | [`muxopenapi`](./muxopenapi) | `github.com/oaswrap/spec/adapter/muxopenapi` | Powerful HTTP router and URL matcher |
2 changes: 1 addition & 1 deletion adapter/chiopenapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ We welcome contributions! Please open issues and PRs at the main [oaswrap/spec](

## License

[MIT License](LICENSE) — Created with ❤️ by [Ahmad Faiz](https://github.com/akfaiz).
[MIT](../../LICENSE)
4 changes: 2 additions & 2 deletions adapter/echoopenapi/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type LoginResponse struct {
}

type GetUserRequest struct {
ID string `path:"id" required:"true"`
ID string `param:"id" required:"true"`
}

type User struct {
Expand Down Expand Up @@ -194,4 +194,4 @@ We welcome contributions! Please open issues and PRs at the main [oaswrap/spec](

## License

[MIT License](LICENSE) — Created with ❤️ by [Ahmad Faiz](https://github.com/akfaiz).
[MIT](../../LICENSE)
2 changes: 1 addition & 1 deletion adapter/echoopenapi/examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type LoginResponse struct {
}

type GetUserRequest struct {
ID string `path:"id" required:"true"`
ID string `param:"id" required:"true"`
}

type User struct {
Expand Down
2 changes: 2 additions & 0 deletions adapter/echoopenapi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/oaswrap/spec => ../..
4 changes: 4 additions & 0 deletions adapter/echoopenapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/oaswrap/spec"
specui "github.com/oaswrap/spec-ui"
"github.com/oaswrap/spec/adapter/echoopenapi/internal/constant"
"github.com/oaswrap/spec/openapi"
"github.com/oaswrap/spec/option"
"github.com/oaswrap/spec/pkg/mapper"
"github.com/oaswrap/spec/pkg/parser"
Expand Down Expand Up @@ -36,6 +37,9 @@ func NewGenerator(e *echo.Echo, opts ...option.OpenAPIOption) Generator {
option.WithPathParser(parser.NewColonParamParser()),
option.WithStoplightElements(),
option.WithCacheAge(0),
option.WithReflectorConfig(
option.ParameterTagMapping(openapi.ParameterInPath, "param"),
),
}
opts = append(defaultOpts, opts...)
gen := spec.NewRouter(opts...)
Expand Down
12 changes: 6 additions & 6 deletions adapter/echoopenapi/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get pet by ID"),
option.Description("Retrieve a pet by its ID."),
option.Request(new(struct {
ID int `path:"petId" required:"true"`
ID int `param:"petId" required:"true"`
})),
option.Response(200, new(dto.Pet)),
)
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get order by ID"),
option.Description("Retrieve an order by its ID."),
option.Request(new(struct {
ID int `path:"orderId" required:"true"`
ID int `param:"orderId" required:"true"`
})),
option.Response(200, new(dto.Order)),
option.Response(404, nil),
Expand All @@ -236,7 +236,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Delete an order"),
option.Description("Delete an order by its ID."),
option.Request(new(struct {
ID int `path:"orderId" required:"true"`
ID int `param:"orderId" required:"true"`
})),
option.Response(204, nil),
)
Expand All @@ -263,7 +263,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get user by username"),
option.Description("Retrieve a user by their username."),
option.Request(new(struct {
Username string `path:"username" required:"true"`
Username string `param:"username" required:"true"`
})),
option.Response(200, new(dto.PetUser)),
option.Response(404, nil),
Expand All @@ -275,7 +275,7 @@ func TestRouter_Spec(t *testing.T) {
option.Request(new(struct {
dto.PetUser

Username string `path:"username" required:"true"`
Username string `param:"username" required:"true"`
})),
option.Response(200, new(dto.PetUser)),
option.Response(404, nil),
Expand All @@ -285,7 +285,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Delete a user"),
option.Description("Delete a user from the store by their username."),
option.Request(new(struct {
Username string `path:"username" required:"true"`
Username string `param:"username" required:"true"`
})),
option.Response(204, nil),
)
Expand Down
4 changes: 2 additions & 2 deletions adapter/fiberopenapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type LoginResponse struct {
}

type GetUserRequest struct {
ID string `path:"id" required:"true"`
ID string `params:"id" required:"true"`
}

type User struct {
Expand Down Expand Up @@ -189,4 +189,4 @@ We welcome contributions! Please open issues and PRs at the main [oaswrap/spec](

## License

[MIT License](LICENSE) — Created with ❤️ by [Ahmad Faiz](https://github.com/akfaiz).
[MIT](../../LICENSE)
2 changes: 1 addition & 1 deletion adapter/fiberopenapi/examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type LoginResponse struct {
}

type GetUserRequest struct {
ID string `path:"id" required:"true"`
ID string `params:"id" required:"true"`
}

type User struct {
Expand Down
2 changes: 2 additions & 0 deletions adapter/fiberopenapi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/oaswrap/spec => ../..
4 changes: 4 additions & 0 deletions adapter/fiberopenapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/oaswrap/spec"
specui "github.com/oaswrap/spec-ui"
"github.com/oaswrap/spec/adapter/fiberopenapi/internal/constant"
"github.com/oaswrap/spec/openapi"
"github.com/oaswrap/spec/option"
"github.com/oaswrap/spec/pkg/mapper"
"github.com/oaswrap/spec/pkg/parser"
Expand All @@ -29,6 +30,9 @@ func NewRouter(r fiber.Router, opts ...option.OpenAPIOption) Generator {
option.WithPathParser(parser.NewColonParamParser()),
option.WithStoplightElements(),
option.WithCacheAge(0),
option.WithReflectorConfig(
option.ParameterTagMapping(openapi.ParameterInPath, "params"),
),
}
opts = append(defaultOpts, opts...)
gen := spec.NewGenerator(opts...)
Expand Down
12 changes: 6 additions & 6 deletions adapter/fiberopenapi/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get pet by ID"),
option.Description("Retrieve a pet by its ID."),
option.Request(new(struct {
ID int `path:"petId" required:"true"`
ID int `params:"petId" required:"true"`
})),
option.Response(200, new(dto.Pet)),
)
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get order by ID"),
option.Description("Retrieve an order by its ID."),
option.Request(new(struct {
ID int `path:"orderId" required:"true"`
ID int `params:"orderId" required:"true"`
})),
option.Response(200, new(dto.Order)),
option.Response(404, nil),
Expand All @@ -176,7 +176,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Delete an order"),
option.Description("Delete an order by its ID."),
option.Request(new(struct {
ID int `path:"orderId" required:"true"`
ID int `params:"orderId" required:"true"`
})),
option.Response(204, nil),
)
Expand All @@ -203,7 +203,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get user by username"),
option.Description("Retrieve a user by their username."),
option.Request(new(struct {
Username string `path:"username" required:"true"`
Username string `params:"username" required:"true"`
})),
option.Response(200, new(dto.PetUser)),
option.Response(404, nil),
Expand All @@ -215,7 +215,7 @@ func TestRouter_Spec(t *testing.T) {
option.Request(new(struct {
dto.PetUser

Username string `path:"username" required:"true"`
Username string `params:"username" required:"true"`
})),
option.Response(200, new(dto.PetUser)),
option.Response(404, nil),
Expand All @@ -225,7 +225,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Delete a user"),
option.Description("Delete a user from the store by their username."),
option.Request(new(struct {
Username string `path:"username" required:"true"`
Username string `params:"username" required:"true"`
})),
option.Response(204, nil),
)
Expand Down
2 changes: 1 addition & 1 deletion adapter/ginopenapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ We welcome contributions! Please open issues and PRs at the main [oaswrap/spec](

## License

[MIT License](LICENSE) — Created with ❤️ by [Ahmad Faiz](https://github.com/akfaiz).
[MIT](../../LICENSE)
2 changes: 1 addition & 1 deletion adapter/ginopenapi/examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type LoginResponse struct {
}

type GetUserRequest struct {
ID string `path:"id" uri:"id" required:"true"`
ID string `uri:"id" required:"true"`
}

type User struct {
Expand Down
2 changes: 2 additions & 0 deletions adapter/ginopenapi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/oaswrap/spec => ../..
4 changes: 4 additions & 0 deletions adapter/ginopenapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/oaswrap/spec"
specui "github.com/oaswrap/spec-ui"
"github.com/oaswrap/spec/adapter/ginopenapi/internal/constant"
"github.com/oaswrap/spec/openapi"
"github.com/oaswrap/spec/option"
"github.com/oaswrap/spec/pkg/mapper"
"github.com/oaswrap/spec/pkg/parser"
Expand All @@ -30,6 +31,9 @@ func NewRouter(ginRouter gin.IRouter, opts ...option.OpenAPIOption) Generator {
option.WithPathParser(parser.NewColonParamParser()),
option.WithStoplightElements(),
option.WithCacheAge(0),
option.WithReflectorConfig(
option.ParameterTagMapping(openapi.ParameterInPath, "uri"),
),
}
opts = append(defaultOpts, opts...)
gen := spec.NewRouter(opts...)
Expand Down
12 changes: 6 additions & 6 deletions adapter/ginopenapi/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get pet by ID"),
option.Description("Retrieve a pet by its ID."),
option.Request(new(struct {
ID int `path:"petId" required:"true"`
ID int `uri:"petId" required:"true"`
})),
option.Response(200, new(dto.Pet)),
)
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get order by ID"),
option.Description("Retrieve an order by its ID."),
option.Request(new(struct {
ID int `path:"orderId" required:"true"`
ID int `uri:"orderId" required:"true"`
})),
option.Response(200, new(dto.Order)),
option.Response(404, nil),
Expand All @@ -174,7 +174,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Delete an order"),
option.Description("Delete an order by its ID."),
option.Request(new(struct {
ID int `path:"orderId" required:"true"`
ID int `uri:"orderId" required:"true"`
})),
option.Response(204, nil),
)
Expand All @@ -201,7 +201,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Get user by username"),
option.Description("Retrieve a user by their username."),
option.Request(new(struct {
Username string `path:"username" required:"true"`
Username string `uri:"username" required:"true"`
})),
option.Response(200, new(dto.PetUser)),
option.Response(404, nil),
Expand All @@ -213,7 +213,7 @@ func TestRouter_Spec(t *testing.T) {
option.Request(new(struct {
dto.PetUser

Username string `path:"username" required:"true"`
Username string `uri:"username" required:"true"`
})),
option.Response(200, new(dto.PetUser)),
option.Response(404, nil),
Expand All @@ -223,7 +223,7 @@ func TestRouter_Spec(t *testing.T) {
option.Summary("Delete a user"),
option.Description("Delete a user from the store by their username."),
option.Request(new(struct {
Username string `path:"username" required:"true"`
Username string `uri:"username" required:"true"`
})),
option.Response(204, nil),
)
Expand Down
2 changes: 1 addition & 1 deletion adapter/httpopenapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,4 @@ We welcome contributions! Please open issues and PRs at the main [oaswrap/spec](

## License

[MIT License](LICENSE) — Created with ❤️ by [Ahmad Faiz](https://github.com/akfaiz).
[MIT](../../LICENSE)
2 changes: 1 addition & 1 deletion adapter/httprouteropenapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@ We welcome contributions! Please open issues and PRs at the main [oaswrap/spec](

## License

[MIT License](LICENSE) — Created with ❤️ by [Ahmad Faiz](https://github.com/akfaiz).
[MIT](../../LICENSE)
2 changes: 1 addition & 1 deletion adapter/httprouteropenapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (r *router) Group(prefix string, middlewares ...func(http.Handler) http.Han
group := &router{
router: r.router,
middlewares: append(r.middlewares, middlewares...),
specRouter: r.specRouter.Group(prefix),
specRouter: r.specRouter.Group(""),
prefix: r.pathOf(prefix),
}
return group
Expand Down
Loading