Giter Site home page Giter Site logo

swaggest / swgui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lazada/swgui

46.0 46.0 8.0 36.92 MB

Embedded Swagger UI for Go

Home Page: https://pkg.go.dev/github.com/swaggest/swgui

License: Apache License 2.0

Go 82.82% Makefile 17.18%
openapi openapi3 swagger swagger-ui

swgui's People

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

Watchers

 avatar  avatar

swgui's Issues

Make swgui relocatable?

I tried to use swaggest in my project today and I can't get the swaggest URL's to play nice with static files.

My goal was to have /api/... and /api/docs be provided by swaggest, with / being passed on to a http.FileServer, but using chi.Mount() to relocate swaggest from / to /api/ causes the swgui to 404 - but the actual REST connectors work just fine.

My code looks something like this (trimmed here for brevity):

func main() {
        // setup REST interface with OpenAPI documentation
        s := web.DefaultService()
	s.OpenAPI.Info.Title = "..."
	s.OpenAPI.Info.WithDescription("...")
	s.OpenAPI.Info.Version = "v0.0.1"
	s.Get("/item/{id}", getItemByID())
        // etc...
	s.Docs("/docs", v4emb.New)

	// static html/css/js files served from embedded FS
	uiFS := webui.StaticFS()

        // top-level router
	r := chi.NewRouter()
	r.Mount("/api/v1", s)                        // relocate swaggest to /api/v1/...
	r.Mount("/", http.FileServer(http.FS(uiFS))) // provide static files at /

        http.ListenAndServe("localhost:8080", r)
}

My problem here is that I have two different handlers (swaggest & http.FileServer) and chi only allows one to be mounted on "/", so I can't just use s.Get("/api/v1/item/{id}",...) because then I can't have the html files at "/"

If anyone has any working examples of having swaggest play nicely with other sub-routers, I'd be most interested.

by the way, I tried Mounting the FileServer on "/static", but that also didn't work. I'm thinking this may be an issue with chi :-/

Thanks in advance

Embedded assets base path

I’m having trouble using the v5emb module with my current setup, as the static assets are being referenced to without the base path of my application.

In my environments applications run behind an ingress with path-based routing inside a Kubernetes cluster.

Meaning for instance that Api1 receives its request with URL http://localhost/api1/…. All of the static assets are being attempted to be loaded using http://localhost/…] (notice the missing api1.

I believe there is way of configuring this asset base path using vearutop/statigz? But I don’t understand how to do so.

Any chance of someone shedding some light on this for me?

Issue compiling

 $ go get github.com/swaggest/swgui/...
go: downloading golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2
go: downloading golang.org/x/text v0.3.2
# github.com/vearutop/statigz
/home/pi/.golib/pkg/mod/github.com/vearutop/[email protected]/server.go:265:22: constant 9223372036854775807 overflows int

My GO version: $ go version
go version go1.16.2 linux/arm

Sort of a bug with urlencode - please double check...

I think i found sort of a bug with urlencoding of slashes.

Here what's going on:

I have an endpoint /api/hello/{name}

In the UI I enter "World" for Name.

This is now the Request URL http://localhost:8080/api/hello/World

In the UI I enter "World/of/bugs" for {name}.

This is now the Request URL http://localhost:8080/api/hello/World%2Fof%2Fbugs

However - this is wrong. The webserver will resolve this to this:

[GIN] 2021/04/04 - 23:49:31 | 404 | 2.853µs | 172.17.0.1 | GET "/api/hello/World/of/bugs"

Which is wrong :) That is simply a different endpoint. It is /api/hello/{a}/{b}/{c} and not /api/hello/{name}.

Slashes (maybe other stuff?) needs to be double encoded like this. Not just a singletime urlencoded :)

http://localhost:8080/api/hello/World%252Fof%252Fbugs

This is how it will arrive on the webserver:

[GIN] 2021/04/04 - 23:52:28 | 200 | 1.221707ms | 172.17.0.1 | GET "/api/hello/World%2Fof%2Fbugs"

Which is now the correct data in the application:

{
  "message": "Hello, World/of/bugs!"
}

Please double check...

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.