I am trying to create a RESTFUL endpoint in Smithy. Basically, the endpoint would have these behaviours:
/results: If user navigates to this endpoint, give them back a list of JSON objects or null[{}]if they have none/results/{resultsID}: Give the user a specific JSON object if resultsID is valid and an empty JSON object{}otherwise
My attempt was to create two endpoints as follows:
structure ResultData { //my main JSON object
user: String,
UUID: String,
number1: Float, //all these are optional
number2: Float,
number3: Float
}
structure EmptyResponse { }
union Response {
response: ResultData,
emptyResponse: EmptyResponse
}
structure ResultDataList { //this structure is for when the user navigates to /results
member: ResultData //in this case I return an array of JSON objects
}
structure resultsInput { //resultsInput is the http path parameter
@required
@httpLabel
resultsID: String
}
@http(code: 200, method: "POST", uri: "/results", httpHeaders: {"Content-Type": "application/json"})
operation ResultsTotal {
output: ResultDataList
}
@http(code: 200, method: "POST", uri: "/results/{resultsID}", httpHeaders: {"Content-Type": "application/json"})
operation Results {
input: resultsInput
output: Response
}
As you can see, I created two endpoints, one for results and one for results/resultID but I am unsure on how to satisfy the constraints I mentioned above. Additionally, I get an error saying operation shape output relationships must target a structure shape, but found union
Any tips on how I can get this to work?
Smithy requires all responses to be a structure. You should have a separate response structure for each operation. Don't try to re-use them.