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

Method designed without params/placeholders throws "missing path parameter placeholder in url"? #91

Closed
metaleap opened this issue Nov 13, 2023 · 3 comments

Comments

@metaleap
Copy link

metaleap commented Nov 13, 2023

Using v0.2.42 here, go getted just today.

My error-raising request-struct looks like this: struct { Id yodb.I64 } which actually equates structurally/mem-wise to struct { Id int64 }.

(It's an unnamed type so I guess reflect.Type.Name will be empty, but not sure. But that's not the cause — just double-checked by temporarily naming it.)

My Add-ing code: op.AddReqStructure(reflect.New(ty_args).Interface(), openapi.WithContentType("application/json"))

This errors out with:

validate path params post /_/postDelete: missing path parameter placeholder in url: Id", link:

Nothing after "link:". What's the idea? The underlying method expects a {"Id": number} payload and does not offer any url placeholdering/parametering. How and why is the assumption there?

(Don't tell me the _ in /_/postDelete is interpreted as placeholder? That's a url-prefix for all our api-method paths, so that any non-_/* path after / is free as a user-claimable vanity-name/base-path, even sth. like apis 😁 )

From what I can tell:

  • AddOperation calls SetupOperation calls SanitizeMethodPath which receives the pathPattern of "/_/postDelete". I'd expect pathParametersSubmatches to be empty for your {([^}:]+)(:[^}]+)?(?:}) regex (tried out quickly at regex101.com which said "no match").
  • So then SetupOperation should receive pathParams as empty/nil, and yet clearly it doesn't — else the subsequent validatePathParams wouldn't throw like I quoted above... mystifies me right now.
@metaleap
Copy link
Author

metaleap commented Nov 14, 2023

Full repro:

import (
	"reflect"
	"testing"

	"github.com/swaggest/jsonschema-go"
	"github.com/swaggest/openapi-go"
	"github.com/swaggest/openapi-go/openapi31"
)

type yodb_I64 int64
type None struct{}

func Test_Repro2(t *testing.T) {
	oarefl := openapi31.NewReflector()
	oarefl.Spec.Info.WithTitle("kaffe.local")
	oarefl.JSONSchemaReflector().DefaultOptions = append(oarefl.JSONSchemaReflector().DefaultOptions, jsonschema.ProcessWithoutTags)

	{
		var dummy_in struct{ Id yodb_I64 }
		var dummy_out None
		ty_args, ty_ret := reflect.TypeOf(dummy_in), reflect.TypeOf(dummy_out)
		op, err := oarefl.NewOperationContext("POST", "/_/postDelete")
		if err != nil {
			t.Fatal(err)
		}
		op.AddReqStructure(reflect.New(ty_args).Elem().Interface(), openapi.WithContentType("application/json"))
		op.AddRespStructure(reflect.New(ty_ret).Elem().Interface(), openapi.WithHTTPStatus(200))
		if err = oarefl.AddOperation(op); err != nil {
			t.Fatal(err)
		}
	}

	src_json, err := oarefl.Spec.MarshalJSON()
	if err != nil {
		t.Fatal(err)
	}
	t.Log(string(src_json))
}

@vearutop
Copy link
Member

vearutop commented Dec 4, 2023

This behavior is due to a default option jsonschema.ProcessWithoutTags that applies to all reflections, including path parameters. Please try v0.2.43 which adds initial tag-less JSON support by reverting jsonschema.ProcessWithoutTags for non-JSON cases.

@metaleap
Copy link
Author

metaleap commented Dec 4, 2023

Sound good but already way past my openapi.json TODO (or the need for any dependency for that functionality) — feel free to Close the Issue at your leisure =)

@vearutop vearutop closed this as completed Dec 4, 2023
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

2 participants