diff --git a/acceptance/petstore_test.go b/acceptance/petstore_test.go index ed6fafb19..a98b45f20 100644 --- a/acceptance/petstore_test.go +++ b/acceptance/petstore_test.go @@ -110,7 +110,7 @@ func (suite *PetStoreSuite) TestJsHttpHandler() { try.GetRequest(suite.T(), "http://127.0.0.1:18080/pet/4", map[string]string{"Accept": "application/json", "api_key": "123"}, try.HasStatusCode(http.StatusInternalServerError), - try.HasBody("encoding data to 'application/json' failed: error count 1:\n\t- #/required: required properties are missing: name, photoUrls\n")) + try.HasBody("HTTP body marshalling failed.\n\nBody: {}\n\nValidation error count 1:\n\t- #/required: required properties are missing: name, photoUrls\n")) // use generated data but change pet's name try.GetRequest(suite.T(), "http://127.0.0.1:18080/pet/5", diff --git a/api/handler_kafka_test.go b/api/handler_kafka_test.go index e09a3ccbf..399f98562 100644 --- a/api/handler_kafka_test.go +++ b/api/handler_kafka_test.go @@ -644,7 +644,7 @@ func TestHandler_KafkaAPI(t *testing.T) { { Partition: -1, Offset: -1, - Error: "no matching message configuration found for the given value: 123\nhint:\nencoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected string but got number\n", + Error: "Kafka message validation failed:\n\nMessage:\n123\n\nValidation error count 1:\n\t- #/type: invalid type, expected string but got number\n", }, }, }, data) @@ -929,7 +929,7 @@ func TestHandler_KafkaAPI(t *testing.T) { { Partition: -1, Offset: -1, - Error: "invalid message: error count 1:\n\t- #/additionalProperties: property 'yuh' not defined and the schema does not allow additional properties", + Error: "Validation error count 1:\n\t- #/additionalProperties: property 'yuh' not defined and the schema does not allow additional properties", }, }, }, data) diff --git a/engine/kafka.go b/engine/kafka.go index 0a4d9a59d..eb8e5376a 100644 --- a/engine/kafka.go +++ b/engine/kafka.go @@ -296,7 +296,7 @@ func selectMessage(value any, topic *asyncapi3.Channel, cfg *asyncapi3.Config) ( } } if validationErr != nil { - return nil, fmt.Errorf("no matching message configuration found for the given value: %v\nhint:\n%w\n", value, validationErr) + return nil, fmt.Errorf("Kafka message validation failed:\n\nMessage:\n%v\n\n%s\n", value, validationErr) } return nil, nil } diff --git a/engine/kafka_test.go b/engine/kafka_test.go index 96c838ba3..db81c1c5c 100644 --- a/engine/kafka_test.go +++ b/engine/kafka_test.go @@ -507,7 +507,7 @@ func TestKafkaClient(t *testing.T) { produce({ topic: 'foo', messages: [{ data: 12 }] }) } `)) - require.EqualError(t, err, "failed to produce message to Kafka topic 'foo': no matching message configuration found for the given value: 12\nhint:\nencoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected string but got integer\n at mokapi/js/kafka.(*Module).Produce-fm (native)") + require.EqualError(t, err, "failed to produce message to Kafka topic 'foo': Kafka message validation failed:\n\nMessage:\n12\n\nValidation error count 1:\n\t- #/type: invalid type, expected string but got integer\n at mokapi/js/kafka.(*Module).Produce-fm (native)") b, errCode := app.Kafka.Get("foo").Store.Topic("foo").Partition(0).Read(0, 1000) require.Equal(t, kafka.None, errCode) @@ -516,7 +516,7 @@ func TestKafkaClient(t *testing.T) { // logs require.Len(t, hook.Entries, 2) - require.Equal(t, "js error: failed to produce message to Kafka topic 'foo': no matching message configuration found for the given value: 12\nhint:\nencoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected string but got integer\n in test.js", hook.LastEntry().Message) + require.Equal(t, "js error: failed to produce message to Kafka topic 'foo': Kafka message validation failed:\n\nMessage:\n12\n\nValidation error count 1:\n\t- #/type: invalid type, expected string but got integer\n in test.js", hook.LastEntry().Message) }, }, { @@ -734,7 +734,7 @@ func TestKafkaClient(t *testing.T) { produce({ messages: [{ data: { foo: 'bar' } }] }) } `)) - require.EqualError(t, err, "failed to produce message to Kafka topic 'foo': no matching message configuration found for the given value: {\"foo\":\"bar\"}\nhint:\nencoding data to 'application/xml' failed: error count 1:\n\t- #/required: required properties are missing: id\n at mokapi/js/kafka.(*Module).Produce-fm (native)") + require.EqualError(t, err, "failed to produce message to Kafka topic 'foo': Kafka message validation failed:\n\nMessage:\n{\"foo\":\"bar\"}\n\nValidation error count 1:\n\t- #/required: required properties are missing: id\n at mokapi/js/kafka.(*Module).Produce-fm (native)") }, }, { diff --git a/go.mod b/go.mod index 48f49cd9d..11af53e41 100644 --- a/go.mod +++ b/go.mod @@ -22,8 +22,8 @@ require ( github.com/sirupsen/logrus v1.9.4 github.com/stretchr/testify v1.11.1 github.com/yuin/gopher-lua v1.1.2 - golang.org/x/net v0.53.0 - golang.org/x/text v0.36.0 + golang.org/x/net v0.54.0 + golang.org/x/text v0.37.0 gopkg.in/go-asn1-ber/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d gopkg.in/yaml.v3 v3.0.1 layeh.com/gopher-luar v1.0.11 @@ -88,9 +88,9 @@ require ( github.com/yosida95/uritemplate/v3 v3.0.2 // indirect go.etcd.io/bbolt v1.4.0 // indirect go.uber.org/atomic v1.9.0 // indirect - golang.org/x/crypto v0.50.0 // indirect + golang.org/x/crypto v0.51.0 // indirect golang.org/x/oauth2 v0.35.0 // indirect - golang.org/x/sys v0.43.0 // indirect + golang.org/x/sys v0.44.0 // indirect google.golang.org/protobuf v1.36.6 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum index 2a18f6454..ee68bb7c2 100644 --- a/go.sum +++ b/go.sum @@ -206,13 +206,13 @@ go.etcd.io/bbolt v1.4.0/go.mod h1:AsD+OCi/qPN1giOX1aiLAha3o1U8rAz65bvN4j0sRuk= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI= -golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q= +golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI= +golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8= golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f h1:W3F4c+6OLc6H2lb//N1q4WpJkhzJCK5J6kUi1NTVXfM= golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f/go.mod h1:J1xhfL/vlindoeF/aINzNzt2Bket5bjo9sdOYzOsU80= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA= -golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs= +golang.org/x/net v0.54.0 h1:2zJIZAxAHV/OHCDTCOHAYehQzLfSXuf/5SoL/Dv6w/w= +golang.org/x/net v0.54.0/go.mod h1:Sj4oj8jK6XmHpBZU/zWHw3BV3abl4Kvi+Ut7cQcY+cQ= golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ= golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= @@ -224,17 +224,17 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI= -golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ= +golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.42.0 h1:UiKe+zDFmJobeJ5ggPwOshJIVt6/Ft0rcfrXZDLWAWY= -golang.org/x/term v0.42.0/go.mod h1:Dq/D+snpsbazcBG5+F9Q1n2rXV8Ma+71xEjTRufARgY= +golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4= +golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg= -golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164= +golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= +golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s= -golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0= +golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c= +golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI= google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/js/mokapi/mokapi_test.go b/js/mokapi/mokapi_test.go index af0629d30..d53b22cd7 100644 --- a/js/mokapi/mokapi_test.go +++ b/js/mokapi/mokapi_test.go @@ -142,7 +142,7 @@ func TestModule(t *testing.T) { const m = require('mokapi') m.marshal('foo', { schema: {type: 'integer'}, contentType: 'application/json' }) `) - r.EqualError(t, err, "encoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected integer but got string at mokapi/js/mokapi.(*Module).Marshal-fm (native)") + r.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got string at mokapi/js/mokapi.(*Module).Marshal-fm (native)") }, }, { diff --git a/lib/type.go b/lib/type.go index e2b1651ce..0d78e8b6d 100644 --- a/lib/type.go +++ b/lib/type.go @@ -1,6 +1,12 @@ package lib -import "reflect" +import ( + "encoding/json" + "fmt" + "reflect" + + log "github.com/sirupsen/logrus" +) func TypeFrom(v interface{}) string { return TypeString(reflect.TypeOf(v)) @@ -26,3 +32,18 @@ func TypeString(t reflect.Type) string { return "Unknown" } } + +func PrettyPrint(v any) string { + if v == nil { + return "" + } + if s, ok := v.(string); ok { + return s + } + b, err := json.MarshalIndent(v, "", " ") + if err == nil { + return string(b) + } + log.Warnf("failed to pretty print %#v: %v", v, err) + return fmt.Sprintf("%v", v) +} diff --git a/mcp/data/automation-core.md b/mcp/data/automation-core.md index 55b15d81b..415941e4e 100644 --- a/mcp/data/automation-core.md +++ b/mcp/data/automation-core.md @@ -20,7 +20,7 @@ interface Mokapi { * @example * getApi('Swagger Petstore') */ - getApi(name: string): OpenApi | Kafka; + getApi(name: string): Http | Kafka; /** * Generate a random value from a JSON Schema. @@ -54,8 +54,20 @@ interface Mokapi { getEvent(id: string): Event[]; /** - * Advanced Search across all APIs, Topics, and Documentation. - * By default, multiple terms are combined with OR (results contain at least one term). Use prefixes to enforce stricter matches. + * Advanced search across all APIs, topics, documentation, events and logs. + * + * Search behavior: + * - Multiple search terms are combined with OR by default + * Example: "pet booking" + * → matches results containing either "pet" OR "booking" + * + * Prefix a term with '+' to require that term to match. + * Example: "+pet booking" + * → matches results containing "pet" AND optionally "booking" + * + * Multiple '+' terms are combined with AND. + * Example: "+pet +booking" + * → matches results containing both "pet" AND "booking" * * QUERY SYNTAX: * - Simple: `petstore` (Search in all fields) @@ -94,6 +106,8 @@ interface SearchResultItem { domain: string /** A human-readable title or summary */ title: string + /** A human-readable description */ + description: string /** * Relevant text snippets showing where the match was found. * Useful to see context like 'GET /pets' or 'Topic: orders'. diff --git a/mcp/data/automation-kafka.md b/mcp/data/automation-kafka.md index d57d5ff1a..748ad5888 100644 --- a/mcp/data/automation-kafka.md +++ b/mcp/data/automation-kafka.md @@ -73,6 +73,10 @@ interface KafkaMessage { summary: string description: string contentType: string + /** + * JSON schema describing the Kafka message payload. + * Use fake(payload) to generate valid example data. + */ payload: Schema; key: Schema headers?: Schema; diff --git a/mcp/run.go b/mcp/run.go index 649d780cc..f44c2282c 100644 --- a/mcp/run.go +++ b/mcp/run.go @@ -193,12 +193,13 @@ type SearchResult struct { } type SearchResultItem struct { - Type string `json:"type"` - Domain string `json:"domain,omitempty"` - Title string `json:"title"` - Fragments []string `json:"fragments,omitempty"` - Metadata map[string]string `json:"metadata"` - Time string `json:"time,omitempty"` + Type string `json:"type"` + Domain string `json:"domain,omitempty"` + Title string `json:"title"` + Description string `json:"description"` + Fragments []string `json:"fragments,omitempty"` + Metadata map[string]string `json:"metadata"` + Time string `json:"time,omitempty"` } func (m *mokapi) search(queryText string, index int, limit int) (SearchResult, error) { @@ -220,12 +221,13 @@ func (m *mokapi) search(queryText string, index int, limit int) (SearchResult, e } for _, item := range sr.Results { result.Items = append(result.Items, SearchResultItem{ - Type: item.Type, - Domain: item.Domain, - Title: item.Title, - Fragments: item.Fragments, - Metadata: item.Params, - Time: item.Time, + Type: item.Type, + Domain: item.Domain, + Title: item.Title, + Description: item.Description, + Fragments: item.Fragments, + Metadata: item.Params, + Time: item.Time, }) } return result, nil diff --git a/mcp/run_kafka.go b/mcp/run_kafka.go index 511a27305..58c897c81 100644 --- a/mcp/run_kafka.go +++ b/mcp/run_kafka.go @@ -1,10 +1,10 @@ package mcp import ( - "errors" "fmt" "mokapi/kafka" "mokapi/media" + "mokapi/providers/asyncapi3" "mokapi/providers/asyncapi3/kafka/store" "mokapi/runtime" "slices" @@ -165,25 +165,20 @@ func (k *Kafka) GetTopic(name string) (Topic, error) { Description: op.Value.Description, } - for _, msg := range op.Value.Messages { - if msg.Value == nil { - continue - } - m := KafkaMessage{ - Name: msg.Value.Name, - Title: msg.Value.Title, - Summary: msg.Value.Summary, - Description: msg.Value.Description, - ContentType: msg.Value.ContentType, - Headers: msg.Value.Headers, - } - if msg.Value.Payload != nil { - m.Payload = msg.Value.Payload.Value + if len(op.Value.Messages) > 0 { + for _, msg := range op.Value.Messages { + if msg.Value == nil { + continue + } + result.Messages = append(result.Messages, getKafkaMessages(msg)) } - if msg.Value.Bindings.Kafka.Key != nil { - m.Key = msg.Value.Bindings.Kafka.Key + } else { + for _, msg := range ch.Value.Messages { + if msg.Value == nil { + continue + } + result.Messages = append(result.Messages, getKafkaMessages(msg)) } - result.Messages = append(result.Messages, m) } t.Operations = append(t.Operations, result) @@ -220,7 +215,7 @@ func (t *Topic) Produce(partition int, value any, key string, headers map[string } if len(result) > 0 && result[0].Error != "" { - return errors.New(result[0].Error) + return fmt.Errorf("%s\nTo create a valid payload:\n1. Select a message from operation.messages\n2. Generate example data:\n\n const value = mokapi.fake(message.payload)\n\n3. Modify only the required fields if needed.", result[0].Error) } // update JS topic and partition @@ -289,3 +284,21 @@ func (t *Topic) Consume(partition int, startOffset int64, limit int) ([]KafkaRec } } } + +func getKafkaMessages(msg *asyncapi3.MessageRef) KafkaMessage { + m := KafkaMessage{ + Name: msg.Value.Name, + Title: msg.Value.Title, + Summary: msg.Value.Summary, + Description: msg.Value.Description, + ContentType: msg.Value.ContentType, + Headers: msg.Value.Headers, + } + if msg.Value.Payload != nil { + m.Payload = msg.Value.Payload.Value + } + if msg.Value.Bindings.Kafka.Key != nil { + m.Key = msg.Value.Bindings.Kafka.Key + } + return m +} diff --git a/mcp/run_kafka_test.go b/mcp/run_kafka_test.go index f0b42d53c..fc1b67230 100644 --- a/mcp/run_kafka_test.go +++ b/mcp/run_kafka_test.go @@ -185,6 +185,74 @@ func TestService_Run_Kafka(t *testing.T) { require.Equal(t, "object", payload.Type.String()) }, }, + { + name: "get topic operation does not define any message", + app: func() *runtime.App { + msg := asyncapi3test.NewMessage( + asyncapi3test.WithMessageName("msg-name-1"), + asyncapi3test.WithMessageTitle("msg-title-1"), + asyncapi3test.WithMessageSummary("msg-summary-1"), + asyncapi3test.WithMessageDescription("msg-description-1"), + asyncapi3test.WithContentType("application/json"), + asyncapi3test.WithPayload( + schematest.New("object", + schematest.WithProperty("foo", schematest.New("string")), + ), + ), + ) + + ch := asyncapi3test.NewChannel( + asyncapi3test.WithChannelTitle("title-1"), + asyncapi3test.WithChannelSummary("channel-1 summary"), + asyncapi3test.WithChannelDescription("description"), + asyncapi3test.UseMessage("foo", &asyncapi3.MessageRef{Value: msg}), + ) + + return runtimetest.NewKafkaApp( + asyncapi3test.NewConfig( + asyncapi3test.WithInfo("foo", "", ""), + asyncapi3test.AddChannel("channel-1", ch), + asyncapi3test.WithOperation("publish", + asyncapi3test.WithOperationAction("send"), + asyncapi3test.WithOperationTitle("op-title-1"), + asyncapi3test.WithOperationSummary("op-summary-1"), + asyncapi3test.WithOperationDescription("op-description-1"), + asyncapi3test.WithOperationChannel(ch), + ), + ), + ) + }(), + test: func(t *testing.T, s *mcp.Service) { + r, err := s.GetRunResponse( + context.Background(), + mcp.RunInput{ + Code: `mokapi.getApi('foo').getTopic('channel-1')`, + }, + ) + require.NoError(t, err) + require.IsType(t, mcp.Topic{}, r.Result) + topic := r.Result.(mcp.Topic) + require.Equal(t, "channel-1", topic.Name) + require.Equal(t, "title-1", topic.Title) + require.Equal(t, "channel-1 summary", topic.Summary) + require.Equal(t, "description", topic.Description) + require.Len(t, topic.Operations, 1) + + require.Equal(t, "send", topic.Operations[0].Action) + require.Equal(t, "op-title-1", topic.Operations[0].Title) + require.Equal(t, "op-summary-1", topic.Operations[0].Summary) + require.Equal(t, "op-description-1", topic.Operations[0].Description) + require.Len(t, topic.Operations[0].Messages, 1) + require.Equal(t, "msg-name-1", topic.Operations[0].Messages[0].Name) + require.Equal(t, "msg-title-1", topic.Operations[0].Messages[0].Title) + require.Equal(t, "msg-summary-1", topic.Operations[0].Messages[0].Summary) + require.Equal(t, "msg-description-1", topic.Operations[0].Messages[0].Description) + require.Equal(t, "application/json", topic.Operations[0].Messages[0].ContentType) + require.IsType(t, &jsonSchema.Schema{}, topic.Operations[0].Messages[0].Payload) + payload := topic.Operations[0].Messages[0].Payload.(*jsonSchema.Schema) + require.Equal(t, "object", payload.Type.String()) + }, + }, { name: "consume from topic", app: func() *runtime.App { @@ -393,11 +461,21 @@ t.produce(0, { foo: 123 }, 'foo'); t`, }, ) - require.EqualError(t, err, `no matching message configuration found for the given value: {"foo":123} -hint: -encoding data to 'application/json' failed: error count 1: + require.EqualError(t, err, `Kafka message validation failed: + +Message: +{"foo":123} + +Validation error count 1: - #/foo/type: invalid type, expected string but got integer -`) + +To create a valid payload: +1. Select a message from operation.messages +2. Generate example data: + + const value = mokapi.fake(message.payload) + +3. Modify only the required fields if needed.`) }, }, } diff --git a/mcp/run_test.go b/mcp/run_test.go index 1a9e94207..89925a522 100644 --- a/mcp/run_test.go +++ b/mcp/run_test.go @@ -151,12 +151,13 @@ func TestService_Run_Search(t *testing.T) { require.NoError(t, err) require.Equal(t, mcp.SearchResult{Items: []mcp.SearchResultItem{ { - Type: "HTTP", - Domain: "foo", - Title: "/foo/payment/bar", - Fragments: []string{"POST"}, - Metadata: map[string]string{"method": "POST", "path": "/foo/payment/bar", "service": "foo", "type": "http"}, - Time: "", + Type: "HTTP", + Domain: "foo", + Title: "/foo/payment/bar", + Description: "Payment summary", + Fragments: []string{"POST"}, + Metadata: map[string]string{"method": "POST", "path": "/foo/payment/bar", "service": "foo", "type": "http"}, + Time: "", }}, Total: 1}, r.Result) r, err = s.GetRunResponse( diff --git a/providers/asyncapi3/kafka/store/client.go b/providers/asyncapi3/kafka/store/client.go index 92d10afae..739ae5b4f 100644 --- a/providers/asyncapi3/kafka/store/client.go +++ b/providers/asyncapi3/kafka/store/client.go @@ -447,7 +447,7 @@ func selectMessage(value any, topic *asyncapi3.Channel) (*asyncapi3.Message, err } } if validationErr != nil { - return nil, fmt.Errorf("no matching message configuration found for the given value: %v\nhint:\n%w\n", value, validationErr) + return nil, fmt.Errorf("Kafka message validation failed:\n\nMessage:\n%v\n\n%w\n", value, validationErr) } return nil, nil } diff --git a/providers/asyncapi3/kafka/store/offset_commit_test.go b/providers/asyncapi3/kafka/store/offset_commit_test.go index eaf1d7532..1e007a552 100644 --- a/providers/asyncapi3/kafka/store/offset_commit_test.go +++ b/providers/asyncapi3/kafka/store/offset_commit_test.go @@ -239,7 +239,7 @@ func TestOffsetCommit_Validation(t *testing.T) { require.Equal(t, 7, len(hook.Entries), hook.Entries) require.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level) - require.Equal(t, "kafka OffsetCommit: invalid consumer 'kafkatest' for topic foo: invalid clientId: error count 1:\n\t- #/pattern: string 'kafkatest' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) + require.Equal(t, "kafka OffsetCommit: invalid consumer 'kafkatest' for topic foo: invalid clientId: Validation error count 1:\n\t- #/pattern: string 'kafkatest' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) }, }, { @@ -280,7 +280,7 @@ func TestOffsetCommit_Validation(t *testing.T) { require.Equal(t, 7, len(hook.Entries)) require.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level) - require.Equal(t, "kafka OffsetCommit: invalid consumer 'kafkatest' for topic foo: invalid groupId: error count 1:\n\t- #/pattern: string 'bar' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) + require.Equal(t, "kafka OffsetCommit: invalid consumer 'kafkatest' for topic foo: invalid groupId: Validation error count 1:\n\t- #/pattern: string 'bar' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) }, }, { diff --git a/providers/asyncapi3/kafka/store/offset_fetch_test.go b/providers/asyncapi3/kafka/store/offset_fetch_test.go index 0037ad019..487c547cf 100644 --- a/providers/asyncapi3/kafka/store/offset_fetch_test.go +++ b/providers/asyncapi3/kafka/store/offset_fetch_test.go @@ -359,7 +359,7 @@ func TestOffsetFetch_Validation(t *testing.T) { require.Equal(t, 6, len(hook.Entries)) require.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level) - require.Equal(t, "kafka OffsetFetch: invalid consumer 'kafkatest' for topic foo: invalid clientId: error count 1:\n\t- #/pattern: string 'kafkatest' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) + require.Equal(t, "kafka OffsetFetch: invalid consumer 'kafkatest' for topic foo: invalid clientId: Validation error count 1:\n\t- #/pattern: string 'kafkatest' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) }, }, { @@ -400,7 +400,7 @@ func TestOffsetFetch_Validation(t *testing.T) { require.Equal(t, 6, len(hook.Entries)) require.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level) - require.Equal(t, "kafka OffsetFetch: invalid consumer 'kafkatest' for topic foo: invalid groupId: error count 1:\n\t- #/pattern: string 'bar' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) + require.Equal(t, "kafka OffsetFetch: invalid consumer 'kafkatest' for topic foo: invalid groupId: Validation error count 1:\n\t- #/pattern: string 'bar' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) }, }, { diff --git a/providers/asyncapi3/kafka/store/partition_test.go b/providers/asyncapi3/kafka/store/partition_test.go index cad87a87a..2526c21cf 100644 --- a/providers/asyncapi3/kafka/store/partition_test.go +++ b/providers/asyncapi3/kafka/store/partition_test.go @@ -186,7 +186,7 @@ func TestPartition_Write_Value_Validator(t *testing.T) { require.NoError(t, err) require.Len(t, wr.Records, 1) require.Equal(t, int32(0), wr.Records[0].BatchIndex) - require.Equal(t, "invalid message: error count 1:\n\t- #/type: invalid type, expected string but got number", wr.Records[0].BatchIndexErrorMessage) + require.Equal(t, "Validation error count 1:\n\t- #/type: invalid type, expected string but got number", wr.Records[0].BatchIndexErrorMessage) require.Equal(t, int64(0), wr.BaseOffset) require.Equal(t, int64(0), p.Offset()) require.Equal(t, int64(0), p.StartOffset()) diff --git a/providers/asyncapi3/kafka/store/produce_test.go b/providers/asyncapi3/kafka/store/produce_test.go index 8cf6dbbab..324a30e15 100644 --- a/providers/asyncapi3/kafka/store/produce_test.go +++ b/providers/asyncapi3/kafka/store/produce_test.go @@ -218,7 +218,7 @@ func TestProduce(t *testing.T) { require.True(t, ok) require.Equal(t, "foo", res.Topics[0].Name) require.Equal(t, kafka.InvalidRecord, res.Topics[0].Partitions[0].ErrorCode) - require.Equal(t, "invalid message: error count 1:\n\t- #/type: invalid type, expected integer but got string", res.Topics[0].Partitions[0].ErrorMessage) + require.Equal(t, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got string", res.Topics[0].Partitions[0].ErrorMessage) require.Equal(t, int64(0), res.Topics[0].Partitions[0].BaseOffset) }, }, @@ -267,11 +267,11 @@ func TestProduce(t *testing.T) { require.Equal(t, "foo", res.Topics[0].Name) require.Equal(t, kafka.UnknownServerError, res.Topics[0].Partitions[0].ErrorCode, "expected kafka error UnknownServerError") require.Equal(t, int64(0), res.Topics[0].Partitions[0].BaseOffset) - require.Equal(t, "invalid producer clientId 'kafkatest' for topic foo: error count 1:\n\t- #/pattern: string 'kafkatest' does not match regex pattern '^[A-Z]{10}[0-5]$'", res.Topics[0].Partitions[0].ErrorMessage) + require.Equal(t, "invalid producer clientId 'kafkatest' for topic foo: Validation error count 1:\n\t- #/pattern: string 'kafkatest' does not match regex pattern '^[A-Z]{10}[0-5]$'", res.Topics[0].Partitions[0].ErrorMessage) require.Equal(t, 1, len(hook.Entries)) require.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level) - require.Equal(t, "kafka: failed to write to topic 'foo': invalid producer clientId 'kafkatest' for topic foo: error count 1:\n\t- #/pattern: string 'kafkatest' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) + require.Equal(t, "kafka: failed to write to topic 'foo': invalid producer clientId 'kafkatest' for topic foo: Validation error count 1:\n\t- #/pattern: string 'kafkatest' does not match regex pattern '^[A-Z]{10}[0-5]$'", hook.LastEntry().Message) }, }, { diff --git a/providers/asyncapi3/kafka/store/store_test.go b/providers/asyncapi3/kafka/store/store_test.go index 23dea9e47..84b1bbd44 100644 --- a/providers/asyncapi3/kafka/store/store_test.go +++ b/providers/asyncapi3/kafka/store/store_test.go @@ -133,7 +133,7 @@ func TestStore(t *testing.T) { }}, ) require.NoError(t, err) - require.Equal(t, "invalid message: error count 1:\n\t- #/type: invalid type, expected string but got number", wr.Records[0].BatchIndexErrorMessage) + require.Equal(t, "Validation error count 1:\n\t- #/type: invalid type, expected string but got number", wr.Records[0].BatchIndexErrorMessage) }, }, } diff --git a/providers/asyncapi3/kafka/store/validation.go b/providers/asyncapi3/kafka/store/validation.go index 624faf899..d5afc61db 100644 --- a/providers/asyncapi3/kafka/store/validation.go +++ b/providers/asyncapi3/kafka/store/validation.go @@ -142,7 +142,6 @@ func (mv *messageValidator) Validate(record *kafka.Record) (*KafkaMessageLog, er if mv.payload != nil { if _, err := mv.payload.Validate(record.Value); err != nil { - err = fmt.Errorf("invalid message: %w", err) return r, err } else { b := kafka.Read(record.Value) diff --git a/providers/asyncapi3/kafka/store/validation_test.go b/providers/asyncapi3/kafka/store/validation_test.go index 0473bd7d1..787870430 100644 --- a/providers/asyncapi3/kafka/store/validation_test.go +++ b/providers/asyncapi3/kafka/store/validation_test.go @@ -103,7 +103,7 @@ func TestValidation(t *testing.T) { }, }) require.NoError(t, err) - require.Equal(t, "invalid message: error count 1:\n\t- #/type: invalid type, expected string but got number", wr.Records[0].BatchIndexErrorMessage) + require.Equal(t, "Validation error count 1:\n\t- #/type: invalid type, expected string but got number", wr.Records[0].BatchIndexErrorMessage) require.Len(t, wr.Records, 1) }, }, @@ -222,7 +222,7 @@ func TestValidation(t *testing.T) { }, }) require.NoError(t, err) - require.Equal(t, "invalid key: error count 1:\n\t- #/minimum: integer 64 is less than minimum value of 100", wr.Records[0].BatchIndexErrorMessage) + require.Equal(t, "invalid key: Validation error count 1:\n\t- #/minimum: integer 64 is less than minimum value of 100", wr.Records[0].BatchIndexErrorMessage) require.Len(t, wr.Records, 1) }, }, @@ -285,7 +285,7 @@ func TestValidation(t *testing.T) { }) require.NoError(t, err) require.Len(t, wr.Records, 1) - require.Equal(t, "invalid message: error count 1:\n\t- #/required: required properties are missing: bar", wr.Records[0].BatchIndexErrorMessage) + require.Equal(t, "Validation error count 1:\n\t- #/required: required properties are missing: bar", wr.Records[0].BatchIndexErrorMessage) }, }, } diff --git a/providers/openapi/handler.go b/providers/openapi/handler.go index 5cee41d0d..7a04fc98b 100644 --- a/providers/openapi/handler.go +++ b/providers/openapi/handler.go @@ -235,6 +235,7 @@ func (h *responseHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { } else { body, err = mediaType.Schema.Marshal(response.Data, contentType) if err != nil { + err = fmt.Errorf("HTTP body marshalling failed.\n\nBody: %v\n\n%w", lib.PrettyPrint(response.Data), err) writeError(rw, r, err, h.config.Info.Name) return } diff --git a/providers/openapi/handler_response_test.go b/providers/openapi/handler_response_test.go index ea9e9adf2..b3f2992d9 100644 --- a/providers/openapi/handler_response_test.go +++ b/providers/openapi/handler_response_test.go @@ -61,7 +61,7 @@ func TestHandler_Response(t *testing.T) { }, test: func(t *testing.T, rr *httptest.ResponseRecorder, eh events.Handler) { require.Equal(t, http.StatusInternalServerError, rr.Code) - require.Equal(t, "encoding data to 'application/json' failed: error count 1:\n\t- #/format: string 'foo' does not match format 'date'\n", rr.Body.String()) + require.Equal(t, "HTTP body marshalling failed.\n\nBody: foo\n\nValidation error count 1:\n\t- #/format: string 'foo' does not match format 'date'\n", rr.Body.String()) }, }, { @@ -118,7 +118,7 @@ func TestHandler_Response(t *testing.T) { }, test: func(t *testing.T, rr *httptest.ResponseRecorder, eh events.Handler) { require.Equal(t, http.StatusInternalServerError, rr.Code) - require.Equal(t, "encoding data to 'application/octet-stream' failed: not supported encoding of content types 'application/octet-stream', except simple data types\n", rr.Body.String()) + require.Equal(t, "HTTP body marshalling failed.\n\nBody: {\n \"foo\": \"bar\"\n}\n\nnot supported encoding of content types 'application/octet-stream', except simple data types\n", rr.Body.String()) }, }, { diff --git a/providers/openapi/handler_test.go b/providers/openapi/handler_test.go index fdadf7de6..f28866b43 100644 --- a/providers/openapi/handler_test.go +++ b/providers/openapi/handler_test.go @@ -279,7 +279,7 @@ func TestResolveEndpoint(t *testing.T) { rr := httptest.NewRecorder() h(rr, r) require.Equal(t, 500, rr.Code) - require.Equal(t, "read request body 'application/json' failed: error count 1:\n\t- #/minLength: string 'foo' is less than minimum of 4\n", rr.Body.String()) + require.Equal(t, "read request body 'application/json' failed: Validation error count 1:\n\t- #/minLength: string 'foo' is less than minimum of 4\n", rr.Body.String()) }, }, // @@ -1166,7 +1166,7 @@ func TestHandler_Event(t *testing.T) { rr := httptest.NewRecorder() h(rr, r) require.Equal(t, http.StatusInternalServerError, rr.Code) - require.Equal(t, "invalid header 'foo': error count 1:\n\t- expected array but got: bar\n", rr.Body.String()) + require.Equal(t, "invalid header 'foo': Validation error count 1:\n\t- expected array but got: bar\n", rr.Body.String()) }, event: func(event string, args ...interface{}) []*common.Action { res := args[1].(*common.HttpEventResponse) diff --git a/providers/openapi/media_type_parse_test.go b/providers/openapi/media_type_parse_test.go index 5f0ebc800..9e62618ac 100644 --- a/providers/openapi/media_type_parse_test.go +++ b/providers/openapi/media_type_parse_test.go @@ -103,7 +103,7 @@ func TestRef_Unmarshal_Json(t *testing.T) { data: `{ "foo": null }`, schema: schematest.New("object", schematest.WithProperty("foo", schematest.New("string"))), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/foo/type: invalid type, expected string but got null") + require.EqualError(t, err, "Validation error count 1:\n\t- #/foo/type: invalid type, expected string but got null") }, }, { @@ -129,7 +129,7 @@ func TestRef_Unmarshal_Json(t *testing.T) { schema: schematest.New("string", schematest.And("number")), data: `true`, test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected number but got boolean") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected number but got boolean") }, }, } @@ -173,7 +173,7 @@ func TestRef_Unmarshal_Json_Any(t *testing.T) { schematest.New("string"), schematest.New("integer"))), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/anyOf: does not match any schemas") + require.EqualError(t, err, "Validation error count 1:\n\t- #/anyOf: does not match any schemas") }, }, { @@ -272,7 +272,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `12`, schema: schematest.New("string"), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected string but got number") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected string but got number") }, }, { @@ -307,7 +307,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"013-64-59943"`, schema: schematest.New("string", schematest.WithPattern("^\\d{3}-\\d{2}-\\d{4}$")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/pattern: string '013-64-59943' does not match regex pattern '^\\d{3}-\\d{2}-\\d{4}$'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/pattern: string '013-64-59943' does not match regex pattern '^\\d{3}-\\d{2}-\\d{4}$'") }, }, { @@ -324,7 +324,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"1908-12-7"`, schema: schematest.New("string", schematest.WithFormat("date")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string '1908-12-7' does not match format 'date'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string '1908-12-7' does not match format 'date'") }, }, { @@ -341,7 +341,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"1908-12-07 T04:14:25Z"`, schema: schematest.New("string", schematest.WithFormat("date-time")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string '1908-12-07 T04:14:25Z' does not match format 'date-time'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string '1908-12-07 T04:14:25Z' does not match format 'date-time'") }, }, { @@ -367,7 +367,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"markusmoen@@pagac.net"`, schema: schematest.New("string", schematest.WithFormat("email")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'markusmoen@@pagac.net' does not match format 'email'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'markusmoen@@pagac.net' does not match format 'email'") }, }, { @@ -384,7 +384,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"590c1440-9888-45b0-bd51-a817ee07c3f2a"`, schema: schematest.New("string", schematest.WithFormat("uuid")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string '590c1440-9888-45b0-bd51-a817ee07c3f2a' does not match format 'uuid'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string '590c1440-9888-45b0-bd51-a817ee07c3f2a' does not match format 'uuid'") }, }, { @@ -401,7 +401,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"152.23.53.100."`, schema: schematest.New("string", schematest.WithFormat("ipv4")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string '152.23.53.100.' does not match format 'ipv4'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string '152.23.53.100.' does not match format 'ipv4'") }, }, { @@ -418,7 +418,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"-8898:ee17:bc35:9064:5866:d019:3b95:7857"`, schema: schematest.New("string", schematest.WithFormat("ipv6")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string '-8898:ee17:bc35:9064:5866:d019:3b95:7857' does not match format 'ipv6'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string '-8898:ee17:bc35:9064:5866:d019:3b95:7857' does not match format 'ipv6'") }, }, { @@ -426,7 +426,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"foo"`, schema: schematest.New("string", schematest.WithMinLength(4)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minLength: string 'foo' is less than minimum of 4") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minLength: string 'foo' is less than minimum of 4") }, }, { @@ -443,7 +443,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"foo"`, schema: schematest.New("string", schematest.WithMaxLength(2)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxLength: string 'foo' exceeds maximum of 2") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxLength: string 'foo' exceeds maximum of 2") }, }, { @@ -469,7 +469,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: `"foo"`, schema: schematest.New("string", schematest.WithEnumValues("bar")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value 'foo' does not match one in the enumeration [bar]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value 'foo' does not match one in the enumeration [bar]") }, }, { @@ -495,7 +495,7 @@ func TestRef_Unmarshal_Json_String(t *testing.T) { s: "123", schema: schematest.New("string", schematest.IsNullable(true)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected [string, null] but got number") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected [string, null] but got number") }, }, } @@ -544,7 +544,7 @@ func TestRef_Unmarshal_Json_OneOf(t *testing.T) { schematest.WithProperty("bar", schematest.New("boolean"))), ), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/oneOf/1/bar/type: invalid type, expected boolean but got number") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf/1/bar/type: invalid type, expected boolean but got number") }, }, { @@ -557,7 +557,7 @@ func TestRef_Unmarshal_Json_OneOf(t *testing.T) { schematest.WithProperty("foo", schematest.New("number"))), ), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") }, }, } @@ -605,7 +605,7 @@ func TestRef_Unmarshal_Json_AllOf(t *testing.T) { schematest.WithProperty("bar", schematest.New("boolean"))), )), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/required: required properties are missing: bar") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/required: required properties are missing: bar") }, }, } @@ -646,7 +646,7 @@ func TestRef_Unmarshal_Json_Integer(t *testing.T) { s: "3.61", schema: schematest.New("integer", schematest.WithFormat("int32")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected integer but got number") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got number") }, }, { @@ -654,7 +654,7 @@ func TestRef_Unmarshal_Json_Integer(t *testing.T) { s: fmt.Sprintf("%v", math.MaxInt64), schema: schematest.New("integer", schematest.WithFormat("int32")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: integer '9.223372036854776e+18' does not match format 'int32'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: integer '9.223372036854776e+18' does not match format 'int32'") }, }, { @@ -671,7 +671,7 @@ func TestRef_Unmarshal_Json_Integer(t *testing.T) { s: "12", schema: schematest.New("integer", schematest.WithMinimum(13)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minimum: integer 12 is less than minimum value of 13") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minimum: integer 12 is less than minimum value of 13") }, }, { @@ -679,7 +679,7 @@ func TestRef_Unmarshal_Json_Integer(t *testing.T) { s: "12", schema: &schema.Schema{Type: jsonSchema.Types{"integer"}, Minimum: toFloatP(12), ExclusiveMinimum: jsonSchema.NewUnionTypeB[float64, bool](true)}, test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minimum: integer 12 equals minimum value of 12 and exclusive minimum is true") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minimum: integer 12 equals minimum value of 12 and exclusive minimum is true") }, }, { @@ -696,7 +696,7 @@ func TestRef_Unmarshal_Json_Integer(t *testing.T) { s: "12", schema: &schema.Schema{Type: jsonSchema.Types{"integer"}, ExclusiveMinimum: jsonSchema.NewUnionTypeA[float64, bool](12)}, test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMinimum: integer 12 equals minimum value of 12") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMinimum: integer 12 equals minimum value of 12") }, }, { @@ -722,7 +722,7 @@ func TestRef_Unmarshal_Json_Integer(t *testing.T) { s: "12", schema: schematest.New("integer", schematest.WithMaximum(11)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: integer 12 exceeds maximum value of 11") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: integer 12 exceeds maximum value of 11") }, }, { @@ -730,7 +730,7 @@ func TestRef_Unmarshal_Json_Integer(t *testing.T) { s: "12", schema: &schema.Schema{Type: jsonSchema.Types{"integer"}, Maximum: toFloatP(12), ExclusiveMaximum: jsonSchema.NewUnionTypeB[float64, bool](true)}, test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: integer 12 equals maximum value of 12 and exclusive maximum is true") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: integer 12 equals maximum value of 12 and exclusive maximum is true") }, }, { @@ -738,7 +738,7 @@ func TestRef_Unmarshal_Json_Integer(t *testing.T) { s: "12", schema: schematest.New("integer", schematest.WithEnumValues(1, 2, 3)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '12' does not match one in the enumeration [1, 2, 3]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '12' does not match one in the enumeration [1, 2, 3]") }, }, { @@ -797,7 +797,7 @@ func TestParse_Number(t *testing.T) { s: fmt.Sprintf("%v", math.MaxFloat64), schema: schematest.New("number", schematest.WithFormat("float")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: number '1.7976931348623157e+308' does not match format 'float'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: number '1.7976931348623157e+308' does not match format 'float'") }, }, { @@ -814,7 +814,7 @@ func TestParse_Number(t *testing.T) { s: "3.612", schema: schematest.New("number", schematest.WithMinimum(3.7)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minimum: number 3.612 is less than minimum value of 3.7") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minimum: number 3.612 is less than minimum value of 3.7") }, }, { @@ -822,7 +822,7 @@ func TestParse_Number(t *testing.T) { s: "3.612", schema: schematest.New("number", schematest.WithFormat("float"), schematest.WithMinimum(3.7)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minimum: number 3.612 is less than minimum value of 3.7") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minimum: number 3.612 is less than minimum value of 3.7") }, }, { @@ -839,7 +839,7 @@ func TestParse_Number(t *testing.T) { s: "3.612", schema: schematest.New("number", schematest.WithMaximum(3.6)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: number 3.612 exceeds maximum value of 3.6") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: number 3.612 exceeds maximum value of 3.6") }, }, { @@ -847,7 +847,7 @@ func TestParse_Number(t *testing.T) { s: "3.612", schema: schematest.New("number", schematest.WithFormat("float"), schematest.WithMaximum(3.6)), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: number 3.612 exceeds maximum value of 3.6") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: number 3.612 exceeds maximum value of 3.6") }, }, { @@ -855,7 +855,7 @@ func TestParse_Number(t *testing.T) { s: "3.6", schema: &schema.Schema{Type: jsonSchema.Types{"number"}, Maximum: toFloatP(3.6), ExclusiveMaximum: jsonSchema.NewUnionTypeB[float64, bool](true)}, test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: number 3.6 equals maximum value of 3.6 and exclusive maximum is true") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: number 3.6 equals maximum value of 3.6 and exclusive maximum is true") }, }, { @@ -872,7 +872,7 @@ func TestParse_Number(t *testing.T) { s: "3.6", schema: &schema.Schema{Type: jsonSchema.Types{"number"}, Enum: []interface{}{3, 4, 5.5}}, test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '3.6' does not match one in the enumeration [3, 4, 5.5]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '3.6' does not match one in the enumeration [3, 4, 5.5]") }, }, { @@ -974,7 +974,7 @@ func TestRef_Unmarshal_Json_Object(t *testing.T) { schematest.WithProperty("age", schematest.New("integer")), ), test: func(t *testing.T, _ interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/required: required properties are missing: age") + require.EqualError(t, err, "Validation error count 1:\n\t- #/required: required properties are missing: age") }, }, { @@ -985,7 +985,7 @@ func TestRef_Unmarshal_Json_Object(t *testing.T) { schematest.WithProperty("age", schematest.New("integer")), ), test: func(t *testing.T, _ interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/name/minLength: string 'abc' is less than minimum of 6") + require.EqualError(t, err, "Validation error count 1:\n\t- #/name/minLength: string 'abc' is less than minimum of 6") }, }, { @@ -997,7 +997,7 @@ func TestRef_Unmarshal_Json_Object(t *testing.T) { schematest.WithEnum([]interface{}{map[string]interface{}{"name": "bar"}}), ), test: func(t *testing.T, _ interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '{name: foo}' does not match one in the enumeration [{name: bar}]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '{name: foo}' does not match one in the enumeration [{name: bar}]") }, }, { @@ -1045,7 +1045,7 @@ func TestRef_Unmarshal_Json_Object(t *testing.T) { schematest.WithFreeForm(false), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/additionalProperties: property 'age' not defined and the schema does not allow additional properties") + require.EqualError(t, err, "Validation error count 1:\n\t- #/additionalProperties: property 'age' not defined and the schema does not allow additional properties") }, }, { @@ -1055,7 +1055,7 @@ func TestRef_Unmarshal_Json_Object(t *testing.T) { schematest.WithMinProperties(2), ), test: func(t *testing.T, _ interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minProperties: property count 1 is less than minimum count of 2") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minProperties: property count 1 is less than minimum count of 2") }, }, { @@ -1065,7 +1065,7 @@ func TestRef_Unmarshal_Json_Object(t *testing.T) { schematest.WithMaxProperties(1), ), test: func(t *testing.T, _ interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxProperties: property count 2 exceeds maximum count of 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxProperties: property count 2 exceeds maximum count of 1") }, }, { @@ -1131,7 +1131,7 @@ func TestRef_Unmarshal_Json_Array(t *testing.T) { schematest.WithItems("string"), ), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minItems: item count 2 is less than minimum count of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minItems: item count 2 is less than minimum count of 3") }, }, { @@ -1152,7 +1152,7 @@ func TestRef_Unmarshal_Json_Array(t *testing.T) { schematest.WithItems("string"), ), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxItems: item count 2 exceeds maximum count of 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxItems: item count 2 exceeds maximum count of 1") }, }, { @@ -1173,7 +1173,7 @@ func TestRef_Unmarshal_Json_Array(t *testing.T) { schematest.WithItems("string"), ), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '[foo, bar]' does not match one in the enumeration [[foo, test]]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '[foo, bar]' does not match one in the enumeration [[foo, test]]") }, }, { @@ -1183,7 +1183,7 @@ func TestRef_Unmarshal_Json_Array(t *testing.T) { schematest.WithItems("string"), ), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '[foo, bar]' does not match one in the enumeration [[bar, foo]]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '[foo, bar]' does not match one in the enumeration [[bar, foo]]") }, }, { @@ -1204,7 +1204,7 @@ func TestRef_Unmarshal_Json_Array(t *testing.T) { schematest.WithItems("string"), ), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/uniqueItems: non-unique array item at index 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/uniqueItems: non-unique array item at index 1") }, }, { @@ -1271,7 +1271,7 @@ func TestRef_Unmarshal_Json_Bool(t *testing.T) { s: `1`, schema: schematest.New("boolean"), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected boolean but got number") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected boolean but got number") }, }, { diff --git a/providers/openapi/parameter_cookie_test.go b/providers/openapi/parameter_cookie_test.go index fa8439a8d..e78f72bf6 100644 --- a/providers/openapi/parameter_cookie_test.go +++ b/providers/openapi/parameter_cookie_test.go @@ -145,7 +145,7 @@ func TestFromRequest_Cookie(t *testing.T) { return r }, test: func(t *testing.T, result *openapi.RequestParameters, err error) { - require.EqualError(t, err, "parse cookie parameter 'debug' failed: error count 1:\n\t- #/type: invalid type, expected integer but got string") + require.EqualError(t, err, "parse cookie parameter 'debug' failed: Validation error count 1:\n\t- #/type: invalid type, expected integer but got string") }, }, { @@ -186,7 +186,7 @@ func TestFromRequest_Cookie(t *testing.T) { return r }, test: func(t *testing.T, result *openapi.RequestParameters, err error) { - require.EqualError(t, err, "parse cookie parameter 'foo' failed: error count 1:\n\t- #/items/1/type: invalid type, expected integer but got string") + require.EqualError(t, err, "parse cookie parameter 'foo' failed: Validation error count 1:\n\t- #/items/1/type: invalid type, expected integer but got string") }, }, { @@ -279,7 +279,7 @@ func TestFromRequest_Cookie(t *testing.T) { return r }, test: func(t *testing.T, result *openapi.RequestParameters, err error) { - require.EqualError(t, err, "parse cookie parameter 'foo' failed: parse property 'age' failed: error count 1:\n\t- #/type: invalid type, expected number but got string") + require.EqualError(t, err, "parse cookie parameter 'foo' failed: parse property 'age' failed: Validation error count 1:\n\t- #/type: invalid type, expected number but got string") }, }, } diff --git a/providers/openapi/parameter_header_test.go b/providers/openapi/parameter_header_test.go index 9ea06ed0c..9f3b7c5a9 100644 --- a/providers/openapi/parameter_header_test.go +++ b/providers/openapi/parameter_header_test.go @@ -153,7 +153,7 @@ func TestFromRequest_Header(t *testing.T) { return r }, test: func(t *testing.T, result *openapi.RequestParameters, err error) { - require.EqualError(t, err, "parse header parameter 'debug' failed: error count 1:\n\t- #/type: invalid type, expected integer but got string") + require.EqualError(t, err, "parse header parameter 'debug' failed: Validation error count 1:\n\t- #/type: invalid type, expected integer but got string") }, }, { @@ -188,7 +188,7 @@ func TestFromRequest_Header(t *testing.T) { return r }, test: func(t *testing.T, result *openapi.RequestParameters, err error) { - require.EqualError(t, err, "parse header parameter 'foo' failed: error count 1:\n\t- #/items/1/type: invalid type, expected integer but got string") + require.EqualError(t, err, "parse header parameter 'foo' failed: Validation error count 1:\n\t- #/items/1/type: invalid type, expected integer but got string") }, }, { @@ -269,7 +269,7 @@ func TestFromRequest_Header(t *testing.T) { return r }, test: func(t *testing.T, result *openapi.RequestParameters, err error) { - require.EqualError(t, err, "parse header parameter 'foo' failed: parse property 'age' failed: error count 1:\n\t- #/type: invalid type, expected number but got string") + require.EqualError(t, err, "parse header parameter 'foo' failed: parse property 'age' failed: Validation error count 1:\n\t- #/type: invalid type, expected number but got string") }, }, { diff --git a/providers/openapi/parameter_query_test.go b/providers/openapi/parameter_query_test.go index 36d9bbaac..c7d4e354b 100644 --- a/providers/openapi/parameter_query_test.go +++ b/providers/openapi/parameter_query_test.go @@ -462,7 +462,7 @@ func TestParseQuery(t *testing.T) { return httptest.NewRequest(http.MethodGet, "https://foo.bar?id[role]=admin&id[age]=foo&id[lastName]=Smith", nil) }, test: func(t *testing.T, result *openapi.RequestParameters, err error) { - require.EqualError(t, err, "parse query parameter 'id' failed: error count 1:\n\t- #/type: invalid type, expected integer but got string") + require.EqualError(t, err, "parse query parameter 'id' failed: Validation error count 1:\n\t- #/type: invalid type, expected integer but got string") }, }, { diff --git a/providers/openapi/path.go b/providers/openapi/path.go index c5a64a705..6f59467ba 100644 --- a/providers/openapi/path.go +++ b/providers/openapi/path.go @@ -217,9 +217,8 @@ func (p *Path) Parse(config *dynamic.Config, reader dynamic.Reader) error { WithField("path", p.Path). WithField("namespace", "http"). Error(err) - } else { - op.Path = p } + op.Path = p } for name, op := range p.AdditionalOperations { diff --git a/providers/openapi/schema/marshal.go b/providers/openapi/schema/marshal.go index adfc13ad7..7d1d37604 100644 --- a/providers/openapi/schema/marshal.go +++ b/providers/openapi/schema/marshal.go @@ -25,14 +25,7 @@ func (s *Schema) Marshal(i interface{}, contentType media.ContentType) ([]byte, } } - if uw, ok := err.(interface{ Unwrap() []error }); ok { - errs := uw.Unwrap() - if len(errs) > 1 { - return nil, fmt.Errorf("encoding data to '%v' failed:\n %w", contentType.String(), err) - } - } - - return nil, fmt.Errorf("encoding data to '%v' failed: %w", contentType, err) + return nil, err } e := encoding.NewEncoder(ConvertToJsonSchema(s)) diff --git a/providers/openapi/schema/marshal_json_test.go b/providers/openapi/schema/marshal_json_test.go index ba6d4a2a7..3d7bc3642 100644 --- a/providers/openapi/schema/marshal_json_test.go +++ b/providers/openapi/schema/marshal_json_test.go @@ -2,12 +2,13 @@ package schema_test import ( "encoding/json" - "github.com/stretchr/testify/require" "mokapi/media" "mokapi/providers/openapi/schema" "mokapi/providers/openapi/schema/schematest" "mokapi/sortedmap" "testing" + + "github.com/stretchr/testify/require" ) func TestRef_Marshal_Json(t *testing.T) { @@ -40,7 +41,7 @@ func TestRef_Marshal_Json(t *testing.T) { schema: schematest.New("number"), data: nil, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected number but got null") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected number but got null") }, }, { @@ -93,7 +94,7 @@ func TestRef_Marshal_Json(t *testing.T) { schema: schematest.New("integer"), data: "12", test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected integer but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got string") }, }, { @@ -137,7 +138,7 @@ func TestRef_Marshal_Json(t *testing.T) { schema: schematest.New("string", schematest.And("number")), data: true, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected number but got boolean") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected number but got boolean") }, }, } @@ -168,7 +169,7 @@ func TestRef_Marshal_Json_Object(t *testing.T) { schematest.WithProperty("value", schematest.New("integer"))), data: 12, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected object but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected object but got integer") require.Len(t, result, 0) }, }, @@ -389,7 +390,7 @@ func TestRef_Marshal_Json_AnyOf(t *testing.T) { ), data: map[string]interface{}{"foo": "foo", "bar": "bar", "value": "test"}, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 2:\n\t- #/anyOf/1/additionalProperties: does not match any schemas: property 'foo' not defined and the schema does not allow additional properties\n\t- #/anyOf/1/additionalProperties: does not match any schemas: property 'value' not defined and the schema does not allow additional properties") + require.EqualError(t, err, "Validation error count 2:\n\t- #/anyOf/1/additionalProperties: does not match any schemas: property 'foo' not defined and the schema does not allow additional properties\n\t- #/anyOf/1/additionalProperties: does not match any schemas: property 'value' not defined and the schema does not allow additional properties") }, }, { @@ -445,7 +446,7 @@ func TestRef_Marshal_Json_OneOf(t *testing.T) { ), data: map[string]interface{}{"bark": true, "breed": "Dingo"}, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") require.Len(t, result, 0) }, }, @@ -484,7 +485,7 @@ func TestRef_Marshal_Json_OneOf(t *testing.T) { ), data: map[string]interface{}{"bark": true, "breed": "Dingo"}, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") require.Len(t, result, 0) }, }, @@ -501,7 +502,7 @@ func TestRef_Marshal_Json_OneOf(t *testing.T) { ), data: map[string]interface{}{"bark": true, "breed": "Dingo"}, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") require.Len(t, result, 0) }, }, @@ -586,7 +587,7 @@ func TestRef_Marshal_Json_AllOf(t *testing.T) { return map[string]interface{}{"bar": "bar"} }, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/required: required properties are missing: foo") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/required: required properties are missing: foo") require.Len(t, result, 0) }, }, @@ -600,7 +601,7 @@ func TestRef_Marshal_Json_AllOf(t *testing.T) { return map[string]interface{}{"bar": "bar"} }, test: func(t *testing.T, result string, err error) { - require.EqualError(t, err, "encoding data to 'application/json' failed: error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/type: invalid type, expected integer but got object") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/type: invalid type, expected integer but got object") require.Len(t, result, 0) }, }, @@ -644,25 +645,25 @@ func TestRef_Marshal_Json_Invalid(t *testing.T) { name: "number", schema: schematest.New("number"), data: "foo", - exp: "encoding data to 'application/json' failed: error count 1:\n\t- #/type: invalid type, expected number but got string", + exp: "Validation error count 1:\n\t- #/type: invalid type, expected number but got string", }, { name: "exclusiveMinimum", schema: schematest.New("integer", schematest.WithExclusiveMinimum(3)), data: 3, - exp: "encoding data to 'application/json' failed: error count 1:\n\t- #/exclusiveMinimum: integer 3 equals minimum value of 3", + exp: "Validation error count 1:\n\t- #/exclusiveMinimum: integer 3 equals minimum value of 3", }, { name: "min array", schema: schematest.New("array", schematest.WithItems("integer"), schematest.WithMinItems(3)), data: []interface{}{12, 13}, - exp: "encoding data to 'application/json' failed: error count 1:\n\t- #/minItems: item count 2 is less than minimum count of 3", + exp: "Validation error count 1:\n\t- #/minItems: item count 2 is less than minimum count of 3", }, { name: "max array", schema: schematest.New("array", schematest.WithItems("integer"), schematest.WithMaxItems(1)), data: []interface{}{12, 13}, - exp: "encoding data to 'application/json' failed: error count 1:\n\t- #/maxItems: item count 2 exceeds maximum count of 1", + exp: "Validation error count 1:\n\t- #/maxItems: item count 2 exceeds maximum count of 1", }, { name: "map missing required property", @@ -672,7 +673,7 @@ func TestRef_Marshal_Json_Invalid(t *testing.T) { schematest.WithRequired("value"), ), data: map[interface{}]interface{}{"name": "foo"}, - exp: "encoding data to 'application/json' failed: error count 1:\n\t- #/required: required properties are missing: value", + exp: "Validation error count 1:\n\t- #/required: required properties are missing: value", }, } diff --git a/providers/openapi/schema/marshal_xml.go b/providers/openapi/schema/marshal_xml.go index 09b38dfda..e79554dbf 100644 --- a/providers/openapi/schema/marshal_xml.go +++ b/providers/openapi/schema/marshal_xml.go @@ -12,7 +12,7 @@ import ( func marshalXml(i interface{}, r *Schema) ([]byte, error) { if r == nil { - return nil, fmt.Errorf("no schema provided") + return nil, fmt.Errorf("failed to marshal XML: no schema provided") } b := &bytes.Buffer{} diff --git a/providers/openapi/schema/marshal_xml_test.go b/providers/openapi/schema/marshal_xml_test.go index 1e54a4171..d00bc4720 100644 --- a/providers/openapi/schema/marshal_xml_test.go +++ b/providers/openapi/schema/marshal_xml_test.go @@ -26,7 +26,7 @@ func TestMarshal_Xml(t *testing.T) { }, schema: nil, test: func(t *testing.T, s string, err error) { - require.EqualError(t, err, "encoding data to 'application/xml' failed: no schema provided") + require.EqualError(t, err, "failed to marshal XML: no schema provided") }, }, { @@ -265,7 +265,7 @@ func TestMarshal_Xml(t *testing.T) { Wrapped: true, })), test: func(t *testing.T, s string, err error) { - require.EqualError(t, err, "encoding data to 'application/xml' failed: error count 1:\n\t- expected array but got: 4") + require.EqualError(t, err, "Validation error count 1:\n\t- expected array but got: 4") }, }, { diff --git a/providers/openapi/schema/parse_xml_test.go b/providers/openapi/schema/parse_xml_test.go index 88a8435f5..7c6b5ddf3 100644 --- a/providers/openapi/schema/parse_xml_test.go +++ b/providers/openapi/schema/parse_xml_test.go @@ -109,7 +109,7 @@ func TestParseXML(t *testing.T) { schematest.WithRequired("id"), ), test: func(t *testing.T, v any, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/required: required properties are missing: id") + require.EqualError(t, err, "Validation error count 1:\n\t- #/required: required properties are missing: id") }, }, } diff --git a/runtime/runtime_http_search.go b/runtime/runtime_http_search.go index eecd0effc..4ab156ed0 100644 --- a/runtime/runtime_http_search.go +++ b/runtime/runtime_http_search.go @@ -21,6 +21,7 @@ type httpSearchIndexData struct { Api string `json:"api"` Name string `json:"name"` Version string `json:"version"` + Summary string `json:"summary"` Description string `json:"description"` Contact *openapi.Contact `json:"contact"` Servers []*openapi.Server `json:"servers"` @@ -84,6 +85,7 @@ func (s *HttpStore) addToIndex(cfg *openapi.Config) { Api: cfg.Info.Name, Name: cfg.Info.Name, Version: cfg.Info.Version, + Summary: cfg.Info.Summary, Description: cfg.Info.Description, Contact: cfg.Info.Contact, Servers: cfg.Servers, @@ -220,6 +222,7 @@ func getHttpSearchResult(fields map[string]string, discriminator []string) (sear if len(discriminator) == 1 { result.Title = fields["name"] + result.Description = BuildDescription(150, fields["summary"], fields["description"]) result.Params = map[string]string{ "type": strings.ToLower(result.Type), "service": result.Title, @@ -231,6 +234,7 @@ func getHttpSearchResult(fields map[string]string, discriminator []string) (sear case "path": result.Domain = fields["api"] result.Title = fields["path"] + result.Description = BuildDescription(150, fields["summary"], fields["description"]) result.Params = map[string]string{ "type": strings.ToLower(result.Type), "service": result.Domain, @@ -240,6 +244,7 @@ func getHttpSearchResult(fields map[string]string, discriminator []string) (sear case "operation": result.Domain = fields["api"] result.Title = fields["path"] + result.Description = BuildDescription(150, fields["summary"], fields["description"]) result.Params = map[string]string{ "type": strings.ToLower(result.Type), "service": result.Domain, diff --git a/runtime/runtime_http_search_test.go b/runtime/runtime_http_search_test.go index 2675548da..bcab2cfd4 100644 --- a/runtime/runtime_http_search_test.go +++ b/runtime/runtime_http_search_test.go @@ -35,7 +35,7 @@ func TestIndex_Http(t *testing.T) { { name: "Search by name", test: func(t *testing.T, app *runtime.App) { - cfg := openapitest.NewConfig("3.0", openapitest.WithInfo("foo", "", "")) + cfg := openapitest.NewConfig("3.0", openapitest.WithInfo("foo", "", "An API description")) app.Http.Add(toConfig(cfg)) var r search.Result @@ -48,9 +48,72 @@ func TestIndex_Http(t *testing.T) { require.Len(t, r.Results, 1) require.Equal(t, search.ResultItem{ - Type: "HTTP", - Title: "foo", - Fragments: []string{"foo"}, + Type: "HTTP", + Title: "foo", + Description: "An API description", + Fragments: []string{"foo"}, + Params: map[string]string{ + "type": "http", + "service": "foo", + }, + }, + r.Results[0]) + }, + }, + { + name: "summary takes precedence over description.", + test: func(t *testing.T, app *runtime.App) { + cfg := openapitest.NewConfig("3.0", + openapitest.WithInfo("foo", "", "An API description"), + openapitest.WithSummary("A short summary"), + ) + app.Http.Add(toConfig(cfg)) + + var r search.Result + var err error + waitSearchIndex(t, func() bool { + r, err = app.Search(search.Request{QueryText: "foo", Limit: 10}) + require.NoError(t, err) + return len(r.Results) == 1 + }) + require.Len(t, r.Results, 1) + require.Equal(t, + search.ResultItem{ + Type: "HTTP", + Title: "foo", + Description: "A short summary An API description", + Fragments: []string{"foo"}, + Params: map[string]string{ + "type": "http", + "service": "foo", + }, + }, + r.Results[0]) + }, + }, + { + name: "truncate summary", + test: func(t *testing.T, app *runtime.App) { + cfg := openapitest.NewConfig("3.0", + openapitest.WithInfo("foo", "", "An API description"), + openapitest.WithSummary("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum."), + ) + app.Http.Add(toConfig(cfg)) + + var r search.Result + var err error + waitSearchIndex(t, func() bool { + r, err = app.Search(search.Request{QueryText: "foo", Limit: 10}) + require.NoError(t, err) + return len(r.Results) == 1 + }) + require.Len(t, r.Results, 1) + require.Equal(t, + search.ResultItem{ + Type: "HTTP", + Title: "foo", + Description: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam...", + Fragments: []string{"foo"}, Params: map[string]string{ "type": "http", "service": "foo", @@ -218,9 +281,10 @@ func TestIndex_Http(t *testing.T) { require.Len(t, r.Results, 2) require.Equal(t, search.ResultItem{ - Type: "HTTP", - Title: "foo", - Fragments: []string{"a description"}, + Type: "HTTP", + Title: "foo", + Description: "a description", + Fragments: []string{"a description"}, Params: map[string]string{ "type": "http", "service": "foo", @@ -229,10 +293,11 @@ func TestIndex_Http(t *testing.T) { r.Results[1]) require.Equal(t, search.ResultItem{ - Type: "HTTP", - Domain: "foo", - Title: "/pets", - Fragments: []string{"a description"}, + Type: "HTTP", + Domain: "foo", + Title: "/pets", + Description: `a description`, + Fragments: []string{"a description"}, Params: map[string]string{ "type": "http", "service": "foo", @@ -251,6 +316,7 @@ func TestIndex_Http(t *testing.T) { openapitest.WithPath("/pets", openapitest.WithPathInfo("", "a description"), openapitest.WithOperation(http.MethodGet, + openapitest.WithOperationInfo("Summary value", "Description value", "", false), openapitest.WithHeaderParam("foo", true, openapitest.WithParamInfo("parameter description")), ), ), @@ -267,10 +333,11 @@ func TestIndex_Http(t *testing.T) { require.Len(t, r.Results, 1) require.Equal(t, search.ResultItem{ - Type: "HTTP", - Domain: "foo", - Title: "/pets", - Fragments: []string{"parameter description"}, + Type: "HTTP", + Domain: "foo", + Title: "/pets", + Description: `Summary value Description value`, + Fragments: []string{"parameter description"}, Params: map[string]string{ "type": "http", "service": "foo", diff --git a/runtime/runtime_kafka_search.go b/runtime/runtime_kafka_search.go index 543779aaa..7652478de 100644 --- a/runtime/runtime_kafka_search.go +++ b/runtime/runtime_kafka_search.go @@ -146,6 +146,7 @@ func getKafkaSearchResult(fields map[string]string, discriminator []string) (sea if len(discriminator) == 1 { result.Title = fields["name"] + result.Description = BuildDescription(150, fields["description"]) result.Params = map[string]string{ "type": strings.ToLower(result.Type), "service": result.Title, @@ -167,6 +168,7 @@ func getKafkaSearchResult(fields map[string]string, discriminator []string) (sea } else if len(fields["title"]) > 0 { title = fields["title"] } + result.Description = BuildDescription(150, fields["summary"], fields["description"]) result.Domain = fields["api"] result.Title = fmt.Sprintf("Topic %s", title) result.Params = map[string]string{ diff --git a/runtime/runtime_kafka_search_test.go b/runtime/runtime_kafka_search_test.go index b98ea7c56..b68be38e3 100644 --- a/runtime/runtime_kafka_search_test.go +++ b/runtime/runtime_kafka_search_test.go @@ -116,10 +116,11 @@ func TestIndex_Kafka(t *testing.T) { require.Len(t, r.Results, 1) require.Equal(t, search.ResultItem{ - Type: "Kafka", - Domain: "Kafka Test server", - Title: "Topic foo", - Fragments: []string{"first"}, + Type: "Kafka", + Domain: "Kafka Test server", + Title: "Topic foo", + Description: `first`, + Fragments: []string{"first"}, Params: map[string]string{ "type": "kafka", "service": "Kafka Test server", @@ -133,10 +134,11 @@ func TestIndex_Kafka(t *testing.T) { require.Len(t, r.Results, 1) require.Equal(t, search.ResultItem{ - Type: "Kafka", - Domain: "Kafka Test server", - Title: "Topic address-name", - Fragments: []string{"second"}, + Type: "Kafka", + Domain: "Kafka Test server", + Title: "Topic address-name", + Description: `second`, + Fragments: []string{"second"}, Params: map[string]string{ "type": "kafka", "service": "Kafka Test server", @@ -150,10 +152,11 @@ func TestIndex_Kafka(t *testing.T) { require.Len(t, r.Results, 1) require.Equal(t, search.ResultItem{ - Type: "Kafka", - Domain: "Kafka Test server", - Title: "Topic yuh", - Fragments: []string{"third"}, + Type: "Kafka", + Domain: "Kafka Test server", + Title: "Topic yuh", + Description: `third`, + Fragments: []string{"third"}, Params: map[string]string{ "type": "kafka", "service": "Kafka Test server", diff --git a/runtime/runtime_search.go b/runtime/runtime_search.go index 300b26a41..e33a45963 100644 --- a/runtime/runtime_search.go +++ b/runtime/runtime_search.go @@ -67,3 +67,61 @@ func getConfigSearchResult(fields map[string]string, _ []string) (search.ResultI }, }, nil } + +func BuildDescription(max int, values ...string) string { + seen := map[string]bool{} + var parts []string + + for _, v := range values { + v = normalize(v) + + if v == "" || seen[v] { + continue + } + + seen[v] = true + parts = append(parts, v) + } + + return truncateWords(strings.Join(parts, " "), max) +} + +func truncateWords(s string, max int) string { + if len(s) <= max { + return s + } + + words := strings.Fields(s) + var result strings.Builder + for _, w := range words { + next := w + if result.Len() > 0 { + next = " " + w + } + + if result.Len()+len(next) > max { + break + } + result.WriteString(next) + } + + r := result.String() + if r != s { + r += "..." + } + return r +} + +func normalize(s string) string { + s = strings.TrimSpace(s) + + // Replace line breaks/tabs with spaces + s = strings.ReplaceAll(s, "\n", " ") + s = strings.ReplaceAll(s, "\r", " ") + s = strings.ReplaceAll(s, "\t", " ") + + // Collapse multiple spaces + s = strings.Join(strings.Fields(s), " ") + + return s +} diff --git a/runtime/search/index.go b/runtime/search/index.go index 38ac1ce2d..1f09956bb 100644 --- a/runtime/search/index.go +++ b/runtime/search/index.go @@ -12,12 +12,13 @@ type Result struct { } type ResultItem struct { - Type string `json:"type"` - Domain string `json:"domain,omitempty"` - Title string `json:"title"` - Fragments []string `json:"fragments,omitempty"` - Params map[string]string `json:"params"` - Time string `json:"time,omitempty"` + Type string `json:"type"` + Domain string `json:"domain,omitempty"` + Title string `json:"title"` + Description string `json:"description,omitempty"` + Fragments []string `json:"fragments,omitempty"` + Params map[string]string `json:"params"` + Time string `json:"time,omitempty"` } type ErrNotEnabled struct{} diff --git a/schema/encoding/decoder_test.go b/schema/encoding/decoder_test.go index 448dc78e0..80e2e1942 100644 --- a/schema/encoding/decoder_test.go +++ b/schema/encoding/decoder_test.go @@ -39,7 +39,7 @@ func TestDecode(t *testing.T) { ), }, test: func(t *testing.T, v any, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected object but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected object but got string") }, }, { diff --git a/schema/encoding/encoder.go b/schema/encoding/encoder.go index e152d7dc6..4070fd8d1 100644 --- a/schema/encoding/encoder.go +++ b/schema/encoding/encoder.go @@ -10,9 +10,6 @@ import ( "strings" ) -const marshalError = "encoding data to '%v' failed: %w" -const marshalErrorList = "encoding data to '%v' failed:\n%w" - type Encoder struct { r *schema.Schema } @@ -31,15 +28,9 @@ func (e *Encoder) Write(v interface{}, contentType media.ContentType) ([]byte, e i, err := p.ParseWith(v, e.r) if err != nil { - if uw, ok := err.(interface{ Unwrap() []error }); ok { - errs := uw.Unwrap() - if len(errs) > 1 { - return nil, fmt.Errorf(marshalErrorList, contentType.String(), err) - } - } - - return nil, fmt.Errorf(marshalError, contentType.String(), err) + return nil, err } + var b []byte switch { case contentType.Subtype == "json" || strings.HasSuffix(contentType.Subtype, "+json"): @@ -64,7 +55,7 @@ func (e *Encoder) Write(v interface{}, contentType media.ContentType) ([]byte, e } if err != nil { - return nil, fmt.Errorf(marshalError, contentType.String(), err) + return nil, err } return b, nil } diff --git a/schema/json/generator/allOf_test.go b/schema/json/generator/allOf_test.go index 90068256d..9d91ca8f6 100644 --- a/schema/json/generator/allOf_test.go +++ b/schema/json/generator/allOf_test.go @@ -210,7 +210,7 @@ func TestAllOf(t *testing.T) { ), }, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "failed to generate valid object: reached attempt limit (10) caused by: error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/additionalProperties: property 'type' not defined and the schema does not allow additional properties") + require.EqualError(t, err, "failed to generate valid object: reached attempt limit (10) caused by: Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/additionalProperties: property 'type' not defined and the schema does not allow additional properties") }, }, } diff --git a/schema/json/parser/enum_test.go b/schema/json/parser/enum_test.go index 0572f1efb..7536eddf1 100644 --- a/schema/json/parser/enum_test.go +++ b/schema/json/parser/enum_test.go @@ -1,11 +1,12 @@ package parser_test import ( - "github.com/stretchr/testify/require" "mokapi/schema/json/parser" "mokapi/schema/json/schema" "mokapi/schema/json/schema/schematest" "testing" + + "github.com/stretchr/testify/require" ) func TestParse_Enum(t *testing.T) { @@ -29,7 +30,7 @@ func TestParse_Enum(t *testing.T) { s: schematest.New("string", schematest.WithEnum([]interface{}{"a", "b", "c"})), d: "z", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value 'z' does not match one in the enumeration [a, b, c]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value 'z' does not match one in the enumeration [a, b, c]") }, }, { @@ -46,7 +47,7 @@ func TestParse_Enum(t *testing.T) { s: schematest.New("integer", schematest.WithEnum([]interface{}{1, 2, 3})), d: 9, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '9' does not match one in the enumeration [1, 2, 3]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '9' does not match one in the enumeration [1, 2, 3]") }, }, { @@ -63,7 +64,7 @@ func TestParse_Enum(t *testing.T) { s: schematest.New("number", schematest.WithEnum([]interface{}{1.1, 2.2, 3.3})), d: 1.5, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '1.5' does not match one in the enumeration [1.1, 2.2, 3.3]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '1.5' does not match one in the enumeration [1.1, 2.2, 3.3]") }, }, { @@ -86,7 +87,7 @@ func TestParse_Enum(t *testing.T) { ), d: map[string]interface{}{"foo": "qux"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '{foo: qux}' does not match one in the enumeration [{foo: bar}, {foo: baz}]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '{foo: qux}' does not match one in the enumeration [{foo: bar}, {foo: baz}]") }, }, { @@ -109,7 +110,7 @@ func TestParse_Enum(t *testing.T) { ), d: []interface{}{"foo", "qux"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/enum: value '[foo, qux]' does not match one in the enumeration [[foo, bar], [foo, baz]]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/enum: value '[foo, qux]' does not match one in the enumeration [[foo, bar], [foo, baz]]") }, }, { diff --git a/schema/json/parser/error.go b/schema/json/parser/error.go index 02d970b04..a339d4d7e 100644 --- a/schema/json/parser/error.go +++ b/schema/json/parser/error.go @@ -2,8 +2,9 @@ package parser import ( "fmt" - "github.com/pkg/errors" "strings" + + "github.com/pkg/errors" ) type Error struct { @@ -39,7 +40,7 @@ func (e *Error) Error() string { sb.WriteString(fmt.Sprintf("\t%s", item)) } - return fmt.Sprintf("error count %d:\n%s", len(items), sb.String()) + return fmt.Sprintf("Validation error count %d:\n%s", len(items), sb.String()) } func (e *ErrorList) Error() string { diff --git a/schema/json/parser/error_test.go b/schema/json/parser/error_test.go index 66fc6eb76..60f82350c 100644 --- a/schema/json/parser/error_test.go +++ b/schema/json/parser/error_test.go @@ -2,8 +2,9 @@ package parser import ( "fmt" - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) func TestError(t *testing.T) { @@ -19,7 +20,7 @@ func TestError(t *testing.T) { fmt.Errorf("string 'a' is less than minimum of 3"), }, }, - exp: "error count 1:\n\t- string 'a' is less than minimum of 3", + exp: "Validation error count 1:\n\t- string 'a' is less than minimum of 3", }, { name: "two error", @@ -29,7 +30,7 @@ func TestError(t *testing.T) { fmt.Errorf("item count 2 exceeds maximum count of 1"), }, }, - exp: "error count 2:\n\t- string 'a' is less than minimum of 3\n\t- item count 2 exceeds maximum count of 1", + exp: "Validation error count 2:\n\t- string 'a' is less than minimum of 3\n\t- item count 2 exceeds maximum count of 1", }, { name: "error detail", @@ -42,7 +43,7 @@ func TestError(t *testing.T) { }, }, }, - exp: "error count 1:\n\t- string 'a' is less than minimum of 3", + exp: "Validation error count 1:\n\t- string 'a' is less than minimum of 3", }, } diff --git a/schema/json/parser/parse_one_test.go b/schema/json/parser/parse_one_test.go index 918cb5721..7d99f30d7 100644 --- a/schema/json/parser/parse_one_test.go +++ b/schema/json/parser/parse_one_test.go @@ -1,11 +1,12 @@ package parser_test import ( - "github.com/stretchr/testify/require" "mokapi/schema/json/parser" "mokapi/schema/json/schema" "mokapi/schema/json/schema/schematest" "testing" + + "github.com/stretchr/testify/require" ) func TestParser_ParseOne(t *testing.T) { @@ -47,7 +48,7 @@ func TestParser_ParseOne(t *testing.T) { ), data: 15, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") }, }, { @@ -58,7 +59,7 @@ func TestParser_ParseOne(t *testing.T) { ), data: 15, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") }, }, { @@ -69,7 +70,7 @@ func TestParser_ParseOne(t *testing.T) { ), data: 15, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") }, }, { @@ -80,7 +81,7 @@ func TestParser_ParseOne(t *testing.T) { ), data: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/oneOf: valid against no schemas") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against no schemas") }, }, { @@ -91,7 +92,7 @@ func TestParser_ParseOne(t *testing.T) { ), data: map[string]interface{}{}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf: valid against more than one schema: valid schema indexes: 0, 1") }, }, { @@ -122,7 +123,7 @@ func TestParser_ParseOne(t *testing.T) { ), data: map[string]interface{}{"foo": "bar"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/oneOf/0/unevaluatedProperties: property foo not successfully evaluated and schema does not allow unevaluated properties") + require.EqualError(t, err, "Validation error count 1:\n\t- #/oneOf/0/unevaluatedProperties: property foo not successfully evaluated and schema does not allow unevaluated properties") }, }, } diff --git a/schema/json/parser/parser_all_test.go b/schema/json/parser/parser_all_test.go index 318d9e42c..a091253bd 100644 --- a/schema/json/parser/parser_all_test.go +++ b/schema/json/parser/parser_all_test.go @@ -66,7 +66,7 @@ func TestParser_ParseAll(t *testing.T) { schematest.New("integer", schematest.WithMaximum(11)), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/maximum: integer 12 exceeds maximum value of 11") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/maximum: integer 12 exceeds maximum value of 11") }, }, { @@ -77,7 +77,7 @@ func TestParser_ParseAll(t *testing.T) { schematest.New("string"), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/type: invalid type, expected string but got integer") }, }, { @@ -112,7 +112,7 @@ func TestParser_ParseAll(t *testing.T) { schematest.New("object", schematest.WithProperty("foo", schematest.New("string"))), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/type: invalid type, expected integer but got object") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/type: invalid type, expected integer but got object") }, }, { @@ -156,7 +156,7 @@ func TestParser_ParseAll(t *testing.T) { schematest.New("object", schematest.WithProperty("age", schematest.New("integer")), schematest.WithFreeForm(false)), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 3:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/additionalProperties: property 'age' not defined and the schema does not allow additional properties\n\t\t- #/allOf/1/additionalProperties: property 'name' not defined and the schema does not allow additional properties") + require.EqualError(t, err, "Validation error count 3:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/additionalProperties: property 'age' not defined and the schema does not allow additional properties\n\t\t- #/allOf/1/additionalProperties: property 'name' not defined and the schema does not allow additional properties") }, }, { @@ -170,7 +170,7 @@ func TestParser_ParseAll(t *testing.T) { schematest.New("object", schematest.WithProperty("age", schematest.New("integer")), schematest.WithFreeForm(false)), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 5:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/name/type: invalid type, expected string but got integer\n\t\t- #/allOf/0/additionalProperties: property 'age' not defined and the schema does not allow additional properties\n\t\t- #/allOf/1/age/type: invalid type, expected integer but got string\n\t\t- #/allOf/1/additionalProperties: property 'name' not defined and the schema does not allow additional properties") + require.EqualError(t, err, "Validation error count 5:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/name/type: invalid type, expected string but got integer\n\t\t- #/allOf/0/additionalProperties: property 'age' not defined and the schema does not allow additional properties\n\t\t- #/allOf/1/age/type: invalid type, expected integer but got string\n\t\t- #/allOf/1/additionalProperties: property 'name' not defined and the schema does not allow additional properties") }, }, { @@ -187,7 +187,7 @@ func TestParser_ParseAll(t *testing.T) { schematest.New("object", schematest.WithProperty("age", schematest.New("integer"))), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/unevaluatedProperties: property age not successfully evaluated and schema does not allow unevaluated properties") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/unevaluatedProperties: property age not successfully evaluated and schema does not allow unevaluated properties") }, }, { @@ -212,7 +212,7 @@ func TestParser_ParseAll(t *testing.T) { "type": "business", }, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/additionalProperties: property 'type' not defined and the schema does not allow additional properties") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/additionalProperties: property 'type' not defined and the schema does not allow additional properties") }, }, { @@ -238,7 +238,7 @@ func TestParser_ParseAll(t *testing.T) { "something that doesn't belong": "hi!", }, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/unevaluatedProperties: property something that doesn't belong not successfully evaluated and schema does not allow unevaluated properties") + require.EqualError(t, err, "Validation error count 1:\n\t- #/unevaluatedProperties: property something that doesn't belong not successfully evaluated and schema does not allow unevaluated properties") }, }, { @@ -315,7 +315,7 @@ func TestParser_ParseAll(t *testing.T) { "type": "residential", }, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/additionalProperties: property 'type' not defined and the schema does not allow additional properties") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/additionalProperties: property 'type' not defined and the schema does not allow additional properties") }, }, } @@ -414,7 +414,7 @@ func TestParser_AllOf_If_Then(t *testing.T) { "postal_code": "10000", }, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/then/postal_code/pattern: does not match schema: string '10000' does not match regex pattern '[A-Z][0-9][A-Z] [0-9][A-Z][0-9]'") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/1/then/postal_code/pattern: does not match schema: string '10000' does not match regex pattern '[A-Z][0-9][A-Z] [0-9][A-Z][0-9]'") }, }, { @@ -435,7 +435,7 @@ func TestParser_AllOf_If_Then(t *testing.T) { "postal_code": "K1M 1M4", }, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/then/postal_code/pattern: does not match schema: string 'K1M 1M4' does not match regex pattern '[0-9]{5}(-[0-9]{4})?'") + require.EqualError(t, err, "Validation error count 2:\n\t- #/allOf: does not match all schema\n\t\t- #/allOf/0/then/postal_code/pattern: does not match schema: string 'K1M 1M4' does not match regex pattern '[0-9]{5}(-[0-9]{4})?'") }, }, } diff --git a/schema/json/parser/parser_any_test.go b/schema/json/parser/parser_any_test.go index 7e54b43e6..38e8fb244 100644 --- a/schema/json/parser/parser_any_test.go +++ b/schema/json/parser/parser_any_test.go @@ -1,11 +1,12 @@ package parser_test import ( - "github.com/stretchr/testify/require" "mokapi/schema/json/parser" "mokapi/schema/json/schema" "mokapi/schema/json/schema/schematest" "testing" + + "github.com/stretchr/testify/require" ) func TestParser_ParseAny(t *testing.T) { @@ -33,7 +34,7 @@ func TestParser_ParseAny(t *testing.T) { schematest.New("string"), schematest.New("integer")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/anyOf: does not match any schemas") + require.EqualError(t, err, "Validation error count 1:\n\t- #/anyOf: does not match any schemas") }, }, { @@ -43,7 +44,7 @@ func TestParser_ParseAny(t *testing.T) { schematest.New("string"), schematest.New("integer")), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/anyOf: does not match any schemas") + require.EqualError(t, err, "Validation error count 1:\n\t- #/anyOf: does not match any schemas") }, }, { @@ -195,7 +196,7 @@ func TestParser_ParseAny(t *testing.T) { ), ), test: func(t *testing.T, i interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/anyOf/0/unevaluatedProperties/type: does not match any schemas: invalid type, expected boolean but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/anyOf/0/unevaluatedProperties/type: does not match any schemas: invalid type, expected boolean but got string") }, }, { diff --git a/schema/json/parser/parser_array_test.go b/schema/json/parser/parser_array_test.go index 193cd0f83..e54218c16 100644 --- a/schema/json/parser/parser_array_test.go +++ b/schema/json/parser/parser_array_test.go @@ -21,7 +21,7 @@ func TestParser_Array(t *testing.T) { schema: schematest.New("array"), data: map[string]interface{}{"a": 1, "b": 2, "c": nil}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected array but got object") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected array but got object") }, }, { @@ -38,7 +38,7 @@ func TestParser_Array(t *testing.T) { schema: schematest.New("array", schematest.WithItems("integer")), data: []interface{}{1, 2, 3, 4, "foo"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/items/4/type: invalid type, expected integer but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/items/4/type: invalid type, expected integer but got string") }, }, { @@ -67,7 +67,7 @@ func TestParser_Array(t *testing.T) { )), data: []interface{}{1, "foo"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/items/1/type: invalid type, expected integer but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/items/1/type: invalid type, expected integer but got string") }, }, { @@ -78,7 +78,7 @@ func TestParser_Array(t *testing.T) { ), schematest.WithItems("integer")), data: []interface{}{1, 2, "foo"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/items/2/type: invalid type, expected integer but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/items/2/type: invalid type, expected integer but got string") }, }, { @@ -113,7 +113,7 @@ func TestParser_Array(t *testing.T) { ), schematest.WithItemsNew(schematest.NewBool(false))), data: []interface{}{1, 2, "foo"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/items/2/valid: schema always fails validation") + require.EqualError(t, err, "Validation error count 1:\n\t- #/items/2/valid: schema always fails validation") }, }, { @@ -124,7 +124,7 @@ func TestParser_Array(t *testing.T) { ), schematest.WithUnevaluatedItems(&schema.Schema{Boolean: toBoolP(false)})), data: []interface{}{1, 2, "foo"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/unevaluatedItems: item at index 2 has not been successfully evaluated and the schema does not allow unevaluated items") + require.EqualError(t, err, "Validation error count 1:\n\t- #/unevaluatedItems: item at index 2 has not been successfully evaluated and the schema does not allow unevaluated items") }, }, { @@ -144,7 +144,7 @@ func TestParser_Array(t *testing.T) { schema: schematest.New("array", schematest.WithContains(schematest.New("integer"))), data: []interface{}{"foo"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/contains: no items match contains") + require.EqualError(t, err, "Validation error count 1:\n\t- #/contains: no items match contains") }, }, { @@ -164,7 +164,7 @@ func TestParser_Array(t *testing.T) { ), data: []interface{}{1}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minContains: contains match count 1 is less than minimum contains count of 2") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minContains: contains match count 1 is less than minimum contains count of 2") }, }, { @@ -187,7 +187,7 @@ func TestParser_Array(t *testing.T) { ), data: []interface{}{1, 2}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxContains: contains match count 2 exceeds maximum contains count of 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxContains: contains match count 2 exceeds maximum contains count of 1") }, }, { @@ -209,7 +209,7 @@ func TestParser_Array(t *testing.T) { ), data: []interface{}{1}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minItems: item count 1 is less than minimum count of 2") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minItems: item count 1 is less than minimum count of 2") }, }, { @@ -230,7 +230,7 @@ func TestParser_Array(t *testing.T) { ), data: []interface{}{1, 2}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxItems: item count 2 exceeds maximum count of 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxItems: item count 2 exceeds maximum count of 1") }, }, { @@ -251,7 +251,7 @@ func TestParser_Array(t *testing.T) { ), data: []interface{}{1, 2, 2}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/uniqueItems: non-unique array item at index 2") + require.EqualError(t, err, "Validation error count 1:\n\t- #/uniqueItems: non-unique array item at index 2") }, }, { @@ -272,7 +272,7 @@ func TestParser_Array(t *testing.T) { ), data: []string{"a", "b"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/const: value '[a, b]' does not match const '[a, b, c]'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/const: value '[a, b]' does not match const '[a, b, c]'") }, }, { @@ -293,7 +293,7 @@ func TestParser_Array(t *testing.T) { ), data: []interface{}{"a", 1, 2}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/items/1/type: invalid type, expected string but got integer\n\t- #/items/2/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 2:\n\t- #/items/1/type: invalid type, expected string but got integer\n\t- #/items/2/type: invalid type, expected string but got integer") }, }, { @@ -310,7 +310,7 @@ func TestParser_Array(t *testing.T) { map[string]interface{}{"foo": "a", "bar": "bar"}, }, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 3:\n\t- #/items/1/bar/type: invalid type, expected integer but got string\n\t- #/items/2/foo/minLength: string 'a' is less than minimum of 3\n\t- #/items/2/bar/type: invalid type, expected integer but got string") + require.EqualError(t, err, "Validation error count 3:\n\t- #/items/1/bar/type: invalid type, expected integer but got string\n\t- #/items/2/foo/minLength: string 'a' is less than minimum of 3\n\t- #/items/2/bar/type: invalid type, expected integer but got string") }, }, { diff --git a/schema/json/parser/parser_bool_test.go b/schema/json/parser/parser_bool_test.go index 5de46023c..e4604c78d 100644 --- a/schema/json/parser/parser_bool_test.go +++ b/schema/json/parser/parser_bool_test.go @@ -1,11 +1,12 @@ package parser_test import ( - "github.com/stretchr/testify/require" "mokapi/schema/json/parser" "mokapi/schema/json/schema" "mokapi/schema/json/schema/schematest" "testing" + + "github.com/stretchr/testify/require" ) func TestParser_ParseBoolean(t *testing.T) { @@ -39,7 +40,7 @@ func TestParser_ParseBoolean(t *testing.T) { data: "true", schema: schematest.New("boolean"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected boolean but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected boolean but got string") }, }, { @@ -68,7 +69,7 @@ func TestParser_ParseBoolean(t *testing.T) { data: 0, schema: schematest.New("boolean"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected boolean but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected boolean but got integer") }, }, { @@ -77,7 +78,7 @@ func TestParser_ParseBoolean(t *testing.T) { data: 1, schema: schematest.New("boolean"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected boolean but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected boolean but got integer") }, }, { @@ -85,7 +86,7 @@ func TestParser_ParseBoolean(t *testing.T) { data: []bool{true}, schema: schematest.New("boolean"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected boolean but got array") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected boolean but got array") }, }, { @@ -93,7 +94,7 @@ func TestParser_ParseBoolean(t *testing.T) { data: false, schema: schematest.New("boolean", schematest.WithConst(true)), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/const: value 'false' does not match const 'true'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/const: value 'false' does not match const 'true'") }, }, { diff --git a/schema/json/parser/parser_integer_test.go b/schema/json/parser/parser_integer_test.go index 9875cdec6..b72a6e94a 100644 --- a/schema/json/parser/parser_integer_test.go +++ b/schema/json/parser/parser_integer_test.go @@ -1,11 +1,12 @@ package parser_test import ( - "github.com/stretchr/testify/require" "mokapi/schema/json/parser" "mokapi/schema/json/schema" "mokapi/schema/json/schema/schematest" "testing" + + "github.com/stretchr/testify/require" ) func TestParse_Integer(t *testing.T) { @@ -23,7 +24,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer"), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected integer but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got string") }, }, { @@ -31,7 +32,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer"), d: map[string]interface{}{}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected integer but got object") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got object") }, }, { @@ -39,7 +40,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithFormat("int32")), d: int64(1e10), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: integer '10000000000' does not match format 'int32'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: integer '10000000000' does not match format 'int32'") }, }, { @@ -47,7 +48,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithFormat("int32")), d: int64(-1e10), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: integer '-10000000000' does not match format 'int32'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: integer '-10000000000' does not match format 'int32'") }, }, { @@ -84,7 +85,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer"), d: 3.4, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected integer but got number") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got number") }, }, { @@ -112,7 +113,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer"), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected integer but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got string") }, convertStringToNumber: true, @@ -122,7 +123,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithFormat("int32")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected integer but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected integer but got string") }, convertStringToNumber: true, @@ -143,7 +144,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithMultipleOf(3)), d: 8, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/multipleOf: integer 8 is not a multiple of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/multipleOf: integer 8 is not a multiple of 3") }, }, { @@ -160,7 +161,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithMinimum(3)), d: 1, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minimum: integer 1 is less than minimum value of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minimum: integer 1 is less than minimum value of 3") }, }, { @@ -177,7 +178,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithMaximum(3)), d: 4, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: integer 4 exceeds maximum value of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: integer 4 exceeds maximum value of 3") }, }, { @@ -194,7 +195,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithExclusiveMinimum(3)), d: 2, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMinimum: integer 2 is less than minimum value of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMinimum: integer 2 is less than minimum value of 3") }, }, { @@ -202,7 +203,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithExclusiveMinimum(3)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMinimum: integer 3 equals minimum value of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMinimum: integer 3 equals minimum value of 3") }, }, { @@ -219,7 +220,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithExclusiveMinimumFlag(true), schematest.WithMinimum(3)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minimum: integer 3 equals minimum value of 3 and exclusive minimum is true") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minimum: integer 3 equals minimum value of 3 and exclusive minimum is true") }, }, { @@ -236,7 +237,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithExclusiveMaximum(3)), d: 4, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMaximum: integer 4 exceeds maximum value of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMaximum: integer 4 exceeds maximum value of 3") }, }, { @@ -244,7 +245,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithExclusiveMaximum(3)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMaximum: integer 3 equals maximum value of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMaximum: integer 3 equals maximum value of 3") }, }, { @@ -261,7 +262,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithExclusiveMaximumFlag(true), schematest.WithMaximum(3)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: integer 3 equals maximum value of 3 and exclusive maximum is true") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: integer 3 equals maximum value of 3 and exclusive maximum is true") }, }, { @@ -278,7 +279,7 @@ func TestParse_Integer(t *testing.T) { s: schematest.New("integer", schematest.WithConst(10)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/const: value '3' does not match const '10'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/const: value '3' does not match const '10'") }, }, { diff --git a/schema/json/parser/parser_number_test.go b/schema/json/parser/parser_number_test.go index 9ea95900f..8abdcbdb5 100644 --- a/schema/json/parser/parser_number_test.go +++ b/schema/json/parser/parser_number_test.go @@ -1,12 +1,13 @@ package parser_test import ( - "github.com/stretchr/testify/require" "math" "mokapi/schema/json/parser" "mokapi/schema/json/schema" "mokapi/schema/json/schema/schematest" "testing" + + "github.com/stretchr/testify/require" ) func TestParse_Number(t *testing.T) { @@ -24,7 +25,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number"), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected number but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected number but got string") }, }, { @@ -32,7 +33,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number"), d: map[string]interface{}{}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected number but got object") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected number but got object") }, }, { @@ -40,7 +41,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithFormat("float")), d: math.MaxFloat64, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: number '1.7976931348623157e+308' does not match format 'float'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: number '1.7976931348623157e+308' does not match format 'float'") }, }, { @@ -106,7 +107,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number"), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected number but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected number but got string") }, convertStringToNumber: true, @@ -116,7 +117,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithFormat("float")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected number but got string") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected number but got string") }, convertStringToNumber: true, @@ -137,7 +138,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithMultipleOf(3.5)), d: 9.5, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/multipleOf: number 9.5 is not a multiple of 3.5") + require.EqualError(t, err, "Validation error count 1:\n\t- #/multipleOf: number 9.5 is not a multiple of 3.5") }, }, { @@ -154,7 +155,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithMinimum(3.5)), d: 1, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minimum: number 1 is less than minimum value of 3.5") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minimum: number 1 is less than minimum value of 3.5") }, }, { @@ -171,7 +172,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithMaximum(3.5)), d: 4, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: number 4 exceeds maximum value of 3.5") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: number 4 exceeds maximum value of 3.5") }, }, { @@ -188,7 +189,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithExclusiveMinimum(3.5)), d: 3.0, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMinimum: number 3 is less than minimum value of 3.5") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMinimum: number 3 is less than minimum value of 3.5") }, }, { @@ -196,7 +197,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithExclusiveMinimum(3.5)), d: 3.5, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMinimum: number 3.5 equals minimum value of 3.5") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMinimum: number 3.5 equals minimum value of 3.5") }, }, { @@ -213,7 +214,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithExclusiveMinimumFlag(true), schematest.WithMinimum(3)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minimum: number 3 equals minimum value of 3 and exclusive minimum is true") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minimum: number 3 equals minimum value of 3 and exclusive minimum is true") }, }, { @@ -230,7 +231,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithExclusiveMaximum(3)), d: 4, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMaximum: number 4 exceeds maximum value of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMaximum: number 4 exceeds maximum value of 3") }, }, { @@ -238,7 +239,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithExclusiveMaximum(3)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/exclusiveMaximum: number 3 equals maximum value of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/exclusiveMaximum: number 3 equals maximum value of 3") }, }, { @@ -255,7 +256,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithExclusiveMaximumFlag(true), schematest.WithMaximum(3)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maximum: number 3 equals maximum value of 3 and exclusive maximum is true") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maximum: number 3 equals maximum value of 3 and exclusive maximum is true") }, }, { @@ -272,7 +273,7 @@ func TestParse_Number(t *testing.T) { s: schematest.New("number", schematest.WithConst(10.5)), d: 3, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/const: value '3' does not match const '10.5'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/const: value '3' does not match const '10.5'") }, }, { diff --git a/schema/json/parser/parser_object_test.go b/schema/json/parser/parser_object_test.go index 0a1b0cb8b..dcdfd693c 100644 --- a/schema/json/parser/parser_object_test.go +++ b/schema/json/parser/parser_object_test.go @@ -24,7 +24,7 @@ func TestParser_ParseObject(t *testing.T) { data: 12, schema: schematest.New("object"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected object but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected object but got integer") }, }, { @@ -32,7 +32,7 @@ func TestParser_ParseObject(t *testing.T) { data: nil, schema: schematest.New("object"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected object but got null") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected object but got null") }, }, { @@ -40,7 +40,7 @@ func TestParser_ParseObject(t *testing.T) { data: map[string]interface{}{"foo": 1234}, schema: schematest.New("object", schematest.WithProperty("foo", schematest.New("string"))), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/foo/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/foo/type: invalid type, expected string but got integer") }, }, { @@ -51,7 +51,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithProperty("bar", schematest.New("string")), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/foo/type: invalid type, expected string but got integer\n\t- #/bar/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 2:\n\t- #/foo/type: invalid type, expected string but got integer\n\t- #/bar/type: invalid type, expected string but got integer") }, }, { @@ -82,7 +82,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithPatternProperty("^S_", schematest.New("string")), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/patternProperties/^S_/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/patternProperties/^S_/type: invalid type, expected string but got integer") }, }, { @@ -104,7 +104,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithFreeForm(false), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/additionalProperties: property 'foo' not defined and the schema does not allow additional properties") + require.EqualError(t, err, "Validation error count 1:\n\t- #/additionalProperties: property 'foo' not defined and the schema does not allow additional properties") }, }, { @@ -138,7 +138,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithAdditionalProperties(schematest.New("string")), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/additionalProperties/number2/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/additionalProperties/number2/type: invalid type, expected string but got integer") }, }, { @@ -191,7 +191,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithAdditionalProperties(schematest.New("string")), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/additionalProperties/keyword/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/additionalProperties/keyword/type: invalid type, expected string but got integer") }, }, { @@ -201,7 +201,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithProperty("foo", schematest.New("string")), schematest.WithRequired("foo")), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/required: required properties are missing: foo") + require.EqualError(t, err, "Validation error count 1:\n\t- #/required: required properties are missing: foo") }, }, { @@ -222,7 +222,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithPropertyNames(schematest.NewTypes(nil, schematest.WithPattern("^[a-z]+"))), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/propertyNames/pattern: string '1_foo' does not match regex pattern '^[a-z]+'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/propertyNames/pattern: string '1_foo' does not match regex pattern '^[a-z]+'") }, }, { @@ -243,7 +243,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithMinProperties(2), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minProperties: property count 1 is less than minimum count of 2") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minProperties: property count 1 is less than minimum count of 2") }, }, { @@ -264,7 +264,7 @@ func TestParser_ParseObject(t *testing.T) { schematest.WithMaxProperties(1), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxProperties: property count 2 exceeds maximum count of 1") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxProperties: property count 2 exceeds maximum count of 1") }, }, { @@ -283,7 +283,7 @@ func TestParser_ParseObject(t *testing.T) { schema: schematest.New("object", schematest.WithConst(map[string]interface{}{"foo": "bar"})), data: map[string]interface{}{"foo": "foobar"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/const: value '{foo: foobar}' does not match const '{foo: bar}'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/const: value '{foo: foobar}' does not match const '{foo: bar}'") }, }, { @@ -300,7 +300,7 @@ func TestParser_ParseObject(t *testing.T) { schema: schematest.New("object", schematest.WithDependentRequired("foo", "bar")), data: map[string]interface{}{"foo": "foobar"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/dependentRequired: dependencies for property 'foo' failed: missing required keys: bar.") + require.EqualError(t, err, "Validation error count 1:\n\t- #/dependentRequired: dependencies for property 'foo' failed: missing required keys: bar.") }, }, { @@ -324,7 +324,7 @@ func TestParser_ParseObject(t *testing.T) { ), data: map[string]interface{}{"foo": "foobar"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/dependentSchemas/foo/required: required properties are missing: bar") + require.EqualError(t, err, "Validation error count 1:\n\t- #/dependentSchemas/foo/required: required properties are missing: bar") }, }, { @@ -359,7 +359,7 @@ func TestParser_ParseObject(t *testing.T) { ), data: map[string]interface{}{"foo": "bar", "bar": "abc"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/then/bar/pattern: does not match schema: string 'abc' does not match regex pattern '[0-9]+'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/then/bar/pattern: does not match schema: string 'abc' does not match regex pattern '[0-9]+'") }, }, { @@ -418,7 +418,7 @@ func TestParser_ParseObject(t *testing.T) { ), data: map[string]interface{}{"foo": "bar2", "zzz": "abc"}, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/else/zzz/pattern: does not match schema: string 'abc' does not match regex pattern '[0-9]+'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/else/zzz/pattern: does not match schema: string 'abc' does not match regex pattern '[0-9]+'") }, }, { diff --git a/schema/json/parser/parser_string_test.go b/schema/json/parser/parser_string_test.go index 3c5ddbb9f..69d4993ef 100644 --- a/schema/json/parser/parser_string_test.go +++ b/schema/json/parser/parser_string_test.go @@ -1,12 +1,13 @@ package parser_test import ( - "github.com/stretchr/testify/require" "mokapi/schema/json/parser" "mokapi/schema/json/schema" "mokapi/schema/json/schema/schematest" "mokapi/version" "testing" + + "github.com/stretchr/testify/require" ) func TestParse_String(t *testing.T) { @@ -50,7 +51,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string"), d: 12, test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected string but got integer") }, }, { @@ -76,7 +77,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithMaxLength(2)), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxLength: string 'foo' exceeds maximum of 2") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxLength: string 'foo' exceeds maximum of 2") }, }, { @@ -93,7 +94,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithMinLength(4)), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/minLength: string 'foo' is less than minimum of 4") + require.EqualError(t, err, "Validation error count 1:\n\t- #/minLength: string 'foo' is less than minimum of 4") }, }, { @@ -110,7 +111,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithPattern("[")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/pattern: validate string 'foo' with regex pattern '[' failed: error parsing regex: missing closing ]") + require.EqualError(t, err, "Validation error count 1:\n\t- #/pattern: validate string 'foo' with regex pattern '[' failed: error parsing regex: missing closing ]") }, }, { @@ -118,7 +119,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithPattern("[0-9]{4}")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/pattern: string 'foo' does not match regex pattern '[0-9]{4}'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/pattern: string 'foo' does not match regex pattern '[0-9]{4}'") }, }, { @@ -126,7 +127,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithPattern("[0-9]*"), schematest.WithMaxLength(3)), d: "1234", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxLength: string '1234' exceeds maximum of 3") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxLength: string '1234' exceeds maximum of 3") }, }, { @@ -143,7 +144,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("date")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'foo' does not match format 'date'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'foo' does not match format 'date'") }, }, { @@ -160,7 +161,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("date-time")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'foo' does not match format 'date-time'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'foo' does not match format 'date-time'") }, }, { @@ -177,7 +178,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("time")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'foo' does not match format 'time'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'foo' does not match format 'time'") }, }, { @@ -194,7 +195,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("duration")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'foo' does not match format 'duration'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'foo' does not match format 'duration'") }, }, { @@ -211,7 +212,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("email")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'foo' does not match format 'email'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'foo' does not match format 'email'") }, }, { @@ -228,7 +229,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("uuid")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'foo' does not match format 'uuid'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'foo' does not match format 'uuid'") }, }, { @@ -245,7 +246,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("ipv4")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'foo' does not match format 'ipv4'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'foo' does not match format 'ipv4'") }, }, { @@ -253,7 +254,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("ipv4")), d: "1080:0:0:0:8:800:200C:417A", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string '1080:0:0:0:8:800:200C:417A' does not match format 'ipv4'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string '1080:0:0:0:8:800:200C:417A' does not match format 'ipv4'") }, }, { @@ -270,7 +271,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("ipv6")), d: "foo", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string 'foo' does not match format 'ipv6'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string 'foo' does not match format 'ipv6'") }, }, { @@ -278,7 +279,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithFormat("ipv6")), d: "192.168.1.1", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/format: string '192.168.1.1' does not match format 'ipv6'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/format: string '192.168.1.1' does not match format 'ipv6'") }, }, { @@ -306,7 +307,7 @@ func TestParse_String(t *testing.T) { s: schematest.New("string", schematest.WithConst("foo")), d: "bar", test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/const: value 'bar' does not match const 'foo'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/const: value 'bar' does not match const 'foo'") }, }, { diff --git a/schema/json/parser/parser_test.go b/schema/json/parser/parser_test.go index 900dfdcf0..e1d2d06cf 100644 --- a/schema/json/parser/parser_test.go +++ b/schema/json/parser/parser_test.go @@ -64,7 +64,7 @@ func TestParser_NoType(t *testing.T) { schematest.WithMaxLength(10), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/maxLength: string 'foobar1234567' exceeds maximum of 10") + require.EqualError(t, err, "Validation error count 1:\n\t- #/maxLength: string 'foobar1234567' exceeds maximum of 10") }, }, { @@ -72,7 +72,7 @@ func TestParser_NoType(t *testing.T) { data: nil, schema: schematest.New("string"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected string but got null") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected string but got null") }, }, { @@ -89,7 +89,7 @@ func TestParser_NoType(t *testing.T) { data: "foo", schema: schematest.New("string", schematest.WithConst("bar")), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/const: value 'foo' does not match const 'bar'") + require.EqualError(t, err, "Validation error count 1:\n\t- #/const: value 'foo' does not match const 'bar'") }, }, { @@ -97,7 +97,7 @@ func TestParser_NoType(t *testing.T) { data: "foo", schema: schematest.New("string", schematest.WithConst(3)), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 2:\n\t- #/const: const value does not match schema\n\t\t- #/const/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 2:\n\t- #/const: const value does not match schema\n\t\t- #/const/type: invalid type, expected string but got integer") }, }, { @@ -105,7 +105,7 @@ func TestParser_NoType(t *testing.T) { data: "foo", schema: schematest.NewTypes(nil, schematest.WithNot(schematest.New("string"))), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/not: is valid against schema") + require.EqualError(t, err, "Validation error count 1:\n\t- #/not: is valid against schema") }, }, { @@ -126,7 +126,7 @@ func TestParser_NoType(t *testing.T) { ), ), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/items/0/foo/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/items/0/foo/type: invalid type, expected string but got integer") }, }, } @@ -165,7 +165,7 @@ func TestParser_Null(t *testing.T) { data: 123, schema: schematest.New("null"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected null but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected null but got integer") }, }, { @@ -200,7 +200,7 @@ func TestParser_Null(t *testing.T) { data: 123, schema: schematest.NewTypes([]string{"null", "string"}), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected [null, string] but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected [null, string] but got integer") }, }, { @@ -208,7 +208,7 @@ func TestParser_Null(t *testing.T) { data: 123, schema: schematest.NewTypes([]string{"string", "null"}), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected [string, null] but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected [string, null] but got integer") }, }, { @@ -234,7 +234,7 @@ func TestParser_Null(t *testing.T) { data: map[string]interface{}{"foo": 123}, schema: schematest.NewTypes([]string{"null", "object"}, schematest.WithProperty("foo", schematest.New("string"))), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/foo/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/foo/type: invalid type, expected string but got integer") }, }, { @@ -242,7 +242,7 @@ func TestParser_Null(t *testing.T) { data: map[string]interface{}{"foo": 123}, schema: schematest.NewTypes([]string{"object", "null"}, schematest.WithProperty("foo", schematest.New("string"))), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/foo/type: invalid type, expected string but got integer") + require.EqualError(t, err, "Validation error count 1:\n\t- #/foo/type: invalid type, expected string but got integer") }, }, { @@ -259,7 +259,7 @@ func TestParser_Null(t *testing.T) { data: map[string]interface{}{"foo": nil}, schema: schematest.New("null"), test: func(t *testing.T, v interface{}, err error) { - require.EqualError(t, err, "error count 1:\n\t- #/type: invalid type, expected null but got object") + require.EqualError(t, err, "Validation error count 1:\n\t- #/type: invalid type, expected null but got object") }, }, } diff --git a/webui/e2e/mocks/http_handler.js b/webui/e2e/mocks/http_handler.js index 2ae20cddc..d6a73af2e 100644 --- a/webui/e2e/mocks/http_handler.js +++ b/webui/e2e/mocks/http_handler.js @@ -746,6 +746,7 @@ function getSearchResults() { type: 'HTTP', domain: 'Swagger Petstore', title: "/pet", + description: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam...', fragments: ['Everything', 'store'], params: { type: 'http', diff --git a/webui/package-lock.json b/webui/package-lock.json index f121dfc51..5de1978d8 100644 --- a/webui/package-lock.json +++ b/webui/package-lock.json @@ -34,22 +34,22 @@ "ncp": "^2.0.0", "nodemailer": "^8.0.7", "vue": "^3.5.34", - "vue-router": "^5.0.6", + "vue-router": "^5.0.7", "vue3-ace-editor": "^2.2.4", "whatwg-mimetype": "^5.0.0", "xml-formatter": "^3.7.0" }, "devDependencies": { - "@playwright/test": "^1.59.1", + "@playwright/test": "^1.60.0", "@rushstack/eslint-patch": "^1.16.1", "@types/js-yaml": "^4.0.9", "@types/markdown-it-container": "^4.0.0", - "@types/node": "^25.6.2", - "@vitejs/plugin-vue": "^6.0.6", + "@types/node": "^25.8.0", + "@vitejs/plugin-vue": "^6.0.7", "@vue/eslint-config-prettier": "^10.2.0", "@vue/eslint-config-typescript": "^14.7.0", "@vue/tsconfig": "^0.9.1", - "eslint": "^10.2.1", + "eslint": "^10.3.0", "eslint-plugin-vue": "^10.9.1", "npm-run-all": "^4.1.5", "prettier": "^3.8.3", @@ -60,19 +60,66 @@ } }, "node_modules/@babel/generator": { - "version": "7.28.6", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.28.6.tgz", - "integrity": "sha512-lOoVRwADj8hjf7al89tvQ2a1lf53Z+7tiXMgpZJL3maQPDxh0DgLMN62B2MKUOFcoodBHLMbDM6WAbKgNy5Suw==", + "version": "8.0.0-rc.5", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-8.0.0-rc.5.tgz", + "integrity": "sha512-nFZPWz3FHIS7y6rMIVoa/WBwjdutfIaRJIBQjzn+t3RnecZoRNlGmGcyR2wb0T/IgSd50Kz/6dG8/LvMCRunjg==", "license": "MIT", "dependencies": { - "@babel/parser": "^7.28.6", - "@babel/types": "^7.28.6", + "@babel/parser": "^8.0.0-rc.5", + "@babel/types": "^8.0.0-rc.5", "@jridgewell/gen-mapping": "^0.3.12", "@jridgewell/trace-mapping": "^0.3.28", + "@types/jsesc": "^2.5.0", "jsesc": "^3.0.2" }, "engines": { - "node": ">=6.9.0" + "node": "^22.18.0 || >=24.11.0" + } + }, + "node_modules/@babel/generator/node_modules/@babel/helper-string-parser": { + "version": "8.0.0-rc.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-8.0.0-rc.5.tgz", + "integrity": "sha512-sN7R8rBvDurfaziNfDEIjIntlazmlkCDGO4SNl2RJ3wRCn+QxspLV7hzYAE8WWVd2joVuT8sUxeePdLp2idI1A==", + "license": "MIT", + "engines": { + "node": "^22.18.0 || >=24.11.0" + } + }, + "node_modules/@babel/generator/node_modules/@babel/helper-validator-identifier": { + "version": "8.0.0-rc.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-8.0.0-rc.5.tgz", + "integrity": "sha512-ehJDxHvtbZ85RtX/L2fi0h9AGsBNqB5Euv1EB8RMAvGYvD+2X+QbpzzOpbklnNXO+WSZJNOaetw2BBj27xsWVg==", + "license": "MIT", + "engines": { + "node": "^22.18.0 || >=24.11.0" + } + }, + "node_modules/@babel/generator/node_modules/@babel/parser": { + "version": "8.0.0-rc.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-8.0.0-rc.5.tgz", + "integrity": "sha512-/Mfg83rK3+jsRbl4Vbd0jqxc6M1A1/WNFtgrowRM1unEsD3XcNnrBdMM0JWakd0/RN9lseQKwPduW1TiEwKOlQ==", + "license": "MIT", + "dependencies": { + "@babel/types": "^8.0.0-rc.5" + }, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": "^22.18.0 || >=24.11.0" + } + }, + "node_modules/@babel/generator/node_modules/@babel/types": { + "version": "8.0.0-rc.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-8.0.0-rc.5.tgz", + "integrity": "sha512-JeSVu/m8x/zpp4CLjYHVNXuhEyOkhPXuxM8YOXjh6L4LlvQNKuUNOTo5KdBuKAcTDHw8DquToTaEkhsBqPXOaA==", + "license": "MIT", + "dependencies": { + "@babel/helper-string-parser": "^8.0.0-rc.5", + "@babel/helper-validator-identifier": "^8.0.0-rc.5" + }, + "engines": { + "node": "^22.18.0 || >=24.11.0" } }, "node_modules/@babel/helper-string-parser": { @@ -433,13 +480,13 @@ } }, "node_modules/@playwright/test": { - "version": "1.59.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.59.1.tgz", - "integrity": "sha512-PG6q63nQg5c9rIi4/Z5lR5IVF7yU5MqmKaPOe0HSc0O2cX1fPi96sUQu5j7eo4gKCkB2AnNGoWt7y4/Xx3Kcqg==", + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.60.0.tgz", + "integrity": "sha512-O71yZIbAh/PxDMNGns37GHBIfrVkEVyn+AXyIa5dOTfb4/xNvRWV+Vv/NMbNCtODB/pO7vLlF2OTmMVLhmr7Ag==", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright": "1.59.1" + "playwright": "1.60.0" }, "bin": { "playwright": "cli.js" @@ -716,9 +763,9 @@ } }, "node_modules/@rolldown/pluginutils": { - "version": "1.0.0-rc.13", - "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-rc.13.tgz", - "integrity": "sha512-3ngTAv6F/Py35BsYbeeLeecvhMKdsKm4AoOETVhAA+Qc8nrA2I0kF7oa93mE9qnIurngOSpMnQ0x2nQY2FPviA==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", "dev": true, "license": "MIT" }, @@ -799,6 +846,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/jsesc": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/@types/jsesc/-/jsesc-2.5.1.tgz", + "integrity": "sha512-9VN+6yxLOPLOav+7PwjZbxiID2bVaeq0ED4qSQmdQTdjnXJSaCVKTR58t15oqH1H5t8Ng2ZX1SabJVoN9Q34bw==", + "license": "MIT" + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -848,12 +901,12 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "25.6.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-25.6.2.tgz", - "integrity": "sha512-sokuT28dxf9JT5Kady1fsXOvI4HVpjZa95NKT5y9PNTIrs2AsobR4GFAA90ZG8M+nxVRLysCXsVj6eGC7Vbrlw==", + "version": "25.8.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.8.0.tgz", + "integrity": "sha512-TCFSk8IZh+iLX1xtksoBVtdmgL+1IX0fC9BeU4QqFSuNdN/K+HUlhqOzEmSYYpZUVsLYcPqc9KX+60iDuninSQ==", "license": "MIT", "dependencies": { - "undici-types": "~7.19.0" + "undici-types": ">=7.24.0 <7.24.7" } }, "node_modules/@types/nodemailer": { @@ -1133,13 +1186,13 @@ } }, "node_modules/@vitejs/plugin-vue": { - "version": "6.0.6", - "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.6.tgz", - "integrity": "sha512-u9HHgfrq3AjXlysn0eINFnWQOJQLO9WN6VprZ8FXl7A2bYisv3Hui9Ij+7QZ41F/WYWarHjwBbXtD7dKg3uxbg==", + "version": "6.0.7", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.7.tgz", + "integrity": "sha512-km+p+XdSz9Sxm5rqUbqcSfZYaAniKxWBj1KURl+Jr7UaPvvX7BmaWMdP69I5rrFDeQGyxAG7NXdc57vz+snhWg==", "dev": true, "license": "MIT", "dependencies": { - "@rolldown/pluginutils": "1.0.0-rc.13" + "@rolldown/pluginutils": "^1.0.1" }, "engines": { "node": "^20.19.0 || >=22.12.0" @@ -1256,37 +1309,31 @@ } }, "node_modules/@vue/devtools-api": { - "version": "8.0.6", - "resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-8.0.6.tgz", - "integrity": "sha512-+lGBI+WTvJmnU2FZqHhEB8J1DXcvNlDeEalz77iYgOdY1jTj1ipSBaKj3sRhYcy+kqA8v/BSuvOz1XJucfQmUA==", + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-8.1.2.tgz", + "integrity": "sha512-vA0O112YqyDuNA1s7Yb2gCgToQ/OxOWiFDO5ThLCcDy0ldHnSd1dUTaSYhOldbqoNgumE4dxtGAoAaSUKUD1Zg==", "license": "MIT", "dependencies": { - "@vue/devtools-kit": "^8.0.6" + "@vue/devtools-kit": "^8.1.2" } }, "node_modules/@vue/devtools-kit": { - "version": "8.0.6", - "resolved": "https://registry.npmjs.org/@vue/devtools-kit/-/devtools-kit-8.0.6.tgz", - "integrity": "sha512-9zXZPTJW72OteDXeSa5RVML3zWDCRcO5t77aJqSs228mdopYj5AiTpihozbsfFJ0IodfNs7pSgOGO3qfCuxDtw==", + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/@vue/devtools-kit/-/devtools-kit-8.1.2.tgz", + "integrity": "sha512-f75/upc+GCyjXErpgPGz4582ujS0L/adAltGy+tqXMGUJpgAcfGr6CxnnhpZY8BHuMYt6KpbF8uaFrrQG66rGQ==", "license": "MIT", "dependencies": { - "@vue/devtools-shared": "^8.0.6", + "@vue/devtools-shared": "^8.1.2", "birpc": "^2.6.1", "hookable": "^5.5.3", - "mitt": "^3.0.1", - "perfect-debounce": "^2.0.0", - "speakingurl": "^14.0.1", - "superjson": "^2.2.2" + "perfect-debounce": "^2.0.0" } }, "node_modules/@vue/devtools-shared": { - "version": "8.0.6", - "resolved": "https://registry.npmjs.org/@vue/devtools-shared/-/devtools-shared-8.0.6.tgz", - "integrity": "sha512-Pp1JylTqlgMJvxW6MGyfTF8vGvlBSCAvMFaDCYa82Mgw7TT5eE5kkHgDvmOGHWeJE4zIDfCpCxHapsK2LtIAJg==", - "license": "MIT", - "dependencies": { - "rfdc": "^1.4.1" - } + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/@vue/devtools-shared/-/devtools-shared-8.1.2.tgz", + "integrity": "sha512-X9RyVFYAdkBe4IUf5v48TxBF/6QPmF8CmWrDAjXzfUHrgQ/HGfTC1A6TqgXqZ03ye66l3AD51BAGD69IvKM9sw==", + "license": "MIT" }, "node_modules/@vue/eslint-config-prettier": { "version": "10.2.0", @@ -1983,21 +2030,6 @@ "node": ">=6.6.0" } }, - "node_modules/copy-anything": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/copy-anything/-/copy-anything-4.0.5.tgz", - "integrity": "sha512-7Vv6asjS4gMOuILabD3l739tsaxFQmC+a7pLZm02zyvs8p977bL3zEgq3yDk5rn9B0PbYgIv++jmHcuUab4RhA==", - "license": "MIT", - "dependencies": { - "is-what": "^5.2.0" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/mesqueeb" - } - }, "node_modules/cors": { "version": "2.8.6", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", @@ -2844,9 +2876,9 @@ } }, "node_modules/eslint": { - "version": "10.2.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.2.1.tgz", - "integrity": "sha512-wiyGaKsDgqXvF40P8mDwiUp/KQjE1FdrIEJsM8PZ3XCiniTMXS3OHWWUe5FI5agoCnr8x4xPrTDZuxsBlNHl+Q==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.3.0.tgz", + "integrity": "sha512-XbEXaRva5cF0ZQB8w6MluHA0kZZfV2DuCMJ3ozyEOHLwDpZX2Lmm/7Pp0xdJmI0GL1W05VH5VwIFHEm1Vcw2gw==", "dev": true, "license": "MIT", "dependencies": { @@ -4251,18 +4283,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-what": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/is-what/-/is-what-5.5.0.tgz", - "integrity": "sha512-oG7cgbmg5kLYae2N5IVd3jm2s+vldjxJzK1pcu9LfpGuQ93MQSzo0okvRna+7y5ifrD+20FE8FvjusyGaz14fw==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/mesqueeb" - } - }, "node_modules/isarray": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", @@ -4909,12 +4929,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/mitt": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz", - "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==", - "license": "MIT" - }, "node_modules/mlly": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.8.0.tgz", @@ -5602,13 +5616,13 @@ } }, "node_modules/playwright": { - "version": "1.59.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.59.1.tgz", - "integrity": "sha512-C8oWjPR3F81yljW9o5OxcWzfh6avkVwDD2VYdwIGqTkl+OGFISgypqzfu7dOe4QNLL2aqcWBmI3PMtLIK233lw==", + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.60.0.tgz", + "integrity": "sha512-hheHdokM8cdqCb0lcE3s+zT4t4W+vvjpGxsZlDnikarzx8tSzMebh3UiFtgqwFwnTnjYQcsyMF8ei2mCO/tpeA==", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.59.1" + "playwright-core": "1.60.0" }, "bin": { "playwright": "cli.js" @@ -5621,9 +5635,9 @@ } }, "node_modules/playwright-core": { - "version": "1.59.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.59.1.tgz", - "integrity": "sha512-HBV/RJg81z5BiiZ9yPzIiClYV/QMsDCKUyogwH9p3MCP6IYjUFu/MActgYAvK0oWyV9NlwM3GLBjADyWgydVyg==", + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.60.0.tgz", + "integrity": "sha512-9bW6zvX/m0lEbgTKJ6YppOKx8H3VOPBMOCFh2irXFOT4BbHgrx5hPjwJYLT40Lu+4qtD36qKc/Hn56StUW57IA==", "dev": true, "license": "Apache-2.0", "bin": { @@ -6509,15 +6523,6 @@ "dev": true, "license": "CC0-1.0" }, - "node_modules/speakingurl": { - "version": "14.0.1", - "resolved": "https://registry.npmjs.org/speakingurl/-/speakingurl-14.0.1.tgz", - "integrity": "sha512-1POYv7uv2gXoyGFpBCmpDVSNV74IfsWlDW216UPjbWufNf+bSU6GdbDsxdcxtfwb4xlI3yxzOTKClUosxARYrQ==", - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/split2": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", @@ -6653,18 +6658,6 @@ "node": ">=4" } }, - "node_modules/superjson": { - "version": "2.2.6", - "resolved": "https://registry.npmjs.org/superjson/-/superjson-2.2.6.tgz", - "integrity": "sha512-H+ue8Zo4vJmV2nRjpx86P35lzwDT3nItnIsocgumgr0hHMQ+ZGq5vrERg9kJBo5AWGmxZDhzDo+WVIJqkB0cGA==", - "license": "MIT", - "dependencies": { - "copy-anything": "^4" - }, - "engines": { - "node": ">=16" - } - }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", @@ -6960,9 +6953,9 @@ } }, "node_modules/undici-types": { - "version": "7.19.2", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.19.2.tgz", - "integrity": "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==", + "version": "7.24.6", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz", + "integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==", "license": "MIT" }, "node_modules/unicorn-magic": { @@ -7248,14 +7241,14 @@ } }, "node_modules/vue-router": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-5.0.6.tgz", - "integrity": "sha512-9+kmUTGbKMyW9Asoy98IXXYIzrTMT7JDAdpDDeEkorHvybpUvBI2wsrSM5jFOXrFydpzRFJ9vAh+80DN2PGu9w==", + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-5.0.7.tgz", + "integrity": "sha512-dqfk8kvRbCutmCOCj/XLDqDEYxc1wBdAOGLuVy5M93ifYMsBd5fIjfaPN4tQAbxr5IprdBDIox1gr4wYyOx/SA==", "license": "MIT", "dependencies": { - "@babel/generator": "^7.28.6", + "@babel/generator": "^8.0.0-rc.4", "@vue-macros/common": "^3.1.1", - "@vue/devtools-api": "^8.0.6", + "@vue/devtools-api": "^8.1.1", "ast-walker-scope": "^0.8.3", "chokidar": "^5.0.0", "json5": "^2.2.3", @@ -7276,9 +7269,9 @@ }, "peerDependencies": { "@pinia/colada": ">=0.21.2", - "@vue/compiler-sfc": "^3.5.17", + "@vue/compiler-sfc": "^3.5.34", "pinia": "^3.0.4", - "vue": "^3.5.0" + "vue": "^3.5.34" }, "peerDependenciesMeta": { "@pinia/colada": { diff --git a/webui/package.json b/webui/package.json index e74ffd2dd..607589575 100644 --- a/webui/package.json +++ b/webui/package.json @@ -43,22 +43,22 @@ "ncp": "^2.0.0", "nodemailer": "^8.0.7", "vue": "^3.5.34", - "vue-router": "^5.0.6", + "vue-router": "^5.0.7", "vue3-ace-editor": "^2.2.4", "whatwg-mimetype": "^5.0.0", "xml-formatter": "^3.7.0" }, "devDependencies": { - "@playwright/test": "^1.59.1", + "@playwright/test": "^1.60.0", "@rushstack/eslint-patch": "^1.16.1", "@types/js-yaml": "^4.0.9", "@types/markdown-it-container": "^4.0.0", - "@types/node": "^25.6.2", - "@vitejs/plugin-vue": "^6.0.6", + "@types/node": "^25.8.0", + "@vitejs/plugin-vue": "^6.0.7", "@vue/eslint-config-prettier": "^10.2.0", "@vue/eslint-config-typescript": "^14.7.0", "@vue/tsconfig": "^0.9.1", - "eslint": "^10.2.1", + "eslint": "^10.3.0", "eslint-plugin-vue": "^10.9.1", "npm-run-all": "^4.1.5", "prettier": "^3.8.3", diff --git a/webui/src/components/dashboard/Search.vue b/webui/src/components/dashboard/Search.vue index 586aa88a5..bcadfb0d2 100644 --- a/webui/src/components/dashboard/Search.vue +++ b/webui/src/components/dashboard/Search.vue @@ -18,7 +18,7 @@ const errorMessage = ref() const searchResult = ref(); const maxVisiblePages = 10 // max pages in pagination const showTips = ref(false) -const facets = ref<{ [name: string]: string | undefined}>({}) +const facets = ref<{ [name: string]: string | undefined }>({}) const loading = useProgressiveLoading() const pageNumber = computed(() => { @@ -77,8 +77,8 @@ async function navigateToSearchResult(result: any) { } return router.push({ name: 'kafkaService', params: result.params }) case 'mail': - if (result.params.mailbox) { - return router.push({ name: 'smtpMailbox', params: { ...{ name: result.params.mailbox }, ...result.params } }) + if (result.params.mailbox) { + return router.push({ name: 'smtpMailbox', params: { ...{ name: result.params.mailbox }, ...result.params } }) } return router.push({ name: 'mailService', params: result.params }) case 'ldap': @@ -105,7 +105,7 @@ function title(result: SearchItem) { case "Config": const n = result.title.length if (n > 55) { - return '...' + result.title.slice(n-55) + return '...' + result.title.slice(n - 55) } break case "Event": @@ -159,7 +159,7 @@ async function search_clicked() { } else { delete newQuery.q } - + if (pageIndex.value) { newQuery.index = pageIndex.value.toString() } else { @@ -210,11 +210,11 @@ async function search() { errorMessage.value = undefined const res = await fetch(transformPath(path)) .then(async (res) => { - if (!res.ok) { - const data = await res.json() - throw new Error(data.message) - } - return res.json() + if (!res.ok) { + const data = await res.json() + throw new Error(data.message) + } + return res.json() }) .then(res => { loading.stop() @@ -243,146 +243,207 @@ function facetTitle(s: string) {
-