Forum Discussion

iphra's avatar
iphra
Occasional Visitor
6 years ago

Referencing part of a component

Hi, in the component section i defined an object Book having some properties. I want to refer to this component in two distinct endpoints, one using the whole Book object in the response, but the other one using just some properties of this Book object in its response body.

In the last case, is it correct to refer to the Book component or should i define another one?

1 Reply

  • When you reference a component, you reference it as-is.

     

    If the difference is between input and output, depending on the version of the spec that you use, you may be able to utilize the 'readOnly' and 'writeOnly' attributes. Otherwise, you'd need to split the model into two, but you can use composition to avoid duplication.