Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omitting host returns Internal Server Error (500) #1019

Closed
akshay196 opened this issue Oct 7, 2021 · 6 comments
Closed

Omitting host returns Internal Server Error (500) #1019

akshay196 opened this issue Oct 7, 2021 · 6 comments

Comments

@akshay196
Copy link

Describe the bug
When I omit host field in a Gin based application and try to access API documentation using localhost:5000/swagger/index.html I get Fetch error Internal Server Error doc.json. Screenshot attached.

Received 500 in the application log:

[GIN] 2021/10/07 - 13:20:11 | 500 |        9.59µs |       127.0.0.1 | GET      "/swagger/doc.json"

As per the Swagger 2.0 specification, host and schemes can be omitted for a more dynamic association. In this case, the host and scheme used to serve the API documentation will be used for API calls. (reference)

To Reproduce
Steps to reproduce the behavior:

  1. Develop Gin application with no host specified.
// @title App
// @version 0.1
// @description application description

// @BasePath /

// @securityDefinitions.apikey Token
// @in header
// @name Authorization
func main() {
	app := gin.Default()
        //...
}
  1. Run swag init
  2. Then run your application
  3. Visit localhost:5000/swagger/index.html (application is running at localhost:5000)
  4. See error in browser

Expected behavior
The API documentation should not return 500. The host and scheme used to serve the API documentation will be used for API calls.

Screenshots
Screenshot from 2021-10-07 13-26-58

Your swag version
v1.7.3

Your go version
1.16.5

Desktop (please complete the following information):

  • OS: Linux/Fedora
  • Browser: Firefox
  • Version:
@akshay196
Copy link
Author

This comment solved this issue.

@volkansolak
Copy link

Hi, i am having this problem too. How did you analyze it?

@Sadakhatali
Copy link

Hi, I am also facing same problem, while accessing the swagger I am facing same error like above

@samozturk
Copy link

You need to import docs package in your main package.
docs package is created by swagger when you swag init.

@beijJxy
Copy link

beijJxy commented Aug 16, 2023

You need to import docs package in your main package. docs package is created by swagger when you swag init.

Thank you so much

@Anorboyev-Xayrullo
Copy link

You need to import docs package in your main package.
docs package is created by swagger when you swag init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants