I'm using a component schema for several answers of my API. The problem is that in certain scenarios the same complex component has a different set of values for one of the attributes (It's an enumeration). If HTTP status is 200 one of the attributes has three possible values, if answer HTTP status is 400 the same attribute may have 10 different possible values.
I want to be explicit on the possible values on the answer for the different HTTP status, but AFAIK, I cannot do it without duplicating the object for each case :-( Is there any way of doing it or am I right?
Thank you very much in advance.
You don't have to duplicate the entire schema, but you will have to create multiple schemas.
Create a base schema, say, BaseResponse. That schema would include everything that's fully shared among the responses. Then create a response specific for your case, and use 'allOf' to combine BaseResponse with any additional fields and restrictions you may have.
Thank you for your answer. In the meanwhile I've applied inheritance (or composition) of the answer as you suggest, which seemed fine, but I found the generated server code didn't include the attributes that didn't belong to the base response. I've delivered the possible solution and I'm not working in this case anymore. Thank you for your availability.