Skip to content

Commit

Permalink
fix: Fix partial comments. (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored May 24, 2024
1 parent 72a6d53 commit c3d2bd1
Show file tree
Hide file tree
Showing 6 changed files with 757 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

#### 🐞 Fixes

- Fixed partial containers missing their comments.

## 0.16.2

#### 🚀 Updates
Expand Down
22 changes: 15 additions & 7 deletions crates/macros/src/common/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,22 @@ impl<'l> Variant<'l> {
}
TaggedFormat::Untagged => inner,
TaggedFormat::External => {
quote! {
{
let mut item = Schema::structure(StructType::new([
(#name.into(), #inner),
]));
#partial_statement
item
let outer = quote! {
Schema::structure(StructType::new([
(#name.into(), #inner),
]))
};

if partial {
quote! {
{
let mut item = #outer;
#partial_statement
item
}
}
} else {
outer
}
}
TaggedFormat::Internal(tag) => {
Expand Down
28 changes: 28 additions & 0 deletions crates/schematic/tests/generator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ mod json_schema {
assert_snapshot!(fs::read_to_string(file).unwrap());
}

#[test]
fn partials() {
let sandbox = create_empty_sandbox();
let file = sandbox.path().join("schema.json");

let mut generator = create_generator();
generator.add::<PartialGenConfig>();
generator
.generate(&file, JsonSchemaRenderer::default())
.unwrap();

assert_snapshot!(fs::read_to_string(file).unwrap());
}

#[test]
fn not_required() {
let sandbox = create_empty_sandbox();
Expand Down Expand Up @@ -323,6 +337,20 @@ mod typescript {
assert_snapshot!(generate(TypeScriptOptions::default()));
}

#[test]
fn partials() {
let sandbox = create_empty_sandbox();
let file = sandbox.path().join("types.ts");

let mut generator = create_generator();
generator.add::<PartialGenConfig>();
generator
.generate(&file, TypeScriptRenderer::new(TypeScriptOptions::default()))
.unwrap();

assert_snapshot!(fs::read_to_string(file).unwrap());
}

#[test]
fn enums() {
assert_snapshot!(generate(TypeScriptOptions {
Expand Down
Loading

0 comments on commit c3d2bd1

Please sign in to comment.