ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas 📝
MIT License
1.4k stars 30 forks source link

supporting 1 or more values of an enum in a querystring variable #198

Closed longmatthewh closed 2 months ago

longmatthewh commented 2 months ago

I've tried the following for a GET request parameter where I could 1 or many values from an enum, and neither of the work. I eiether get an error saying that "querystring.product should be equal to one of the allowed values" when I send multiple values or "querystring.product should be an array" when I send a single value:

    product: {
      type: ["string", "array"],
      enum: ["product1", "product2", "product3"],
      default: ["product1", "product2"],
    },

and this

    product: {
      type: "array",
      items: {
        type: "string",
        enum: ["product1", "product2", "product3"],
      },
      default: ["product1", "product2"],
    },
ThomasAribart commented 1 month ago

@longmatthewh I think it makes sense as your value cannot be an array and a string at the same time. You should use an anyOf instead !