Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
Vibaswan committed Jan 3, 2024
1 parent 671f43b commit aa84f6c
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 171 deletions.
12 changes: 3 additions & 9 deletions openapiart/tests/new_tests/test_mixed_formats_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,7 @@ def test_integer_datatypes(api):
number_type_object = config.native_features.number_type_object
value = number_type_object._TYPES.get("validate_uint32_1")
assert value.get("format") is not None
# TODO: Uncomment when the backward compatibility support is uncommented from openapiartprotobuf
# and remove the existing validation with int64
# assert value.get("format") == "uint32"
assert value.get("format") == "int64"
assert value.get("format") == "uint32"
number_type_object.validate_uint32_1 = 4261412865

value = number_type_object._TYPES.get("validate_uint32_2")
Expand All @@ -256,10 +253,7 @@ def test_integer_datatypes(api):

value = number_type_object._TYPES.get("validate_uint64_1")
assert value.get("format") is not None
# TODO: Uncomment when the backward compatibility support is uncommented from openapiartprotobuf
# and remove the existing validation with int64
# assert value.get("format") == "uint64"
assert value.get("format") == "int64"
assert value.get("format") == "uint64"
number_type_object.validate_uint64_1 = 9223372036854775807

value = number_type_object._TYPES.get("validate_uint64_2")
Expand Down Expand Up @@ -289,7 +283,7 @@ def test_integer_datatypes(api):

data = config.serialize("dict")
assert isinstance(
data["native_features"]["number_type_object"]["validate_uint32_1"], str
data["native_features"]["number_type_object"]["validate_uint32_1"], int
)
assert isinstance(
data["native_features"]["number_type_object"]["validate_uint32_2"], int
Expand Down
5 changes: 5 additions & 0 deletions openapiart/tests/restructured_config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,14 @@ components:
type: integer
minimum: 0
maximum: 4261412864
format: int64
x-field-uid: 11
integer64_list:
description: int64 type list
type: array
items:
type: integer
format: int64
minimum: 0
maximum: 4261412864
x-field-uid: 12
Expand All @@ -290,6 +292,7 @@ components:
type: integer
minimum: 0
maximum: 4294967295
format: uint32
x-field-uid: 43
validate_uint32_2:
type: integer
Expand All @@ -299,6 +302,7 @@ components:
type: integer
minimum: 0
maximum: 9223372036854775807
format: uint64
x-field-uid: 45
validate_uint64_2:
type: integer
Expand All @@ -317,6 +321,7 @@ components:
type: integer
minimum: 0
maximum: 9223372036854775807
format: int64
x-field-uid: 49
validate_int64_2:
type: integer
Expand Down
24 changes: 10 additions & 14 deletions pkg/new_tests/choice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ func TestChoiceValSchema(t *testing.T) {
// This test checks the values in choice val schema.
// Objective is to check if values are set properly.

api := openapiart.NewApi()
config := api.NewTestConfig()
config := openapiart.NewTestConfig()
mVal := config.ExtendedFeatures().ChoiceVal().MixedVal()

mVal.SetIntVal(34)
Expand All @@ -33,16 +32,15 @@ func TestChoiceValSchema(t *testing.T) {
assert.Equal(t, mVal.BoolVal(), true)
assert.Equal(t, mVal.Choice(), openapiart.MixedValChoice.BOOL_VAL)

err := config.Validate()
_, err := config.Marshal().ToYaml()
assert.Nil(t, err)
}

func TestChoiceHeirarchy(t *testing.T) {

// This test checks choices at different heirarchy

api := openapiart.NewApi()
config := api.NewTestConfig()
config := openapiart.NewTestConfig()
val := config.ExtendedFeatures().ChoiceValNoProperties()

val.IntermediateObj().Leaf().SetName("str1").SetValue(3)
Expand All @@ -52,22 +50,21 @@ func TestChoiceHeirarchy(t *testing.T) {
assert.Equal(t, val.IntermediateObj().Leaf().Name(), "str1")
assert.Equal(t, val.IntermediateObj().Leaf().Value(), int32(3))

err := config.Validate()
_, err := config.Marshal().ToYaml()
assert.Nil(t, err)
}

func TestChoiceWithNoProperties(t *testing.T) {

// This test checks choices with no properties has no issues reagrding set and get

api := openapiart.NewApi()
config := api.NewTestConfig()
config := openapiart.NewTestConfig()
val := config.ExtendedFeatures().ChoiceValNoProperties()

val.SetChoice(openapiart.ChoiceValWithNoPropertiesChoice.NO_OBJ)
val.NoObj()
assert.Equal(t, val.Choice(), openapiart.ChoiceValWithNoPropertiesChoice.NO_OBJ)

err := config.Validate()
_, err := config.Marshal().ToYaml()
assert.Nil(t, err)

}
Expand All @@ -76,12 +73,11 @@ func TestChoiceWithRequiredFeild(t *testing.T) {

// This set checks choices which are defined as required

api := openapiart.NewApi()
config := api.NewTestConfig()
config := openapiart.NewTestConfig()
val := config.ExtendedFeatures().ChoiceValNoProperties()

// check error
err := config.Validate()
_, err := config.Marshal().ToYaml()
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "Choice is required field on interface ChoiceValWithNoProperties")

Expand All @@ -91,7 +87,7 @@ func TestChoiceWithRequiredFeild(t *testing.T) {
assert.Equal(t, val.IntermediateObj().Choice(), openapiart.RequiredChoiceChoice.STR_VAL)
assert.Equal(t, val.IntermediateObj().StrVal(), "str1")

err = config.Validate()
_, err = config.Marshal().ToYaml()
assert.Nil(t, err)

}
10 changes: 4 additions & 6 deletions pkg/new_tests/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ func TestOptionalValSchema(t *testing.T) {
// This test checks the values in optional schema.
// Objective is to check if default values are set properly.

api := openapiart.NewApi()
config := api.NewTestConfig()
config := openapiart.NewTestConfig()
oVal := config.NativeFeatures().OptionalVal()
assert.Equal(t, oVal.IntVal(), int32(50))
assert.Equal(t, oVal.NumVal(), float32(50.05))
assert.Equal(t, oVal.StrVal(), "default_str_val")
assert.Equal(t, oVal.BoolVal(), true)

err := config.Validate()
_, err := config.Marshal().ToYaml()
assert.Nil(t, err)
}

Expand All @@ -29,14 +28,13 @@ func TestOptionalArrayValSchema(t *testing.T) {
// This test checks the values in optional array schema.
// Objective is to check if default values are set properly.

api := openapiart.NewApi()
config := api.NewTestConfig()
config := openapiart.NewTestConfig()
oVal := config.NativeFeatures().OptionalValArray()
assert.Equal(t, oVal.IntVals(), []int32{10, 20})
assert.Equal(t, oVal.NumVals(), []float32{10.01, 20.02})
assert.Equal(t, oVal.StrVals(), []string{"first_str", "second_str"})
assert.Equal(t, oVal.BoolVals(), []bool{})

err := config.Validate()
_, err := config.Marshal().ToYaml()
assert.Nil(t, err)
}
Loading

0 comments on commit aa84f6c

Please sign in to comment.