GithubHelp home page GithubHelp logo

swaggo / echo-swagger Goto Github PK

View Code? Open in Web Editor NEW
739.0 739.0 120.0 96 KB

echo middleware to automatically generate RESTful API documentation with Swagger 2.0.

License: MIT License

Go 100.00%
echo echo-framework golang middleware swagger2

echo-swagger's People

Contributors

aermolaev avatar akojo avatar bilal-kilic avatar comphilip avatar dependabot[bot] avatar drewsilcock avatar easonlin404 avatar kakwa avatar kesuskim avatar kuklyy avatar madjake avatar mocaberos avatar nerzal avatar pei0804 avatar salprima avatar starcharles avatar ubogdan avatar wsw0108 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

echo-swagger's Issues

Add Proof Key for Code Exchange Support

Similar to the issue #243 in the gin-swagger repo, and swaggo/swag#871:

Is your feature request related to a problem? Please describe.
OAuth2 clients that only support Authorization Code Flow with PKCE do not work with the current feature set of echo-swagger.

Describe the solution
Add Proof Key for Code Exchange support. There is a flag for it in Swagger UI 3.24.0+. The flag in Swagger UI is usePkceWithAuthorizationCodeGrant.
In the corresponding Pull Request I added an additional attribute to the OAuthConfig struct called "UsePkce" which configures the boolean parameter for "usePkceWithAuthorizationCodeGrant" in the "initOAuth" part of the index template.
With this small change, the auth flow works as expected.

*core.ProxyResponseWriter is not http.Flusher

The error occurs after lambda starts and you try to hit the swagger endpoint.

  • Error:
[PANIC RECOVER] interface conversion: *core.ProxyResponseWriter is not http.Flusher: missing method Flush goroutine 54 [running]:
github.com/labstack/echo/v4/middleware.RecoverWithConfig.func1.1.1(0xef5fc8, 0x1000, 0x0, 0x1077148, 0xc001bcaa00)

  • Commit link:

aaf4249

Compilation problem:cannot use swaggerFiles.FS (variable of type fs.FS) as webdav.FileSystem value in struct literal

go version go1.18.9 windows/amd64

Build failed: cannot use swaggerFiles.FS (variable of type fs.FS) as webdav.FileSystem value in struct literal: fs.FS does not implement webdav.FileSystem (missing method Mkdir)

I found that the definitions of the two codes are inconsistent

// The FS interface defined as:
type FS interface {
	// Open opens the named file.
	//
	// When Open returns an error, it should be of type *PathError
	// with the Op field set to "open", the Path field set to name,
	// and the Err field describing the problem.
	//
	// Open should reject attempts to open names that do not satisfy
	// ValidPath(name), returning a *PathError with Err set to
	// ErrInvalid or ErrNotExist.
	Open(name string) (File, error)
}

// FileSystem in webdav defined as: 
type FileSystem interface {
	Mkdir(ctx context.Context, name string, perm os.FileMode) error
	OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (File, error)
	RemoveAll(ctx context.Context, name string) error
	Rename(ctx context.Context, oldName, newName string) error
	Stat(ctx context.Context, name string) (os.FileInfo, error)
}

How can I import from a yaml file

Hello everyone

I just want to import a yaml file for UI. I tryed but I got an error.

How can I make it?

Thanks

	e := echo.New()
	e.Use(middleware.Static("/static"))
	url := echoSwagger.URL("static/openapi.yaml")
	e.GET("/swagger/*", echoSwagger.EchoWrapHandler(url))

Output Screenshot:

Screenshot from 2022-02-23 12-28-21

two or more swagger html on the same app

Hi,

In my app, i have endpoints published in the main app ( at the URL /swagger/ ) and i have another one, with admin endpoints (for example)

import (
echoSwagger "github.com/swaggo/echo-swagger"
...
)
On the main...:

	url := echoSwagger.URL("admin.json")
	echo.GET("/admin/swagger/*", echoSwagger.EchoWrapHandler(url))
	echo.GET("/swagger/*", echoSwagger.WrapHandler)

I am finding problems with this solution, cause each time that i load something of "/admin/swagger/", the main swagger stops to work.

Is posible to perform this?

Thanks!!

No operations defined in spec!

No operations defined in spec!

Web capture_16-1-2022_3384_localhost

Web capture_16-1-2022_33729_editor swagger io

