Background:
We support an API guide directory where we document and show the different web services present in our system. There are many containers that group related services and few services have a common schema/model. For ex, ignore the identifier as this is an excample create a person - POST - [name, email, age] get all persons - GET - list of [name, email, age]
The 2 calls above have the same model,
"name" : {
"type" : "string",
"description" : "name of the persion"
},
"email" : {
"type" : "string",
"description" : "user email id",
"example" : "abcd@def.com"
},
"age" : {
"type" : "integer",
"description" : "user age",
"example" : 20
}
Question:
We have been using the same schema against both GET/POST calls so far, and now we want to add additional validations that may exist on fields, for example, name cannot contain numbers..
"name" : {
"type" : "string",
"description" : "name of the persion",
**"validation" : "name cannot contain numbers"**
},
"email" : {
"type" : "string",
"description" : "user email id",
"example" : "abcd@def.com"
},
"age" : {
"type" : "integer",
"description" : "user age",
"example" : 20
}
As you can see this validation makes sense on POST requests only and not on get requests,
Solutions:
So, what is a good design in this case?
- Have separate snippets for GET and POST?(one without the validation and one with))
- Keep the validation and maintain only one schema and let user see the extra field?
Any industry standards documented? any experiences/ examples? Just interested in getting some thoughts!
Opening discussion to learn and discuss what a better design would be for a problem many might have faced or will face.