Closed jiangxiaoqiang closed 2 years ago
The easiest way to return JSON is to use Json<...>
with a struct.
For example:
https://github.com/GREsau/okapi/blob/65244f0037a4625f22a64cc45ef8179cdb984745/examples/json-web-api/src/main.rs#L84-L91
Then you can add the structure and documentation like this:
https://github.com/GREsau/okapi/blob/65244f0037a4625f22a64cc45ef8179cdb984745/examples/json-web-api/src/main.rs#L74-L82
With RawJson
you can return any JSON, so there is no way to know what the structure is of the JSON at compile time.
I am using rust rocket as my web server, this is the code looks like:
this code works fine. Now I facing a problem is that the rust rocket return raw json, the client side could not know the return content structure. it only show a json string in swagger:
the client did not know what the response content is. I have read the the rust rocket official document still did not figure out what should I do to return the entity structure. I have tried like this:
the compiler shows:
I also tried to implement like this:
seems did not work. I have tried this:
it works but still could not show the response structure at client side.