2 ms·
By Serde's classification, `success: {}` is a textbook externally tagged representation.
by Nullabillity 3y ago
By Serde's classification, `success: {}` is a textbook externally tagged representation.
- mindwok 3y agoI wasn't familiar with Serde's description of this so that was a good read, thanks. Although I still think this is a bad example of an externally tagged representation. In the Serde example they have the key as "Request" then what follows is the request object. In this example, the "success" key is followed by an arbitrary string message, which isn't obvious at all.
- Nullabillity 3y agoThe contents of each variant don't really matter here. The tag represents the variant, not the type contained inside of it. The Serde equivalent here would be: #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum Response { Success(serde_json::Value), Error(serde_json::Value), }
- chrismorgan 3y agoIf there was always only one top-level field and everything else was inside that, it could be externally tagged, but it’s definitely just untagged here, because #/components/examples/errorInvalidJson/value (line 4397) shows an error body with multiple top-level fields: {"error":"Invalid JSON.","detail":"…","location":{"offset":0,"line":1,"column":0}}. Externally tagged would be {"error":{"message":"Invalid JSON.","detail":"…","location":{…}}}.