-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use utoipa support for serde_json::Value
- Loading branch information
Showing
4 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"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.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"}},"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."}}}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#[cfg(feature = "utoipa")] | ||
#[test] | ||
fn schema() { | ||
use json_patch::*; | ||
use utoipa::OpenApi; | ||
|
||
#[utoipa::path( | ||
get, | ||
path = "foo", | ||
request_body = Patch, | ||
responses( | ||
(status = 200, description = "Patch completed"), | ||
(status = 406, description = "Not accepted"), | ||
), | ||
)] | ||
#[allow(unused)] | ||
fn get_foo(body: Patch) {} | ||
|
||
#[derive(OpenApi, Default)] | ||
#[openapi( | ||
paths(get_foo), | ||
components(schemas( | ||
AddOperation, | ||
CopyOperation, | ||
MoveOperation, | ||
PatchOperation, | ||
RemoveOperation, | ||
ReplaceOperation, | ||
TestOperation, | ||
Patch, | ||
)) | ||
)] | ||
struct ApiDoc; | ||
|
||
let doc = ApiDoc::openapi().to_json().unwrap(); | ||
|
||
expectorate::assert_contents("tests/utoipa.json", &doc); | ||
} |