definitions:
  response.Struct:
    properties:
      code:
        type: integer
      data: {}
      message:
        type: string
      time_stamp:
        type: integer
    type: object
  services.AuthStruct:
    properties:
      password:
        maxLength: 20
        minLength: 6
        type: string
      user_name:
        maxLength: 20
        minLength: 6
        type: string
    required:
    - password
    - user_name
    type: object
info:
  contact: {}
paths:
  /login:
    post:
      consumes:
      - application/json
      description: User Login
      parameters:
      - description: user login
        in: body
        name: payload
        required: true
        schema:
          $ref: '#/definitions/services.AuthStruct'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/response.Struct'
        "400":
          description: wrong request parameter
          schema:
            $ref: '#/definitions/response.Struct'
        "20005":
          description: The corresponding username or password is incorrect
          schema:
            $ref: '#/definitions/response.Struct'
      summary: User Login
      tags:
      - Auth
securityDefinitions:
  ApiKeyAuth:
    in: 'header like: Bearer xxxx'
    name: Authorization
    type: apiKey
swagger: "2.0"

Swagger UI Not Picking Up Generated swagger.json

After annotating the Echo handlers, swag init is able to generate the swagger.json and swagger.yaml file in the docs folder. However when I browse to
http://localhost:8080/swagger/index.html
or
http://localhost:8080/swagger/v1/index.html

is still showing the default example items. Here is my setup:

// @title Nexlife Reward
// @version 1.0
// @description This is API spec for Nexlife Reward.
// @termsOfService https://tm.com.my/

// @contact.name Azzuwan Aziz
// @contact.url https://tm.com.my/
// @contact.email [email protected]

// @license.name TM Proprietary
// @license.url https://tm.com.my

// @host https://tm.com.my/
// @BasePath /v1

e.GET("/swagger/*", echoSwagger.WrapHandler)

// Create godoc
// @Summary Create a reward transaction
// @Description post a reward transaction
// @Tags transaction
// @Accept  json
// @Produce  json
// @Param user_id body model.transaction.Transaction.UserID true "ID of the user performing the transaction"
// @Param outlet_id body model.transation.Transaction.OutletID true "ID of the outlet the user is getting the reward"
// @Param point body model.transaction.Transaction.Point true "The value of the reward"
// @Success 200 {object} model.transaction.Transaction
// @Failure 400 {object} config.api.ResponseMessage
// @Failure 404 {object} config.api.ResponseMessage
// @Failure 500 {object} config.api.ResponseMessage
// @Router /transactions [post]

Is it possible to fill in parameters from the configuration?

The canonical example describes how to fill parameters with hardcode:

// @title Swagger Example API
// @version 1.0
// @host petstore.swagger.io
// @BasePath /v2

Is it possible to fill in parameters from the configuration or something template?

// @title Swagger Example API
// @version {{APP_VERSION}}
// @host {{APP_HOST}}
// @BasePath /v2

go version 1.18 Generics, swag init failed

When I use go 1.18 new feature: generics, I get error: expected '(', found '[' (and 1 more errors).
Obviously, swag parse not support go 1.18 new feature generics.
So when to support generics 😶

func IsElemInList[T any](elem T, list []T) bool {
	for i := 0; i < len(list); i++ {
		if reflect.DeepEqual(elem, list[i]) {
			return true
		}
	}
	return false
}

Swagger doesn't update HTML

I don't know how, but the doc.json seem to be static. I run the $ swagger init --g main.go, all files are created/edited and when I access by browser /swagger/index.html, nothing happens, doesn't update the JSON

// FIX TO LOAD CORRECT FILE
e.File("/swagger/doc.json", "./docs/swagger.json")

Libs and versions
v4.2.1 - github.com/labstack/echo/v4
v1.1.0 - github.com/swaggo/echo-swagger
v1.7.0 - github.com/swaggo/swag

Example + endpoint

Hello there,

I'm confused because the example doesn't have an endpoint, maybe adding an endpoint should be better.

Getting 404 for CSS and JS files

Hi,

I have deployed echo api and i am using echo swagger for documentation.

Golang Version golang:1.16-alpine3.13
echo-swagger version v1.1.0

I am getting 404 loading:

  1. swagger-ui.css
  2. swagger-ui-bundle.js
  3. swagger-ui-standalone-preset.js

I have defined the API as following:

        echo.GET("/swagger/*", echoSwagger.WrapHandler)
 	echo.GET("/test/", h.Status, enforcer.Enforce)
	echo.Start(":8080")

