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

no matching operation was found when servers are defined #356

Closed
crodwell opened this issue Apr 29, 2021 · 7 comments · Fixed by #467
Closed

no matching operation was found when servers are defined #356

crodwell opened this issue Apr 29, 2021 · 7 comments · Fixed by #467

Comments

@crodwell
Copy link
Contributor

crodwell commented Apr 29, 2021

using gin gonic is a framework, I can't seem to match a route to the the api spec

my code is pretty much as per example;

    router, _ := legacyrouter.NewRouter(s.ApiSpec)
    route, pathParams, err := router.FindRoute(c.Request)
    // no matching operation was found

I traced the problem to this part of the code

func (router *Router) FindRoute(req *http.Request) (*routers.Route, map[string]string, error) {
	method, url := req.Method, req.URL
	doc := router.doc
	// Get server
	servers := doc.Servers
	var server *openapi3.Server
	var remainingPath string
	var pathParams map[string]string
	if len(servers) == 0 {
		remainingPath = url.Path
	} else {
		var paramValues []string
		server, paramValues, remainingPath = servers.MatchURL(url)
		if server == nil {
				return nil, nil, &routers.RouteError{
				Reason: routers.ErrPathNotFound.Error(),
			}
		}

servers =

(openapi3.Servers) (len=1 cap=4) {
 (*openapi3.Server)(0xc000321b00)({
  ExtensionProps: (openapi3.ExtensionProps) {
   Extensions: (map[string]interface {}) {
   }
  },
  URL: (string) (len=24) "http://192.168.0.30:3000",
  Description: (string) (len=3) "API",
  Variables: (map[string]*openapi3.ServerVariable) <nil>
 })
}

url = /plans and that definitely exists in my openapi.yml file

@crodwell crodwell changed the title panic gin gonic - no matching operation was found Apr 29, 2021
@crodwell
Copy link
Contributor Author

crodwell commented Apr 30, 2021

Interestingly when I duplicate that router and remove the offending code;

func (router *Router) FindRoute(req *http.Request) (*routers.Route, map[string]string, error) {
	method, url := req.Method, req.URL
	doc := router.doc
	// Get server
	// servers := doc.Servers
	// var server *openapi3.Server
	var remainingPath string
	var pathParams map[string]string
	// if len(servers) == 0 {
	remainingPath = url.Path
	/*} else {
		var paramValues []string
		server, paramValues, remainingPath = servers.MatchURL(url)
		if server == nil {
			return nil, nil, &routers.RouteError{
				Reason: routers.ErrPathNotFound.Error(),
			}
		}
		pathParams = make(map[string]string, 8)
		paramNames, _ := server.ParameterNames()
		for i, value := range paramValues {
			name := paramNames[i]
			pathParams[name] = value
		}
	}*/

	// Get PathItem
	root := router.node()
	var route *routers.Route

The validation works, no idea how or why

@fenollp
Copy link
Collaborator

fenollp commented Apr 30, 2021

Could you tell us more? e.g. what's the value of req.URL?

Ideally you'd formulate your issue as a test and open a PR with it to prove something isn't right.

@crodwell
Copy link
Contributor Author

crodwell commented May 4, 2021

Hi @fenollp , thanks for the quick reply. Fair enough, turns out this issue is nothing to do with gin gonic and I can reproduce it in the test cases:

#357

@fenollp
Copy link
Collaborator

fenollp commented May 4, 2021

Thanks for the bug PR!

Ah it seems you're hitting #118
I'd love to review your PR on this :)

@crodwell
Copy link
Contributor Author

crodwell commented May 4, 2021

I'm not sure it is the same as being unable to process localhost. I first came across the problem connecting to a development server that was defined as

servers:
  - url: 'http://192.168.0.30:3000'
    description: API

As I said on my second comment, I can work around it - but I'm not sure I should be submitting that as a PR as it's probably used for another scenario I'm unfamiliar with

@crodwell
Copy link
Contributor Author

crodwell commented May 6, 2021

oh, or I can just remove the servers from the spec altogether and it works fine without changing code :)

@crodwell crodwell changed the title gin gonic - no matching operation was found no matching operation was found when servers are defined May 6, 2021
@fenollp
Copy link
Collaborator

fenollp commented May 20, 2021

Isn't the whole of 192.168 submask LAN? In any case these hosts are probably handled similarly to localhost by Golang.
I still believe this is #118. See this comment on how/why local hosts don't match the legacy router: #118 (comment)

I can remove the servers altogether and it works

is discussed there as well :)

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

Successfully merging a pull request may close this issue.

2 participants