I have a RESTful API supporting CRUD operations on an entity. Should I have single xsd file that defines the schema for all the CRUD operations?
The reason why I ask this question is, I have some fields that are relevant only for Retrieve calls and not for Create or Update. In that case, should I have one xsd file and ignore some fields for Create and Update?
Your question seems to tie together fields usage with number of XSD files, which makes me think you may be missing on some basic XSD concepts.
Let’s say that your problem is that for a given entity, you may retrieve more fields than you can update; illustrating on a fictitious
Personentity, you may R(etrieve) theName,Address,Date of BirthandRegistered Sinceattributes, yet to C(reate) the entity, you only allow forName,AddressandDate of Birth– you want the backend system to set theRegistered Sinceattribute. The requirement is to constrain the XSD as much as possible, to improve the self-descriptiveness of the model.You can achieve the separation of these scenarios by creating an XSD base type, then extend that using another type, which will then include the extra fields you want. You could do this kind of stuff in a single file, or two or more different files.
NOTE: The XSD above is not intented to illustrate XSD best practices
If extension/restriction is not allowed in your environment, you could achieve reuse by virtue of
xsd:group– it doesn’t change my point. So, I am basically saying that the reason why you’re asking the question –I have some fields that are relevant only for Retrieve calls and not for Create or Update.– has no bearing whatsoever on the number of XSD files… unless you consider more variables. I’ll try some that come to my mind, but I am not going to provide an exhaustive list: