json-test.capnp (3431B)
1 # Copyright (c) 2018 Cloudflare, Inc. and contributors 2 # Licensed under the MIT License: 3 # 4 # Permission is hereby granted, free of charge, to any person obtaining a copy 5 # of this software and associated documentation files (the "Software"), to deal 6 # in the Software without restriction, including without limitation the rights 7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 # copies of the Software, and to permit persons to whom the Software is 9 # furnished to do so, subject to the following conditions: 10 # 11 # The above copyright notice and this permission notice shall be included in 12 # all copies or substantial portions of the Software. 13 # 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 # THE SOFTWARE. 21 22 @0xc9d405cf4333e4c9; 23 24 using Json = import "/capnp/compat/json.capnp"; 25 26 $import "/capnp/c++.capnp".namespace("capnp"); 27 28 struct TestJsonAnnotations { 29 someField @0 :Text $Json.name("names-can_contain!anything Really"); 30 31 aGroup :group $Json.flatten() { 32 flatFoo @1 :UInt32; 33 flatBar @2 :Text; 34 flatBaz :group $Json.name("renamed-flatBaz") { 35 hello @3 :Bool; 36 } 37 doubleFlat :group $Json.flatten() { 38 flatQux @4 :Text; 39 } 40 } 41 42 prefixedGroup :group $Json.flatten(prefix = "pfx.") { 43 foo @5 :Text; 44 bar @6 :UInt32 $Json.name("renamed-bar"); 45 baz :group { 46 hello @7 :Bool; 47 } 48 morePrefix :group $Json.flatten(prefix = "xfp.") { 49 qux @8 :Text; 50 } 51 } 52 53 aUnion :union $Json.flatten() $Json.discriminator(name = "union-type") { 54 foo :group $Json.flatten() { 55 fooMember @9 :Text; 56 multiMember @10 :UInt32; 57 } 58 bar :group $Json.flatten() $Json.name("renamed-bar") { 59 barMember @11 :UInt32; 60 multiMember @12 :Text; 61 } 62 } 63 64 dependency @13 :TestJsonAnnotations2; 65 # To test that dependencies are loaded even if not flattened. 66 67 simpleGroup :group { 68 # To test that group types are loaded even if not flattened. 69 grault @14 :Text $Json.name("renamed-grault"); 70 } 71 72 enums @15 :List(TestJsonAnnotatedEnum); 73 74 innerJson @16 :Json.Value; 75 76 customFieldHandler @17 :Text; 77 78 testBase64 @18 :Data $Json.base64; 79 testHex @19 :Data $Json.hex; 80 81 bUnion :union $Json.flatten() $Json.discriminator(valueName = "bValue") { 82 foo @20 :Text; 83 bar @21 :UInt32 $Json.name("renamed-bar"); 84 } 85 86 externalUnion @22 :TestJsonAnnotations3; 87 88 unionWithVoid :union $Json.discriminator(name = "type") { 89 intValue @23 :UInt32; 90 voidValue @24 :Void; 91 textValue @25 :Text; 92 } 93 } 94 95 struct TestJsonAnnotations2 { 96 foo @0 :Text $Json.name("renamed-foo"); 97 cycle @1 :TestJsonAnnotations; 98 } 99 100 struct TestJsonAnnotations3 $Json.discriminator(name = "type") { 101 union { 102 foo @0 :UInt32; 103 bar @1 :TestFlattenedStruct $Json.flatten(); 104 } 105 } 106 107 struct TestFlattenedStruct { 108 value @0 :Text; 109 } 110 111 enum TestJsonAnnotatedEnum { 112 foo @0; 113 bar @1 $Json.name("renamed-bar"); 114 baz @2 $Json.name("renamed-baz"); 115 qux @3; 116 } 117 118 struct TestBase64Union { 119 union { 120 foo @0 :Data $Json.base64; 121 bar @1 :Text; 122 } 123 }