For context I am using vb.net but the concepts remain the same.
This is a submission API for dozens of different sample sheets. As such I would like to have the one main endpoint and use 2 properties that define what "object" the internal payload resolves too. I would have thought this would be a fairly std paradigm as I have used it many times in the past when the transport format was xml, but I have not found much mentioning it when it is Json.
As an example;
the wrapper class:
Public Class Submission
Public Property AgreementCode As String
Public Property SampleType As String
Public Property SampleTypeVersion As Integer
Public Property Details As Object 'Note!
End Class
And an inner class: (one of many)
Public Class TubeV2
Public SampleNumber As Integer
Public SampleName As String
Public Property TubeName As String
Public Property AdditionalComments As String
Public Property SexAtBirth As String
End Class
The server-side code that makes this all work is;
Public Overloads Function UploadSubmissionWithPayload( ByVal value
As WebApiNoMVC.Model.Submission) As HttpResponseMessage
If value.SampleType = "Tube" And
value.SampleTypeVersion = 2 Then
Dim oTube As WebApiNoMVC.Model.TubeV2
Dim objs As List(Of WebApiNoMVC.Model.TubeV2) =
value.Details.ToObject(Of List(Of WebApiNoMVC.Model.TubeV2))()
For Each oTube In objs
'all values are now available
Next
elseif etc etc
And finally a concrete json example;
{"AgreementCode":"ABCDEF2297321","SampleType":"Tube","SampleTypeVersion":2,
"Details": [
{
"SampleNumber": "1",
"SampleName": "Dido","TubeName":"Tube1",
"SexAtBirth": "F"
},
{
"SampleNumber": "2",
"SampleName": "Adsy", "AdditionalComments":"Trans",
"SexAtBirth": "U"
}
]
}
I really like this as a paradigm but have a feeling this is just no longer the way "things are done".
Is anyone able to either confirm this is ok as a design pattern, or conversely highlight why it is a really bad idea?
So far the main issue raised is that as the internal json objects are not part of the endpoint and so they are not automatically described using YAML/Open API, but as they could be easily described (and disseminated) using Json schema I'm not sure how critical a drawback this is, if it is at all.