Commit graph

48 commits

Author SHA1 Message Date
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
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
9501fe319f Update to syn 2 and serde_derive_internals 0.29 2024-04-28 18:56:06 +01:00
Graham Esau
342b2dff33
Add schema_id(), handles different types with the same name (#247) 2023-09-17 20:36:52 +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
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
Adam Leventhal
0a1200baac
Use oneOf for enums when possible (#108) 2021-09-26 18:02:44 +01:00
Graham Esau
605db3bba8 Emit compilation errors for duplicate validation attributes 2021-09-17 23:04:37 +01:00
Graham Esau
d99a96fc8a Add some doc comments 2021-04-24 11:46:07 +01:00
Graham Esau
5f841f2e5c Refactoring 2021-04-16 17:02:57 +01:00
Graham Esau
4be21bd811 Refactor out "local_id" for type definitions 2021-04-16 14:23:10 +01:00
Graham Esau
9e507272da Process validation attributes in tuple structs 2021-04-16 13:56:26 +01:00
Graham Esau
31a5893d10 Process validation attributes in newtype structs 2021-04-16 12:30:52 +01:00
Graham Esau
60a9869448 Refactor out add_schema_as_property 2021-04-16 10:42:03 +01:00
Graham Esau
1a2dafc1a5 Handle required flattened Option fields 2021-04-15 18:11:28 +01:00
Graham Esau
b68132f17d Merge branch 'master' into validate 2021-04-15 16:08:10 +01:00
Graham Esau
55b860428e Refactory of private functions 2021-04-15 13:34:04 +01:00
Graham Esau
5dc644000c Allow schema_with attr on enum variants 2021-04-10 15:16:16 +01:00
Graham Esau
ebd7ff32ce More fixes for deriving JsonSchema inside macro 2021-04-05 16:40:20 +01:00
Graham Esau
4d3400152e
Fix deriving JsonSchema inside macro (#79) 2021-04-05 16:15:34 +01:00
Graham Esau
6ab567f3a5 Read #[validate(...)] attributes 2021-03-29 16:38:55 +01:00
Graham Esau
11d95b79e5
Derive JsonSchema_repr (#76) 2021-03-25 22:36:28 +00:00
Graham Esau
6a3bba1e86 Set additionalProperties to false on enums where appropriate 2021-03-20 18:45:29 +00:00
Graham Esau
3a7d7ad905 Apply some clippy suggestions 2021-03-19 23:20:16 +00:00
Graham Esau
1b42dc7e3e Allow overriding title/desc from doc comments (#13) 2020-05-17 11:19:48 +01:00
Graham Esau
5a28cef598 Respect #[serde(transparent)] attribute (#17) 2020-05-16 21:16:59 +01:00
Graham Esau
509a1c3b7b Check for #[deprecated] attributes 2020-05-16 16:44:44 +01:00
Graham Esau
bfb3f06253 Avoid setting ObjectValidation unnecessarily 2020-05-16 12:10:54 +01:00
Denis Kurilov
1190b1fad9
additionalProperties: false for struct annotated with serde deny_unknown_fields (#30)
Co-authored-by: Denis Kurilov <denis@routinghub.com>
2020-05-16 12:02:47 +01:00
Graham Esau
ea351f3b42 Set type on enum schemas (#28) 2020-05-16 10:41:30 +01:00
Graham Esau
3fd316063a schema_with attribute 2020-05-15 17:11:28 +01:00
Graham Esau
780c7286a6 Refactor attribute parsing to make it more extensible 2020-05-12 21:17:34 +01:00
Graham Esau
b1ded882b7 More refactoring of proc macro... 2020-05-11 21:53:36 +01:00