diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7bb7f67d..a55274dd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -60,7 +60,7 @@ jobs: # It is good to test more than the MSRV and stable since sometimes # breakage occurs in intermediate versions. # IMPORTANT: Synchronize the MSRV with the Cargo.toml values. - rust: ["1.67", "1.70", "1.75", "1.80", "stable", "beta", "nightly"] + rust: ["1.70", "1.75", "1.80", "stable", "beta", "nightly"] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/Cargo.lock b/Cargo.lock index 1bbc24d6..b2f1fb67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,12 +40,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - [[package]] name = "autocfg" version = "1.1.0" @@ -75,18 +69,18 @@ dependencies = [ [[package]] name = "bit-set" -version = "0.5.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" dependencies = [ "bit-vec", ] [[package]] name = "bit-vec" -version = "0.6.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" [[package]] name = "bitflags" @@ -97,6 +91,12 @@ dependencies = [ "serde", ] +[[package]] +name = "borrow-or-share" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eeab4423108c5d7c744f4d234de88d18d636100093ae04caf4825134b9c3a32" + [[package]] name = "bumpalo" version = "3.14.0" @@ -211,6 +211,17 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dissimilar" version = "1.0.7" @@ -238,6 +249,15 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" +[[package]] +name = "email_address" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e079f19b08ca6239f47f8ba8509c11cf3ea30095831f7fed61441475edd8c449" +dependencies = [ + "serde", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -256,15 +276,26 @@ dependencies = [ [[package]] name = "fancy-regex" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531e46835a22af56d1e3b66f04844bed63158bc094a628bec1d321d9b4c44bf2" +checksum = "6e24cb5a94bcae1e5408b0effca5cd7172ea3c5755049c5f3af4cd283a165298" dependencies = [ "bit-set", "regex-automata", "regex-syntax", ] +[[package]] +name = "fluent-uri" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1918b65d96df47d3591bed19c5cca17e3fa5d0707318e4b5ef2eae01764df7e5" +dependencies = [ + "borrow-or-share", + "ref-cast", + "serde", +] + [[package]] name = "fnv" version = "1.0.7" @@ -297,10 +328,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] @@ -362,6 +391,124 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -378,6 +525,27 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -400,15 +568,6 @@ dependencies = [ "serde", ] -[[package]] -name = "iso8601" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "924e5d73ea28f59011fec52a0d12185d496a9b075d360657aed2a5707f701153" -dependencies = [ - "nom", -] - [[package]] name = "itoa" version = "1.0.10" @@ -426,30 +585,26 @@ dependencies = [ [[package]] name = "jsonschema" -version = "0.18.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0afd06142c9bcb03f4a8787c77897a87b6be9c4918f1946c33caa714c27578" +checksum = "893d6229c7315763ca0df9b29ab7661ee419f286577a02847c5521b462e071af" dependencies = [ "ahash", - "anyhow", "base64 0.22.1", "bytecount", + "email_address", "fancy-regex", "fraction", - "getrandom", - "iso8601", + "idna 1.0.3", "itoa", - "memchr", "num-cmp", "once_cell", - "parking_lot", "percent-encoding", - "regex", + "referencing", + "regex-syntax", "serde", "serde_json", - "time", - "url", - "uuid", + "uuid-simd", ] [[package]] @@ -465,20 +620,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] -name = "litrs" -version = "0.2.3" +name = "litemap" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9275e0933cf8bb20f008924c0cb07a0692fe54d8064996520bf998de9eb79aa" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" [[package]] -name = "lock_api" -version = "0.4.11" +name = "litrs" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] +checksum = "f9275e0933cf8bb20f008924c0cb07a0692fe54d8064996520bf998de9eb79aa" [[package]] name = "log" @@ -498,22 +649,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "num" version = "0.4.3" @@ -601,32 +736,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] -name = "parking_lot" -version = "0.12.1" +name = "outref" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] +checksum = "4030760ffd992bef45b0ae3f10ce1aba99e33464c90d14dd7c039884963ddc7a" [[package]] name = "paste" @@ -686,12 +804,36 @@ dependencies = [ ] [[package]] -name = "redox_syscall" -version = "0.5.1" +name = "ref-cast" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "ccf0a6f84d5f1d581da8b41b47ec8600871962f2a528115b542b362d4b744931" dependencies = [ - "bitflags", + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "referencing" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb853437e467c693ac1dc8c1520105a31b8c2588544ff2f3cfa5a7c706c6c069" +dependencies = [ + "ahash", + "fluent-uri", + "once_cell", + "percent-encoding", + "serde_json", ] [[package]] @@ -793,12 +935,6 @@ dependencies = [ "syn", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "semver" version = "1.0.20" @@ -955,9 +1091,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "strsim" @@ -976,6 +1118,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "termcolor" version = "1.4.0" @@ -1036,6 +1189,16 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1143,16 +1306,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", - "idna", + "idna 0.5.0", "percent-encoding", ] +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "uuid" version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +[[package]] +name = "uuid-simd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b082222b4f6619906941c17eb2297fff4c2fb96cb60164170522942a200bd8" +dependencies = [ + "outref", + "uuid", + "vsimd", +] + [[package]] name = "version-sync" version = "0.9.5" @@ -1174,6 +1360,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vsimd" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1334,6 +1526,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "xml-rs" version = "0.8.20" @@ -1346,6 +1550,30 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.31" @@ -1365,3 +1593,46 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index f1a516fe..447db135 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/jonasbb/serde_with/" -rust-version = "1.67" +rust-version = "1.70" version = "3.11.0" [workspace.metadata.release] diff --git a/serde_with/Cargo.toml b/serde_with/Cargo.toml index b98481b9..a4db1bb7 100644 --- a/serde_with/Cargo.toml +++ b/serde_with/Cargo.toml @@ -147,7 +147,7 @@ time_0_3 = {package = "time", version = "~0.3.36", optional = true, default-feat expect-test = "1.5.0" fnv = "1.0.6" glob = "0.3.0" -jsonschema = { version = "0.18.0", default-features = false, features = ["resolve-file"] } +jsonschema = { version = "0.26.1", default-features = false, features = ["resolve-file"] } mime = "0.3.16" pretty_assertions = "1.4.0" regex = {version = "1.11.0", default-features = false, features = ["std"]} diff --git a/serde_with/src/schemars_0_8.rs b/serde_with/src/schemars_0_8.rs index 0864c4eb..f2159acc 100644 --- a/serde_with/src/schemars_0_8.rs +++ b/serde_with/src/schemars_0_8.rs @@ -112,6 +112,9 @@ pub trait JsonSchemaAs { /// The name of the generated JSON Schema. /// /// This is used as the title for root schemas, and the key within the root's `definitions` property for sub-schemas. + /// + /// As the schema name is used as as part of `$ref` it has to be a valid URI path segment according to + /// [RFC 3986 Section-3](https://datatracker.ietf.org/doc/html/rfc3986#section-3). fn schema_name() -> String; /// Returns a string that uniquely identifies the schema produced by this type. @@ -536,11 +539,11 @@ where T: JsonSchema, { fn schema_name() -> String { - std::format!("EnumMap<{}>", T::schema_name()) + std::format!("EnumMap({})", T::schema_name()) } fn schema_id() -> Cow<'static, str> { - std::format!("serde_with::EnumMap<{}>", T::schema_id()).into() + std::format!("serde_with::EnumMap({})", T::schema_id()).into() } // We generate the schema here by going through all the variants of the @@ -727,12 +730,12 @@ where TA: JsonSchemaAs, { fn schema_name() -> String { - std::format!("KeyValueMap<{}>", >::schema_name()) + std::format!("KeyValueMap({})", >::schema_name()) } fn schema_id() -> Cow<'static, str> { std::format!( - "serde_with::KeyValueMap<{}>", + "serde_with::KeyValueMap({})", >::schema_id() ) .into() @@ -800,14 +803,14 @@ where { fn schema_name() -> String { std::format!( - "OneOrMany<{}, PreferOne>", + "OneOrMany({},PreferOne)", >::schema_name() ) } fn schema_id() -> Cow<'static, str> { std::format!( - "serde_with::OneOrMany<{}, PreferOne>", + "serde_with::OneOrMany({},PreferOne)", >::schema_id() ) .into() @@ -896,9 +899,9 @@ macro_rules! schema_for_pickfirst { fn schema_name() -> String { std::format!( concat!( - "PickFirst<(", + "PickFirst(", $( "{", stringify!($param), "}", )+ - ")>" + ")" ), $( $param = >::schema_name(), )+ ) @@ -907,9 +910,9 @@ macro_rules! schema_for_pickfirst { fn schema_id() -> Cow<'static, str> { std::format!( concat!( - "serde_with::PickFirst<(", + "serde_with::PickFirst(", $( "{", stringify!($param), "}", )+ - ")>" + ")" ), $( $param = >::schema_id(), )+ ) diff --git a/serde_with/tests/schemars_0_8.rs b/serde_with/tests/schemars_0_8.rs index d8b41113..d110abd8 100644 --- a/serde_with/tests/schemars_0_8.rs +++ b/serde_with/tests/schemars_0_8.rs @@ -46,6 +46,11 @@ macro_rules! declare_snapshot_test { } let schema = schemars::schema_for!($name); + let _ = jsonschema::Validator::new( + &serde_json::to_value(&schema).expect("generated schema is not valid json"), + ) + .expect("generated schema is not valid"); + let mut schema = serde_json::to_string_pretty(&schema) .expect("schema could not be serialized"); schema.push('\n'); @@ -425,6 +430,14 @@ mod snapshots { } } + pickfirst_nested { + #[serde(transparent)] + struct Test { + #[serde_as(as = "OneOrMany>")] + optional_value: Vec + } + } + one_or_many_nested { struct Test { #[serde_as(as = "Option>")] diff --git a/serde_with/tests/schemars_0_8/schemars_deserialize_only_bug_735.json b/serde_with/tests/schemars_0_8/schemars_deserialize_only_bug_735.json index 8ad0d16a..f318b342 100644 --- a/serde_with/tests/schemars_0_8/schemars_deserialize_only_bug_735.json +++ b/serde_with/tests/schemars_0_8/schemars_deserialize_only_bug_735.json @@ -20,7 +20,7 @@ "description": "Will emit matching schemars attribute", "allOf": [ { - "$ref": "#/definitions/PickFirst<(uint32String)>" + "$ref": "#/definitions/PickFirst(uint32String)" } ] }, @@ -44,7 +44,7 @@ } }, "definitions": { - "PickFirst<(uint32String)>": { + "PickFirst(uint32String)": { "anyOf": [ { "type": "integer", diff --git a/serde_with/tests/schemars_0_8/snapshots/enum_map.json b/serde_with/tests/schemars_0_8/snapshots/enum_map.json index 9a8d428c..f8eeb3b5 100644 --- a/serde_with/tests/schemars_0_8/snapshots/enum_map.json +++ b/serde_with/tests/schemars_0_8/snapshots/enum_map.json @@ -7,11 +7,11 @@ ], "properties": { "data": { - "$ref": "#/definitions/EnumMap" + "$ref": "#/definitions/EnumMap(Mappable)" } }, "definitions": { - "EnumMap": { + "EnumMap(Mappable)": { "type": "object", "properties": { "A": { diff --git a/serde_with/tests/schemars_0_8/snapshots/key_value_map.json b/serde_with/tests/schemars_0_8/snapshots/key_value_map.json index e232adc5..63eee02a 100644 --- a/serde_with/tests/schemars_0_8/snapshots/key_value_map.json +++ b/serde_with/tests/schemars_0_8/snapshots/key_value_map.json @@ -7,11 +7,11 @@ ], "properties": { "data": { - "$ref": "#/definitions/KeyValueMap" + "$ref": "#/definitions/KeyValueMap(KvMapData)" } }, "definitions": { - "KeyValueMap": { + "KeyValueMap(KvMapData)": { "type": "object", "additionalProperties": { "type": "object", diff --git a/serde_with/tests/schemars_0_8/snapshots/key_value_map_enum.json b/serde_with/tests/schemars_0_8/snapshots/key_value_map_enum.json index d4a60070..c6474db9 100644 --- a/serde_with/tests/schemars_0_8/snapshots/key_value_map_enum.json +++ b/serde_with/tests/schemars_0_8/snapshots/key_value_map_enum.json @@ -7,11 +7,11 @@ ], "properties": { "data": { - "$ref": "#/definitions/KeyValueMap" + "$ref": "#/definitions/KeyValueMap(KvMapEnum)" } }, "definitions": { - "KeyValueMap": { + "KeyValueMap(KvMapEnum)": { "type": "object", "additionalProperties": { "oneOf": [ diff --git a/serde_with/tests/schemars_0_8/snapshots/key_value_map_flatten.json b/serde_with/tests/schemars_0_8/snapshots/key_value_map_flatten.json index a94120d9..74ee495f 100644 --- a/serde_with/tests/schemars_0_8/snapshots/key_value_map_flatten.json +++ b/serde_with/tests/schemars_0_8/snapshots/key_value_map_flatten.json @@ -7,11 +7,11 @@ ], "properties": { "data": { - "$ref": "#/definitions/KeyValueMap" + "$ref": "#/definitions/KeyValueMap(KvMapFlatten)" } }, "definitions": { - "KeyValueMap": { + "KeyValueMap(KvMapFlatten)": { "type": "object", "additionalProperties": { "type": "object", diff --git a/serde_with/tests/schemars_0_8/snapshots/one_or_many_nested.json b/serde_with/tests/schemars_0_8/snapshots/one_or_many_nested.json index 67c4ce91..31f845f4 100644 --- a/serde_with/tests/schemars_0_8/snapshots/one_or_many_nested.json +++ b/serde_with/tests/schemars_0_8/snapshots/one_or_many_nested.json @@ -7,7 +7,7 @@ "default": null, "anyOf": [ { - "$ref": "#/definitions/OneOrMany" + "$ref": "#/definitions/OneOrMany(String,PreferOne)" }, { "type": "null" @@ -16,7 +16,7 @@ } }, "definitions": { - "OneOrMany": { + "OneOrMany(String,PreferOne)": { "anyOf": [ { "type": "string" diff --git a/serde_with/tests/schemars_0_8/snapshots/one_or_many_prefer_one.json b/serde_with/tests/schemars_0_8/snapshots/one_or_many_prefer_one.json index b9aa247a..84466425 100644 --- a/serde_with/tests/schemars_0_8/snapshots/one_or_many_prefer_one.json +++ b/serde_with/tests/schemars_0_8/snapshots/one_or_many_prefer_one.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "OneOrMany", + "title": "OneOrMany(int32,PreferOne)", "anyOf": [ { "type": "integer", diff --git a/serde_with/tests/schemars_0_8/snapshots/pickfirst.json b/serde_with/tests/schemars_0_8/snapshots/pickfirst.json index 766bcaef..af5006c1 100644 --- a/serde_with/tests/schemars_0_8/snapshots/pickfirst.json +++ b/serde_with/tests/schemars_0_8/snapshots/pickfirst.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "PickFirst<(uint32String)>", + "title": "PickFirst(uint32String)", "anyOf": [ { "type": "integer", diff --git a/serde_with/tests/schemars_0_8/snapshots/pickfirst_nested.json b/serde_with/tests/schemars_0_8/snapshots/pickfirst_nested.json new file mode 100644 index 00000000..a429e29b --- /dev/null +++ b/serde_with/tests/schemars_0_8/snapshots/pickfirst_nested.json @@ -0,0 +1,34 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OneOrMany(PickFirst(uint32String),PreferOne)", + "anyOf": [ + { + "$ref": "#/definitions/PickFirst(uint32String)" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/PickFirst(uint32String)" + } + } + ], + "definitions": { + "PickFirst(uint32String)": { + "anyOf": [ + { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + }, + { + "writeOnly": true, + "allOf": [ + { + "type": "string" + } + ] + } + ] + } + } +} diff --git a/serde_with/tests/utils.rs b/serde_with/tests/utils.rs index 7eb50bd2..e6917db9 100644 --- a/serde_with/tests/utils.rs +++ b/serde_with/tests/utils.rs @@ -83,18 +83,18 @@ pub fn check_matches_schema(value: &serde_json::Value) where T: schemars_0_8::JsonSchema, { - use jsonschema::JSONSchema; + use jsonschema::Validator; use std::fmt::Write; if cfg!(feature = "schemars_0_8") { let schema_object = serde_json::to_value(schemars_0_8::schema_for!(T)) .expect("schema for T could not be serialized to json"); - let schema = match JSONSchema::compile(&schema_object) { + let schema = match Validator::new(&schema_object) { Ok(schema) => schema, Err(e) => panic!("schema for T was not a valid JSON schema: {e}"), }; - if let Err(errs) = schema.validate(value) { + if let Err(err) = schema.validate(value) { let mut message = String::new(); let _ = writeln!( @@ -102,10 +102,7 @@ where "Object was not valid according to its own schema:" ); - for err in errs { - let _ = writeln!(&mut message, " -> {}", err); - } - + let _ = writeln!(&mut message, " -> {}", err); let _ = writeln!(&mut message); let _ = writeln!(&mut message, "Object Value:"); let _ = writeln!(