Support for creating sets, instead of arrays, when uniqueItems is true
Description
Is it possible to update the library to generate sets instead of arrays if uniqueItems: true?
@jasonlor can you show an example of what you're looking for and what's the use case?
Yep, so I'm using this library to generate types from my open API definition.
Here's a basic example:
"TypeToBeGenerated": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
},
In this situation, I'd like the following type as an output:
export type TypeToBeGenerated = Set<String> instead of export type TypeToBeGenerated = Array<String>
But your API does not return a set, it returns an array... how do you use the response from the API when it's typed as Set? They don't have identical APIs
When I construct a response or request, I want to guarantee uniqueness by removing duplicates. I suppose the alternative approach for my use case would be to remove duplicates if uniqueItems: true but still send arrays.
Wouldn't defining parameters as a set, be a better guarantee, even if it is transported as an array?
While that is a viable approach for your use case, I'm not sure it makes sense to include as a configuration option for everyone. What would make sense, however, is giving you control over the generation step so that you can configure this behaviour for yourself rather than bake it into the package. Which OpenAPI version are you working with?
That makes complete sense, I'm working with OpenAPI 3.0
Added a RSVP label on this issue in case more people are interested in it. In the meantime, I encourage you to check out the WIP parser and see if you can figure out how you'd want to be able to "plug" into it and override this for your needs (I did not consider this use case yet)