Closed chriskolenko closed 8 months ago
I tried to reproduce, but couldn't. Can you update the test below with more details, so that it panics?
package main_test
import (
"bytes"
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/swaggest/jsonschema-go"
"github.com/swaggest/openapi-go/openapi3"
"github.com/swaggest/rest/web"
"github.com/swaggest/usecase"
)
func TestFoo(t *testing.T) {
type NewThing struct {
ParentId *uuid.UUID `json:"parent_id" required:"false"`
}
s := web.NewService(openapi3.NewReflector())
// Create custom schema mapping for 3rd party type.
uuidDef := jsonschema.Schema{}
uuidDef.AddType(jsonschema.String)
uuidDef.WithFormat("uuid")
uuidDef.WithExamples("248df4b7-aa70-47b8-a036-33ac447e668d")
s.OpenAPICollector.Reflector().AddTypeMapping(uuid.UUID{}, uuidDef)
s.Post("/foo", usecase.NewInteractor(func(ctx context.Context, input NewThing, output *string) error {
if input.ParentId != nil {
*output = input.ParentId.String()
} else {
*output = "nil"
}
return nil
}))
req, err := http.NewRequest(http.MethodPost, "/foo", bytes.NewReader([]byte(`{"parent_id": "348df4b7-aa70-47b8-a036-33ac447e668d"}`)))
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
rw := httptest.NewRecorder()
s.ServeHTTP(rw, req)
assert.Equal(t, `"348df4b7-aa70-47b8-a036-33ac447e668d"
`, rw.Body.String())
}
I've added a check in openapi-go
v0.2.45
, but still would be interested to reproduce the bug.
Please feel free to reopen if the issue happens again.
Describe the bug
When using a
*uuid.UUID
type in a body request the Validator Middleware is panicing. (See stack trace below)It only happens with a pointer, when using
uuid.UUID
it works fine.This bug was introduced between: github.com/swaggest/openapi-go v0.2.44 => v0.2.43 ^^ found this after creating the bug might need to move this to the other repo?
To Reproduce Add a pointer to a uuid.UUID In my models I have
Expected behavior It shouldn't panic, and the field should not be validated.
Additional context