Skip to content

no matching operation was found when servers are defined #356

@crodwell

Description

@crodwell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions