Skip to content

Commit

Permalink
Optional second parameter when using object in swaggertype (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlesar authored Nov 29, 2020
1 parent ee29e2b commit 031a42d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ func BuildCustomSchema(types []string) (*spec.Schema, error) {
}

switch types[0] {
case "primitive":
case PRIMITIVE:
if len(types) == 1 {
return nil, errors.New("need primitive type after primitive")
}
return BuildCustomSchema(types[1:])
case "array":
case ARRAY:
if len(types) == 1 {
return nil, errors.New("need array item type after array")
}
Expand All @@ -169,9 +169,9 @@ func BuildCustomSchema(types []string) (*spec.Schema, error) {
return nil, err
}
return spec.ArrayProperty(schema), nil
case "object":
case OBJECT:
if len(types) == 1 {
return nil, errors.New("need object item type after object")
return PrimitiveSchema(types[0]), nil
}
schema, err := BuildCustomSchema(types[1:])
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func TestBuildCustomSchema(t *testing.T) {
assert.Equal(t, schema.SchemaProps.Items.Schema.SchemaProps.Type, spec.StringOrArray{"string"})

schema, err = BuildCustomSchema([]string{"object"})
assert.Error(t, err)
assert.Nil(t, schema)
assert.NoError(t, err)
assert.Equal(t, schema.SchemaProps.Type, spec.StringOrArray{"object"})

schema, err = BuildCustomSchema([]string{"object", "oops"})
assert.Error(t, err)
Expand Down

0 comments on commit 031a42d

Please sign in to comment.