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

Using inline struct inside of function that returns http.HandlerFunc can't generate spec #2383

Open
snowzach opened this issue Aug 14, 2020 · 0 comments
Labels
generate spec Related to spec generation from code scanner

Comments

@snowzach
Copy link

Environment

swagger version: 48f1315
go version: 1.14
OS: Linux

Testing this for generating swagger specs... I have this function that returns an HTTP handler:

// Login logs in a user
func (s *Server) Login() http.HandlerFunc {

	type loginRequest struct {
		Username string `json:"username"`
		Password string `json:"password"`
	}
	
	type loginResponse struct {
		Token string `json:"token"`
	}
	
	// This returns the JWT token used for Authorization: Bearer header
	// swagger:parameters login
	type SwaggerRequest struct {
		// The username and password payload
		// in: body
		// requred: true
		Payload *loginRequest
	}

	// Login Success
	// swagger:response loginResponse
	type SwaggerResponse struct {
		// The JWT token
		// in: body
		Payload *loginResponse
	}

	// swagger:route POST /api/login AUTH login
	// Login to system
	// responses:
	//   200: loginResponse "Success"
	return func(w http.ResponseWriter, r *http.Request) {
		// do login stuff
	}
}

When I try to generate the spec it shows:
unable to find package and source file for: github.com/reponame/package.passwordRequest

If I move the loginRequest and loginResponse structs outside of the Login() function it works. Is there any way to fix it to be able to see those struct in that scope? Is there a better way I should be defining this login function?

@fredbi fredbi added the generate spec Related to spec generation from code label Aug 16, 2020
@fredbi fredbi added the scanner label Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generate spec Related to spec generation from code scanner
Projects
None yet
Development

No branches or pull requests

2 participants