From fe5cc78a6c2650761324664cf1ef467597bc2598 Mon Sep 17 00:00:00 2001 From: dieg0code Date: Sun, 8 Dec 2024 13:17:51 -0300 Subject: [PATCH] fix: char length linter error in jsconschema test --- jsonschema/json_test.go | 36 +++++++++++++++++------------------- test.mp3 | 1 - 2 files changed, 17 insertions(+), 20 deletions(-) delete mode 100644 test.mp3 diff --git a/jsonschema/json_test.go b/jsonschema/json_test.go index 2dd172394..2513ec15b 100644 --- a/jsonschema/json_test.go +++ b/jsonschema/json_test.go @@ -19,8 +19,8 @@ func TestDefinition_GenerateSchemaForType(t *testing.T) { MenuItems []MenuItem `json:"menu_items" description:"List of menu items ordered by the user" required:"true"` DeliveryAddress string `json:"delivery_address" description:"Delivery address for the order" required:"true"` UserName string `json:"user_name" description:"Name of the user placing the order" required:"true"` - PhoneNumber string `json:"phone_number" description:"Phone number of the user placing the order" required:"true"` - PaymentMethod string `json:"payment_method" description:"Payment method for the order, only transfer or cash accepted" required:"true" enum:"cash,transfer,check,card"` + PhoneNumber string `json:"phone_number" description:"Phone number of the user" required:"true"` + PaymentMethod string `json:"payment_method" description:"Payment method" required:"true" enum:"cash,transfer"` } tests := []struct { @@ -100,16 +100,14 @@ func TestDefinition_GenerateSchemaForType(t *testing.T) { }, "phone_number":{ "type":"string", - "description":"Phone number of the user placing the order" + "description":"Phone number of the user" }, "payment_method":{ "type":"string", - "description":"Payment method for the order, only transfer or cash accepted", + "description":"Payment method", "enum":[ "cash", - "transfer", - "check", - "card" + "transfer" ] } }, @@ -163,19 +161,21 @@ func TestDefinition_SchemaGenerationComparison(t *testing.T) { MenuItems []MenuItem `json:"menu_items" description:"List of menu items ordered by the user" required:"true"` DeliveryAddress string `json:"delivery_address" description:"Delivery address for the order" required:"true"` UserName string `json:"user_name" description:"Name of the user placing the order" required:"true"` - PhoneNumber string `json:"phone_number" description:"Phone number of the user placing the order" required:"true"` - PaymentMethod string `json:"payment_method" description:"Payment method for the order" required:"true" enum:"cash,transfer"` + PhoneNumber string `json:"phone_number" description:"Phone number of the user" required:"true"` + PaymentMethod string `json:"payment_method" description:"Payment method" required:"true" enum:"cash,transfer"` } // Manually created schema to compare against struct-generated schema manualSchema := &jsonschema.Definition{ - Type: jsonschema.Object, - Required: []string{"menu_items", "delivery_address", "user_name", "phone_number", "payment_method"}, + Type: jsonschema.Object, + AdditionalProperties: false, Properties: map[string]jsonschema.Definition{ "menu_items": { - Type: jsonschema.Array, + Type: jsonschema.Array, + Description: "List of menu items ordered by the user", Items: &jsonschema.Definition{ - Type: jsonschema.Object, + Type: jsonschema.Object, + AdditionalProperties: false, Properties: map[string]jsonschema.Definition{ "item_name": { Type: jsonschema.String, @@ -190,10 +190,8 @@ func TestDefinition_SchemaGenerationComparison(t *testing.T) { Description: "Price of the menu item", }, }, - Required: []string{"item_name", "quantity", "price"}, - AdditionalProperties: false, + Required: []string{"item_name", "quantity", "price"}, }, - Description: "List of menu items ordered by the user", }, "delivery_address": { Type: jsonschema.String, @@ -205,15 +203,15 @@ func TestDefinition_SchemaGenerationComparison(t *testing.T) { }, "phone_number": { Type: jsonschema.String, - Description: "Phone number of the user placing the order", + Description: "Phone number of the user", }, "payment_method": { Type: jsonschema.String, - Description: "Payment method for the order", + Description: "Payment method", Enum: []string{"cash", "transfer"}, }, }, - AdditionalProperties: false, + Required: []string{"menu_items", "delivery_address", "user_name", "phone_number", "payment_method"}, } t.Run("Compare Struct-Generated and Manual Schema", func(t *testing.T) { diff --git a/test.mp3 b/test.mp3 deleted file mode 100644 index b6fc4c620..000000000 --- a/test.mp3 +++ /dev/null @@ -1 +0,0 @@ -hello \ No newline at end of file