Commit graph

158 commits

Author SHA1 Message Date
Graham Esau
5d58a4d3f0 Wrap comment lines at 100 chars 2024-08-30 13:05:33 +01:00
Graham Esau
d6c8b6b022 Fix ui tests in nightly 2024-08-30 11:12:23 +01:00
Graham Esau
9bba81892f Move private crate exports into _private module 2024-08-29 19:47:19 +01:00
Graham Esau
9770301218
Read #[garde(...)] attributes in addition to #[validate(...)] (#331) 2024-08-29 17:12:06 +01:00
Graham Esau
56cdd45c5a Allow validate (but not schemars) attributes to have extra values where necessary 2024-08-28 09:59:24 +01:00
Graham Esau
a85f0fc7bc Rust rustfmt 2024-08-28 09:16:29 +01:00
Graham Esau
d7ff81de96 Fix regex attribute when it uses dereferencing 2024-08-27 19:26:02 +01:00
Maximilian Güntner
04fa0713da
fix: honor rename_all_fields, add tests (#304) 2024-08-27 17:55:21 +01:00
Graham Esau
d07a1be031
Rewrite attribute handling code (#330) 2024-08-27 16:50:47 +01:00
Graham Esau
66f17fff0e
Allow regex(path = ...) value to be a non-string expression (#328) 2024-08-24 18:27:27 +01:00
Graham Esau
df06fc5f66
Allow arbitrary expressions in doc/title/description attributes (#327) 2024-08-24 14:35:30 +01:00
Graham Esau
8438865588 Disable doctests for derive code snippets 2024-08-21 17:52:56 +01:00
Graham Esau
2914a1b66a Include derive(JsonSchema) docs in rustdoc 2024-08-21 17:52:56 +01:00
Graham Esau
b4f214f6dc
Remove usages of gen identifier (#323)
`gen` is a reserved keyword in rust 2024, making it very awkward to use as a module/variable name.
2024-08-21 16:15:13 +01:00
Graham Esau
89a34e7a63
Add no_std support via disabling the new default feature std (#319) 2024-08-17 19:46:11 +01:00
Bilal Mahmoud
0af8f50086
Add absolute import for Result (#307)
This changes it so that the `Result` used in the derived schema code is using the absolute path to the `Result` enum, otherwise type aliases, such as: `error_stack::Result` cannot be used.
2024-08-17 13:28:56 +01:00
Graham Esau
faf15e7859 Merge metadata setters and transform applications if they're both specified 2024-08-12 18:24:38 +01:00
Graham Esau
eb3077742f Optimise applying metadata
This reduces the output MIR size of the example code from https://github.com/GREsau/schemars/issues/246 by ~50% (from 18k to 9k lines)
2024-08-12 18:21:25 +01:00
Graham Esau
14b06e71ba
Add transform = ... attribute (#312)
This allows running arbitrary transforms on generated schemas when deriving `JsonSchema`
2024-08-10 09:56:52 +01:00
Graham Esau
ce15380863
Do not collapse newlines in doc comments (#310) 2024-08-04 16:43:22 +01:00
Graham Esau
840315b2dd
Add #[schemars(extend("key" = value))] attribute (#297) 2024-06-05 21:09:52 +01:00
Graham Esau
760403e2f5 Update doc comments and make SchemaGenerator available from crate root 2024-05-27 11:09:15 +01:00
Graham Esau
f8b56cb455 Replace is_referenceable() with always_inline_schema() 2024-05-26 16:51:42 +01:00
Graham Esau
1aaa162e0b Make schema_name() return Cow<'static, str> instead of String 2024-05-26 15:20:56 +01:00
Graham Esau
3aa0e7fa3c
Support JSON Schema draft 2020-12 and use it by default (#294) 2024-05-19 20:49:45 +01:00
Graham Esau
c4d42ec11a Refactor flatten and move it to _private, remove TempFixupForTests, regenerate test schemas 2024-05-13 22:02:32 +01:00
Graham Esau
18300c67bb
Use const instead of single-valued enum (#291) 2024-05-13 21:30:51 +01:00
Graham Esau
3b3870ca82 Simplify flatten
No longer use it for internally-tagged enums. Instead, use a private helper that adds the tag property.
2024-05-13 10:52:42 +01:00
Graham Esau
342cd5fd09
Define Schema as a newtype around serde_json::Value (#289) 2024-05-12 19:23:54 +01:00
Graham Esau
1a40d1b06c Fix deriving JsonSchema on enum without variants
Fixes #287
2024-05-06 18:12:20 +01:00
Graham Esau
d04c17bda4
Simplify generated enum code (#286)
* simplify the code generated for unit enums
* simplify generated code for validating object properties
* optimize internal and externally tagged enums

---------

Co-authored-by: Robin Appelman <robin@icewind.nl>
2024-05-06 13:54:13 +01:00
Graham Esau
df00e2fd71 Add comment explaining why we double-parse an Expr 2024-04-28 18:59:42 +01:00
Graham Esau
9501fe319f Update to syn 2 and serde_derive_internals 0.29 2024-04-28 18:56:06 +01:00
Graham Esau
ae9544aaf9 Put schema value into a variable before calling apply_metadata
This reduces size of MIR output, which should somewhat mitigate #246
2023-11-11 20:28:10 +00:00
Graham Esau
342b2dff33
Add schema_id(), handles different types with the same name (#247) 2023-09-17 20:36:52 +01:00
Jakub Jirutka
a5e51b22b3
Add #[schemars(inner(...)] attribute to specify schema for array items (#234) 2023-09-09 13:35:53 +01:00
Graham Esau
37478d764e
Support types with const generics (#239)
Co-authored-by: Spencer Sharkey <spsharkey@tesla.com>
2023-08-27 20:50:20 +01:00
Graham Esau
072730f6f6 Resolve clippy warnings 2023-08-20 18:14:04 +01:00
Graham Esau
824993ca76 Apply clippy fixes 2023-02-26 19:59:17 +00:00
Graham Esau
39bae201eb Run cargo fmt 2023-02-26 19:47:10 +00:00
Graham Esau
c59e5b5e1c Fix test 2022-10-02 19:46:29 +01:00
Graham Esau
4754a13fb3 Ignore bound set in serde attrs 2022-10-02 19:46:29 +01:00
Graham Esau
104dccca50 Add #[schemars(bound = ...)] attribute
Based on https://github.com/GREsau/schemars/pull/162

Co-authored-by: teozkr <teo@nullable.se>
2022-10-02 19:46:29 +01:00
Adam Leventhal
76427ef384
Fix handling of attributes applied to unit variant types (#152) 2022-08-12 15:37:34 +01:00
Graham Esau
d93bdc43e3 Revert "Support generic default values"
This feature inadvertently introduced a breaking change (#144)

This reverts commits: feb6c4b2fe
b38a55331b.
2022-05-17 18:17:17 +01:00
Andy Weiss
115a9eebf2 Add license notice to regex_syntax.rs
The comment in the code says this code was copied from another source
with an appropriate link. However just local to this file it is not
clear what the license terms of that code are. I added the license
notice to this file that governs the particular code that was copied
over.

I would like to use this crate in an environment where we want to be
clear about licensing. Hopefully this is an okay change otherwise I
would be more than happy to do this a different way as long as the
license provenance is clear.
2022-05-15 22:33:24 +01:00
Graham Esau
feb6c4b2fe Use as instead of immediately-invoked typed function 2022-05-15 22:30:38 +01:00
Graeme Coupar
b38a55331b Support generic default values
I'm trying to `derive(JsonSchema)` on a field with a default that relies
on type inference to determine it's return type.  This causes compile
errors because schemars calls the default function without providing
any types for inference to use.

This changes that - wraps the `default` in a closure with a defined
return value that it immediately calls.  Feels a bit hacky, but I
couldn't think of a better way to fix this.
2022-05-15 22:30:38 +01:00
Adam H. Leventhal
98ad16288b Internally tagged enums don't honor deny_unknown_fields as precisely as
they might.

flatten doesn't act quite as intended with regard to
additional_properties
2021-11-25 21:55:48 +00:00
Graham Esau
690fe44343 Allow non-Serialize default values.
Default values that don't implement Serialize are now ignored, rather than causing a compile error.
This is done by simulating specialization using a technique copied from Rocket:
5ebefa97c9/core/lib/src/sentinel.rs (L391-L445)

Fixes #115
2021-11-14 19:16:46 +00:00