Closed j-d-carmichael closed 3 years ago
Yeah I had a similar idea the other day with extends - oa3 has it build it but if you area still on oa2 then it means any base model is just repeated for slight differences
oh really? what is the feature called in oa3?
https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/
also supports oneOf
- so data can be something like id: number OR username: string
ah yea but this is a different thing; i thought i had missed a trick :)
Here i want to have 1 common model, and have a lighter model simply pick a specific list of attributes from the common model.
With oneOf this is not possible in a straight forward manner that is not overly verbose and afaik is design primarily for saying "this can be this OR this".
sure, but with inheritence you can do the ssme thing - basemodel = result_of_pick, regular model = basemodel + pick
@jonmanga actually built this one already: pickProps.ts
An inverse function would be pretty helpful though
Openapi has a nice feature.. allOf.. but doesn't offer the ability to pick attributes from an existing model.
This allows you to create a set of base attributes to be used as say search results... lighter versions of the models. Then using allOf extend to create a fuller model for a detail view... but then when you need a 3rd version.. the whole thing becomes too complex to easily manage.
A function in boats to pick attribute from the full model to create a new model would be much easier to manage, all attributes held in the the main model, the lighters model cherry picking what they needed:
Would result in:
Where the full model might look like:
There will however be an issue when a picked attribute contains a $ref