After more than 24-96 hours working in PRO properly, suddenly the app starts to drop 404 loading css, js that i mentioned.

Failed to load resource: the server responded with a status of 404 (Not Found)
swagger-ui-bundle.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
swagger-ui-standalone-preset.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
index.html:75 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at window.onload (index.html:75)
swagger-ui.css:1 Failed to load resource: the server responded with a status of 404 (Not Found)

If i restart app, it starts to work... but i dont know why it happens. I cant restart the app in PRO like i want.

Do you have any idea?

Thanks.

No operations defined in spec!

I follow the echo-wagger README tutorial and get the error bellow
image
And I google so many times and have no answer. so any help or suggesions would be appreciate.

Redirection error when using AddTrailingSlash middleware

Current Behavior

When AddTrainlingSlash middleware is used, the swagger route starts an infinite redirection loop resulting in ERR_TOO_MANY_REDIRECTS on the browser. It happens with both index.html and doc.json routes.

Steps to reproduce

  1. Follow the usage instructions and add the AddTrailingSlash middleware to the app:
package main

import (
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
	echoSwagger "github.com/swaggo/echo-swagger"
)

// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host petstore.swagger.io
// @BasePath /v2
func main() {
	e := echo.New()

	e.Pre(middleware.AddTrailingSlash())

	e.GET("/swagger/*", echoSwagger.WrapHandler)

	e.Logger.Fatal(e.Start(":1323"))
}

Data Race

I'm getting a data race the first time I hit swagger.

Versions:

github.com/labstack/echo/v4 v4.1.17
github.com/swaggo/echo-swagger v1.1.0
github.com/swaggo/swag v1.7.0

Server.go:

echoServer := echo.New()
echoServer.GET("/swagger/*", echoSwagger.WrapHandler)
err := echoServer.Start(httpAddr) // line 96

Data race:

==================
WARNING: DATA RACE
Write at 0x00c000416980 by goroutine 69:
  github.com/swaggo/echo-swagger.EchoWrapHandler.func1()
      ../go/pkg/mod/github.com/swaggo/[email protected]/swagger.go:60 +0x155
  github.com/labstack/echo/v4.(*Echo).add.func1()
      ../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:522 +0x81
  github.com/labstack/echo/v4.(*Echo).ServeHTTP()
      ../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:633 +0x209
  net/http.serverHandler.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2843 +0xca
  net/http.(*conn).serve()
      /usr/local/go/src/net/http/server.go:1925 +0x84c

Previous write at 0x00c000416980 by goroutine 67:
  github.com/swaggo/echo-swagger.EchoWrapHandler.func1()
      ../go/pkg/mod/github.com/swaggo/[email protected]/swagger.go:60 +0x155
  github.com/labstack/echo/v4.(*Echo).add.func1()
      ../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:522 +0x81
  github.com/labstack/echo/v4.(*Echo).ServeHTTP()
      ../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:633 +0x209
  net/http.serverHandler.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2843 +0xca
  net/http.(*conn).serve()
      /usr/local/go/src/net/http/server.go:1925 +0x84c

Goroutine 69 (running) created at:
  net/http.(*Server).Serve()
      /usr/local/go/src/net/http/server.go:2969 +0x5d3
  github.com/labstack/echo/v4.(*Echo).StartServer()
      ../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:724 +0x715
  github.com/labstack/echo/v4.(*Echo).Start()
      ../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:644 +0x2a9
  app/server.StartRESTServer()
      app/server/Server.go:96 +0x21e
  main.start()
      app/main.go:75 +0x5a
  main.main()
      app/main.go:67 +0x355

Goroutine 67 (running) created at:
  net/http.(*Server).Serve()
      /usr/local/go/src/net/http/server.go:2969 +0x5d3
  github.com/labstack/echo/v4.(*Echo).StartServer()
      ../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:724 +0x715
  github.com/labstack/echo/v4.(*Echo).Start()
      ../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:644 +0x2a9
  app/server.StartRESTServer()
      app/server/Server.go:96 +0x21e
  main.start()
      app/main.go:75 +0x5a
  main.main()
      app/main.go:67 +0x355
==================

oauth2-redirect.html with query parameters return 404

Hi, when I try to login oauth2 feature, it is redirection to this URL:

http://localhost:3000/swagger/oauth2-redirect.html?state=U3X..

But when I checked, if any query parameters go to this html oauth2-redirect.html route not found and return 404.

This should be bug and need to fix the route, serve steps.

