Skip to content

Validating an enum array does not seem to work #203

Closed
@jamesraby

Description

@jamesraby

I have the following schema:

    items:
      type: string
      enum:
      - Admin
      - Prescriber
      - Clinician

When I try to validate the array field with input ["Admin"] - I get the following error:

code=400, message=Request body has an error: doesn't match the schema: Error at \"/permissions\":JSON value is not one of the allowed values, internal=Request body has an error: doesn't match the schema: Error at \"/permissions\":JSON value is not one of the allowed values\nSchema:\n {\n \"enum\": [\n \"Prescriber\",\n \"Admin\",\n \"Clinician\"\n ],\n \"items\": {\n \"type\": \"string\"\n },\n \"type\": \"array\"\n }\n\nValue:\n [\n \"Admin\"\n ]\n"

It seems like it is comparing the array ["Admin"] vs iterating through the array on line:

func (schema *Schema) visitSetOperations(value interface{}, fast bool) (err error) {
if enum := schema.Enum; len(enum) != 0 {
for _, v := range enum {
if value == v {
return
}
}
if fast {
return errSchema
}
return &SchemaError{
Value: value,
Schema: schema,
SchemaField: "enum",
Reason: "JSON value is not one of the allowed values",
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions