Skip to content

Commit

Permalink
Make test a bit more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
idubrov committed Oct 9, 2023
1 parent 4584942 commit fad9f28
Show file tree
Hide file tree
Showing 2 changed files with 292 additions and 3 deletions.
289 changes: 288 additions & 1 deletion tests/utoipa.json
Original file line number Diff line number Diff line change
@@ -1 +1,288 @@
{"openapi":"3.0.3","info":{"title":"json-patch","description":"RFC 6902, JavaScript Object Notation (JSON) Patch","contact":{"name":"Ivan Dubrov","email":"dubrov.ivan@gmail.com"},"license":{"name":"MIT/Apache-2.0"},"version":"1.2.0"},"paths":{"foo":{"get":{"tags":["crate"],"operationId":"get_foo","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Patch"}}},"required":true},"responses":{"200":{"description":"Patch completed"},"406":{"description":"Not accepted"}}}}},"components":{"schemas":{"AddOperation":{"type":"object","description":"JSON Patch 'add' operation representation","required":["path","value"],"properties":{"path":{"type":"string","description":"JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."},"value":{"description":"Value to add to the target location."}}},"CopyOperation":{"type":"object","description":"JSON Patch 'copy' operation representation","required":["from","path"],"properties":{"from":{"type":"string","description":"JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nto copy value from."},"path":{"type":"string","description":"JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."}}},"MoveOperation":{"type":"object","description":"JSON Patch 'move' operation representation","required":["from","path"],"properties":{"from":{"type":"string","description":"JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nto move value from."},"path":{"type":"string","description":"JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."}}},"Patch":{"type":"array","items":{"$ref":"#/components/schemas/PatchOperation"},"description":"Representation of JSON Patch (list of patch operations)"},"PatchOperation":{"oneOf":[{"allOf":[{"$ref":"#/components/schemas/AddOperation"},{"type":"object","required":["op"],"properties":{"op":{"type":"string","enum":["add"]}}}]},{"allOf":[{"$ref":"#/components/schemas/RemoveOperation"},{"type":"object","required":["op"],"properties":{"op":{"type":"string","enum":["remove"]}}}]},{"allOf":[{"$ref":"#/components/schemas/ReplaceOperation"},{"type":"object","required":["op"],"properties":{"op":{"type":"string","enum":["replace"]}}}]},{"allOf":[{"$ref":"#/components/schemas/MoveOperation"},{"type":"object","required":["op"],"properties":{"op":{"type":"string","enum":["move"]}}}]},{"allOf":[{"$ref":"#/components/schemas/CopyOperation"},{"type":"object","required":["op"],"properties":{"op":{"type":"string","enum":["copy"]}}}]},{"allOf":[{"$ref":"#/components/schemas/TestOperation"},{"type":"object","required":["op"],"properties":{"op":{"type":"string","enum":["test"]}}}]}],"description":"JSON Patch single patch operation","discriminator":{"propertyName":"op"}},"RemoveOperation":{"type":"object","description":"JSON Patch 'remove' operation representation","required":["path"],"properties":{"path":{"type":"string","description":"JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."}}},"ReplaceOperation":{"type":"object","description":"JSON Patch 'replace' operation representation","required":["path","value"],"properties":{"path":{"type":"string","description":"JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."},"value":{"description":"Value to replace with."}}},"TestOperation":{"type":"object","description":"JSON Patch 'test' operation representation","required":["path","value"],"properties":{"path":{"type":"string","description":"JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."},"value":{"description":"Value to test against."}}}}}}
{
"openapi": "3.0.3",
"info": {
"title": "json-patch",
"description": "RFC 6902, JavaScript Object Notation (JSON) Patch",
"contact": {
"name": "Ivan Dubrov",
"email": "dubrov.ivan@gmail.com"
},
"license": {
"name": "MIT/Apache-2.0"
},
"version": "0.0.0"
},
"paths": {
"foo": {
"get": {
"tags": [
"crate"
],
"operationId": "get_foo",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Patch"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Patch completed"
},
"406": {
"description": "Not accepted"
}
}
}
}
},
"components": {
"schemas": {
"AddOperation": {
"type": "object",
"description": "JSON Patch 'add' operation representation",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
},
"value": {
"description": "Value to add to the target location."
}
}
},
"CopyOperation": {
"type": "object",
"description": "JSON Patch 'copy' operation representation",
"required": [
"from",
"path"
],
"properties": {
"from": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nto copy value from."
},
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
}
}
},
"MoveOperation": {
"type": "object",
"description": "JSON Patch 'move' operation representation",
"required": [
"from",
"path"
],
"properties": {
"from": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nto move value from."
},
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
}
}
},
"Patch": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PatchOperation"
},
"description": "Representation of JSON Patch (list of patch operations)"
},
"PatchOperation": {
"oneOf": [
{
"allOf": [
{
"$ref": "#/components/schemas/AddOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"add"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/RemoveOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"remove"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/ReplaceOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"replace"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/MoveOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"move"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/CopyOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"copy"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/TestOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"test"
]
}
}
}
]
}
],
"description": "JSON Patch single patch operation",
"discriminator": {
"propertyName": "op"
}
},
"RemoveOperation": {
"type": "object",
"description": "JSON Patch 'remove' operation representation",
"required": [
"path"
],
"properties": {
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
}
}
},
"ReplaceOperation": {
"type": "object",
"description": "JSON Patch 'replace' operation representation",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
},
"value": {
"description": "Value to replace with."
}
}
},
"TestOperation": {
"type": "object",
"description": "JSON Patch 'test' operation representation",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
},
"value": {
"description": "Value to test against."
}
}
}
}
}
}
6 changes: 4 additions & 2 deletions tests/utoipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ fn schema() {
)]
struct ApiDoc;

let doc = ApiDoc::openapi().to_json().unwrap();
let mut doc = ApiDoc::openapi();

expectorate::assert_contents("tests/utoipa.json", &doc);
doc.info.version = "0.0.0".to_string();
let json = doc.to_pretty_json().unwrap();
expectorate::assert_contents("tests/utoipa.json", &json);
}

0 comments on commit fad9f28

Please sign in to comment.