v1.3.5 works fine with oauth2 redirection.

How can I use routes that are defined outside the directory structure of main package?

for example a directory structure like:

repo
  cmd
    app
      main.go // echo server code here
      docs
        docs.go // generated swag init files here
        ...
  internal
    routes
      index.go // route definitions including declarative comments

Running swag init from repo/cmd/app produces some files in repo/cmd/app/docs/ but it doesn't seem to discover any docs elsewhere

Show document page when delete "docs/*"

Step1: copy README.md example to main.go

Step2: set API doc in user.go

Setp3: run swag init

the page work but not show user.go API doc:
http://localhost:1323/swagger/index.html

so, I run rm -rf docs/* and rerun my main.go, the Swagger page still show....what happen?

Env:

  • WLS 2 (Ubuntu 22) on Windows10 64x
  • Golang 1.18
  • GoLand 2022
  • PATH has /usr/local/go/:
  • /usr/local/go/bin:/home/uiosun/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/usr/local/go/bin:/home/uiosun/go/bin:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/d/softwares/Bandizip/:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mn t/d/softwares/Git/cmd:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Users/sunzeyu/AppData/Local/Microsoft/WindowsApps:/mnt/d/softwares/xampp/php:/mnt/d/softwares/gpl/prometheus-2.40.0.windows-amd64:/snap/bin:/usr/local/go/bin

Swagger UI shows empty

Thanks for the this package, unfortunately swagger UI doesn't show API details

package main

import (
	_ "myecho-swagger/docs" // docs is generated by Swag CLI, you have to import it.
	"net/http"

	"github.com/labstack/echo/v4"
	echoSwagger "github.com/swaggo/echo-swagger"
)

// @title Swagger Example API
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host petstore.swagger.io
// @BasePath /v2
func main() {
	e := echo.New()

	// Or can use EchoWrapHandler func with configurations.
	url := echoSwagger.URL("http://localhost:1323/swagger/doc.json") //The url pointing to API definition
	e.GET("/swagger/*", echoSwagger.EchoWrapHandler(url))

	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, World!")
	})

	e.Logger.Fatal(e.Start(":1323"))
}

image

Expose OpenAPI in yml in a different endpoint

Hi,
Would be good to have the possibility to expose the .yml resource in a dedicated endpoint. (Our use case is to interface with a tool that fetches documentation and is only consuming yml). Would it be valuable for the project ? If so, I'll try to have a look and submit a pull request.
Thanks anyway for your work !
Ed

Incompatibility of version 4

Cannot use 'echoSwagger.WrapHandler' (type "github.com/labstack/echo/v4".HandlerFunc) as type "github.com/labstack/echo".HandlerFunc 

Why is there that warning when i do
e.GET("/docs/*", echoSwagger.WrapHandler) ?

help with echo example

could you help please =?

captura de pantalla 2019-02-17 a la s 23 12 30

http://localhost:1323/swagger/doc.json is empty!

captura de pantalla 2019-02-17 a la s 23 08 58

package main

import (
	"net/http"
	"github.com/labstack/echo"
	"github.com/swaggo/echo-swagger"
)

type Sensor struct {
	Id      string `json:"id" xml:"id"`
	Value   string `json:"value" xml:"value"`
	Status  string `json:"status" xml:"status"`
	OwnerId string `json:"owner_id" xml:"owner_id"`
}


// @title Sensors Api
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email [email protected]

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host petstore.swagger.io
// @BasePath /v2
func main() {

	e := echo.New()

	e.GET("/swagger/*", echoSwagger.WrapHandler)

	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Sensor Service")
	})

	// @Produce  json
	// @Router /sensors/:id/air-quality [get]
	//TODO: integrate with firebase
	e.GET("/sensors/:id/air-quality", getSensorInfo)

	//TODO: integrate with firebase
	e.GET("/sensors/:id/temperature", getSensorInfo)

	//TODO: integrate with firebase
	e.GET("/sensors/:id/humidity", getSensorInfo)

	//TODO: integrate with firebase
	e.GET("/sensors/:id/co2gas", getSensorInfo)

	e.Logger.Fatal(e.Start(":1323"))

}

func getSensorInfo(c echo.Context) error {

	id := c.Param("id")

	aq := &Sensor{
		Id: id,
		Value:  "100",
		Status: "normal",
		OwnerId: "municipalidad",
	}

	return c.JSON(http.StatusOK, aq)

}

with go mod echo-swagger cant find package

hi,
i have some issue that i can run go build, go test, go get
that because go send error like this

  • go: finding github.com/swaggo/echo-swagger latest
  • go: downloading github.com/swaggo/echo-swagger v0.0.0-20190219082602-1a361fc821b8
    build myproject: cannot load github.com/swaggo/echo-swagger: cannot find module providing package github.com/swaggo/echo-swagger

this happen when i use "go mod", anybody can help to solve this problem ?

in my go mod have require like this

require (
cloud.google.com/go v0.37.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/denisenkom/go-mssqldb v0.0.0-20190315220205-a8ed825ac853
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/kr/pty v1.1.4 // indirect
github.com/labstack/echo v3.3.10+incompatible
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/swaggo/echo-swagger/v2 v2.0.0-20190219082602-1a361fc821b8
github.com/swaggo/gin-swagger v1.1.0 // indirect
github.com/swaggo/swag v1.4.1 // indirect
github.com/tylerb/graceful v1.2.15
github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 // indirect
github.com/valyala/fasttemplate v1.0.1 // indirect
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576 // indirect
golang.org/x/net v0.0.0-20190322120337-addf6b3196f6 // indirect
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc // indirect
golang.org/x/tools v0.0.0-20190322203728-c1a832b0ad89 // indirect
)

thank you

Is it possible to create swagger-ui from a yaml file

Hello everyone

I'm trying to create swagger ui from a yaml file but I getting an error.

I could not solve this problem.

How can I make it?

Help me please.
Thanks

e := echo.New()

url := echoSwagger.URL("./static/openapi.yaml")
e.GET("/swagger/*", echoSwagger.EchoWrapHandler(url))

e.Logger.Fatal(e.Start(":1919"))

Output Screenshot:

Screenshot from 2022-02-23 12-28-21

IncompatibleAssign Swagger

Getting this error

cannot use echoSwagger.WrapHandler (variable of type "github.com/labstack/echo/v4".HandlerFunc) as "github.com/labstack/echo".HandlerFunc value in argument to e.GETcompiler[IncompatibleAssign](https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#IncompatibleAssign)

There are repeated slashes when jumping to index

The regular match contains a slash, but an extra slash is spliced below.

echo-swagger/swagger.go

Lines 131 to 164 in 5602047

var re = regexp.MustCompile(`^(.*/)([^?].*)?[?|.]*$`)
return func(c echo.Context) error {
if c.Request().Method != http.MethodGet {
return echo.NewHTTPError(http.StatusMethodNotAllowed, http.StatusText(http.StatusMethodNotAllowed))
}
matches := re.FindStringSubmatch(c.Request().RequestURI)
path := matches[2]
switch filepath.Ext(path) {
case ".html":
c.Response().Header().Set("Content-Type", "text/html; charset=utf-8")
case ".css":
c.Response().Header().Set("Content-Type", "text/css; charset=utf-8")
case ".js":
c.Response().Header().Set("Content-Type", "application/javascript")
case ".json":
c.Response().Header().Set("Content-Type", "application/json; charset=utf-8")
case ".yaml":
c.Response().Header().Set("Content-Type", "text/plain; charset=utf-8")
case ".png":
c.Response().Header().Set("Content-Type", "image/png")
}
response := c.Response()
// This check fixes an error introduced here: https://github.com/labstack/echo/blob/8da8e161380fd926d4341721f0328f1e94d6d0a2/response.go#L86-L88
if _, ok := response.Writer.(http.Flusher); ok {
defer response.Flush()
}
switch path {
case "":
_ = c.Redirect(http.StatusMovedPermanently, matches[1]+"/"+"index.html")

So if you access the path /swagger/, you will get /swagger//index.html

enums not parsed correctly

I've a model with enum tag, but swagger json does not include the enums:

type Contact struct {
ID int json:"id" validate:"required"
Type string json:"type" validate:"required" enums:"phone,fax,email"
}

What's my fault?

Go module git tag

git tag it to support latest go module please.

$ git tag v1.0.0
$ git push --tags

Is there any way to use echo-swagger with echo.v3?

Hi, when use echo-swagger with echo v3.3.6, I got

Could not introduce github.com/swaggo/echo-swagger@master, as it requires package github.com/labstack/echo/v4 from github.com/labstack/echo, but in version v3.3.6 that package is missing.

In my case, I can't use go modules and can't update echo.v3 to v4.
So, my question is that is there any way to echo-swagger with echo.v3?
Thanks for your help.

My Go version
1.12.5

@Failure, @Success Response Type Usage Error

I am going to use the structure type for the private module as the response type for @sucess, @failure.
However, ParseCommentError in... A cannot find type definition error message occurs.

Can't I use the structure type for the private module as a response type?
Please tell me the solution.

securityDefinitions are not parsed

I have added securityDefinitions.apikey to my api doc annotations and used the security definition on a route.

What I expected: The route will have the lock-symbol-button rendered on its right side, where I can click on to fill out auth data for the protected route. Additionally, a green "Authorize" Button is rendered at the top of the swaggerUI page where I can configure auth methods as well.

What I got: The little lock-symbol is rendered on my route, but there is no action when I click on it. There is no "Authorize" Button neither.
When I check the generated swagger.json, I can see that there is an empty security entry on my route:

"security": [
                    {
                        "ApiKeyAuth": []
                    }
                ],

But no security config whatsoever at the root level (where host, info etc are defined).
My guess is therefore that swaggo did not parse my securityDefinition annotation at all.

You can see a minimum setup to reproduce this issue in this repository: https://github.com/adrian-sturm/swaggo-test

Latest swagger returns swagger-ui-bundle. version: 3.23.0

Our application is currently using latest echo-swagger version.v1.3.3. github.com/swaggo/files also on latest version.

But swagger-ui-bundle.js is at older version: 3.23.0.
/swagger/swagger-ui-bundle.js Extracted version from JavaScript bundle: ...d=!0,h="g23d7260f",v="3.23.0",...

Expected version: 4.11.0

Register called twice for swag

I have two webserver starting in same main program. If i try to register them as separate swagger module, its throwing following error.

panic: Register called twice for swag: Management

goroutine 1 [running]:
github.com/swaggo/swag.Register(0x18ce987, 0xa, 0x19b23e0, 0x2716df0)
/Users/knarukulla/.gvm/pkgsets/go1.15/global/pkg/mod/github.com/swaggo/[email protected]/swagger.go:30 +0x12f
identity/web/mgmt/docs.init.0()
/Users/knarukulla/workspace/data-processing/src/main/go/src/identity/web/mgmt/docs/docs.go:487 +0x

Swagger Ui is loading after upgrading version 1.3.1 release

We are getting below error when we load swagger ui.

reactProdInvariant.js:29 Uncaught Invariant Violation: Minified React error #37; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=37 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at e.exports (https://sunpathms.cmh.reportsstage.evinternal.net/swagger/swagger-ui-bundle.js:2:77966)
    at Object._renderNewRootComponent (https://sunpathms.cmh.reportsstage.evinternal.net/swagger/swagger-ui-bundle.js:2:628862)
    at Object._renderSubtreeIntoContainer (https://sunpathms.cmh.reportsstage.evinternal.net/swagger/swagger-ui-bundle.js:2:629937)
    at Object.render (https://sunpathms.cmh.reportsstage.evinternal.net/swagger/swagger-ui-bundle.js:2:630064)
    at j (https://sunpathms.cmh.reportsstage.evinternal.net/swagger/swagger-ui-bundle.js:2:274191)
    at m (https://sunpathms.cmh.reportsstage.evinternal.net/swagger/swagger-ui-bundle.js:2:1089719)
    at Lr (https://sunpathms.cmh.reportsstage.evinternal.net/swagger/swagger-ui-bundle.js:2:1090084)
    at window.onload (https://sunpathms.cmh.reportsstage.evinternal.net/swagger/index.html:75:14)

Dependency issue

Tag 1.0.0 has dependency issue

go: github.com/swaggo/[email protected] requires
        github.com/swaggo/[email protected] requires
        github.com/ugorji/[email protected] requires
        github.com/ugorji/go/[email protected]: reading github.com/ugorji/go/codec/codec/go.mod at revision codec/v1.1.5-pre: unknown revision codec/v1.1.5-pre

I have tried echo-swagger master(v1.0.1-0.20200924082307-3a99ef02e455), but still not working

go: finding github.com/swaggo/echo-swagger master
go: github.com/swaggo/[email protected] requires
        github.com/swaggo/[email protected] requires
        github.com/ugorji/[email protected] requires
        github.com/ugorji/go/[email protected]: reading github.com/ugorji/go/codec/codec/go.mod at revision codec/v1.1.5-pre: unknown revision codec/v1.1.5-pre

Any help? thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.