Skip to content

Commit

Permalink
Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed May 24, 2024
1 parent 4f89b6f commit 391678c
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 66 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## Unreleased

#### 🚀 Updates

- Brought back the concept of `SchemaField`, as it solved some edge cases related to structs.

#### 🐞 Fixes

- Fixed missing container comments for `ConfigEnum`.
- Fixed missing container comments.

## 0.16.1

Expand Down
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 28 additions & 24 deletions book/src/schema/enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,42 @@ schema.enumerable(EnumType::new([
## Detailed variants

If you'd like to provide more detailed information for each variant (value), like descriptions and
visibility, you can define the `variants` field and pass a list of
[`Schema`](https://docs.rs/schematic/latest/schematic/struct.Schema.html)s.
visibility, you can define the `variants` field and pass a map of
[`SchemaField`](https://docs.rs/schematic/latest/schematic/struct.SchemaField.html)s.

```rust
use schematic::Schema;

schema.enumerable(EnumType {
values: vec![
LiteralValue::String("debug".into()),
LiteralValue::String("error".into()),
LiteralValue::String("warning".into()),
],
variants: Some(vec![
Schema {
name: "debug".into(),
description: Some("Shows debug messages and above".into()),
ty: SchemaType::literal(LiteralValue::String("debug".into())),
..Schema::default()
},
Schema {
name: "error".into(),
description: Some("Shows only error messages".into()),
ty: SchemaType::literal(LiteralValue::String("error".into())),
..Schema::default()
},
Schema {
name: "warning".into(),
description: Some("Shows warning and error messages".into()),
ty: SchemaType::literal(LiteralValue::String("warning".into())),
..Schema::default()
},
]),
variants: Some(IndexMap::from_iter([
(
"Debug".into(),
SchemaField {
comment: Some("Shows debug messages and above".into()),
schema: Schema::new(SchemaType::literal(LiteralValue::String("debug".into()))),
..SchemaField::default()
}
),
(
"Error".into(),
SchemaField {
comment: Some("Shows only error messages".into()),
schema: Schema::new(SchemaType::literal(LiteralValue::String("error".into()))),
..SchemaField::default()
}
),
(
"Warning".into(),
SchemaField {
comment: Some("Shows warning and error messages".into()),
schema: Schema::new(SchemaType::literal(LiteralValue::String("warning".into()))),
..SchemaField::default()
}
),
])),
..EnumType::default()
})
```
Expand Down
36 changes: 16 additions & 20 deletions book/src/schema/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,26 @@ impl Schematic for T {
fields: HashMap::from_iter([
(
"name".into(),
Box::new(Schema {
name: "name".into(),
description: Some("Name of the user".into()),
ty: schema.infer::<String>(),
..Schema::default()
Box::new(SchemaField {
comment: Some("Name of the user".into()),
schema: schema.infer::<String>(),
..SchemaField::default()
})
),
(
"age".into(),
Box::new(Schema {
name: "age".into(),
description: Some("Age of the user".into()),
ty: schema.nest().integer(IntegerType::new_kind(IntegerKind::U16)),
..Schema::default()
Box::new(SchemaField {
comment: Some("Age of the user".into()),
schema: schema.nest().integer(IntegerType::new_kind(IntegerKind::U16)),
..SchemaField::default()
})
),
(
"active".into(),
Box::new(Schema {
name: "active".into(),
description: Some("Is the user active".into()),
ty: schema.infer::<bool>(),
..Schema::default()
Box::new(SchemaField {
comment: Some("Is the user active".into()),
schema: schema.infer::<bool>(),
..SchemaField::default()
})
),
]),
Expand All @@ -52,11 +49,10 @@ method. When using this approach, the `Box`s are automatically inserted for you.
schema.structure(StructType::new([
(
"name".into(),
Schema {
name: "name".into(),
description: Some("Name of the user".into()),
ty: schema.infer::<String>(),
..Schema::default()
SchemaField {
comment: Some("Name of the user".into()),
schema: schema.infer::<String>(),
..SchemaField::default()
}
),
// ...
Expand Down
2 changes: 1 addition & 1 deletion crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ convert_case = "0.6.0"
darling = "0.20.9"
proc-macro2 = "1.0.83"
quote = "1.0.36"
syn = { version = "2.0.65", features = ["full"] }
syn = { version = "2.0.66", features = ["full"] }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion crates/schematic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ serde_json = { workspace = true, optional = true, features = [

# json schema
markdown = { version = "1.0.0-alpha.17", optional = true }
schemars = { version = "0.8.20", optional = true, default-features = false }
schemars = { version = "0.8.21", optional = true, default-features = false }

# toml
toml = { workspace = true, optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ expression: "generate(TypeScriptOptions {\n enum_format: EnumFormat::Valu

/* eslint-disable */

/** Docblock comment. */
export enum BasicEnum {
Foo = 'foo',
Bar = 'bar',
Expand All @@ -14,6 +15,7 @@ export enum BasicEnum {

export type FallbackEnum = 'foo' | 'bar' | 'baz' | string;

/** Some comment. */
export interface AnotherConfig {
/**
* An optional enum.
Expand Down
2 changes: 1 addition & 1 deletion crates/types/src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::*;
use indexmap::IndexMap;
pub use indexmap::IndexMap;

#[derive(Clone, Debug, Default, PartialEq)]
pub struct EnumType {
Expand Down

0 comments on commit 391678c

Please sign in to comment.