Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Bump `sigil-stitch` to 0.6.8

## [0.1.14]

### Added
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.148"
serde_norway = "0.9.42"
serde_plain = "1.0.2"
sigil-stitch = "0.6.7"
sigil-stitch = "0.6.8"
similar = "2.7.0"
snafu = "0.8.9"
toml = "0.9.8"
Expand Down
27 changes: 10 additions & 17 deletions src/generators/java/okhttp/sigil_emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,15 @@ fn emit_object(schema: &IrSchema, obj: &IrObject, package_name: &str) -> Option<
.expect("ctor param"),
);
}
let assignments: Vec<CodeBlock> = obj
let assignment_fields: Vec<String> = obj
.properties
.iter()
.map(|(_json_name, prop)| {
let field_name = java_field_name(&prop.name);
sigil_quote!(Java {
this.$L(field_name.as_str()) = $L(field_name.as_str());
})
.expect("assignment")
})
.map(|(_json_name, prop)| java_field_name(&prop.name))
.collect();
let ctor_body = sigil_quote!(Java {
$C_each(assignments);
$for(field_name in &assignment_fields) {
this.$L(field_name.as_str()) = $L(field_name.as_str());
}
})
.expect("ctor body");
ctor = ctor.body(ctor_body);
Expand Down Expand Up @@ -412,17 +408,14 @@ fn emit_intersection(
.expect("param"),
);
}
let assignments: Vec<CodeBlock> = member_bindings
let assignment_fields: Vec<String> = member_bindings
.iter()
.map(|(_member_type, field_name)| {
sigil_quote!(Java {
this.$L(field_name.as_str()) = $L(field_name.as_str());
})
.expect("assignment")
})
.map(|(_member_type, field_name)| field_name.clone())
.collect();
let ctor_body = sigil_quote!(Java {
$C_each(assignments);
$for(field_name in &assignment_fields) {
this.$L(field_name.as_str()) = $L(field_name.as_str());
}
})
.expect("ctor body");
ctor = ctor.body(ctor_body);
Expand Down
30 changes: 12 additions & 18 deletions src/generators/java/okhttp/sigil_emit_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,20 @@ fn build_response_class(plan: &OpPlan<'_>) -> TypeSpec {
.expect("param"),
);
}
let mut field_assignments: Vec<CodeBlock> = vec![
sigil_quote!(Java { this.statusCode = statusCode; }).expect("assign"),
sigil_quote!(Java { this.raw = raw; }).expect("assign"),
];
let mut assignment_fields = Vec::new();
let mut body_seen: HashSet<String> = HashSet::new();
for tr in &plan.typed_responses {
if !body_seen.insert(tr.field_name.clone()) {
continue;
}
field_assignments.push(
sigil_quote!(Java {
this.$L(tr.field_name.as_str()) = $L(tr.field_name.as_str());
})
.expect("assign"),
);
assignment_fields.push(tr.field_name.clone());
}
let ctor_body = sigil_quote!(Java {
$C_each(field_assignments);
this.statusCode = statusCode;
this.raw = raw;
$for(field_name in &assignment_fields) {
this.$L(field_name.as_str()) = $L(field_name.as_str());
}
})
.expect("ctor body");
ctor = ctor.body(ctor_body);
Expand Down Expand Up @@ -442,13 +438,11 @@ fn emit_method_body(plan: &OpPlan<'_>) -> CodeBlock {
dedup_args.push(a);
}
}
cb.add_statement(
&format!(
"return new {}({})",
plan.response_type,
dedup_args.join(", ")
),
(),
cb.add_code(
sigil_quote!(Java {
return new $N(plan.response_type.as_str())($for(arg in &dedup_args; separator = ", ") { $L(arg.as_str()) });
})
.expect("typed response constructor return"),
);
} else {
cb.add_statement(
Expand Down
8 changes: 5 additions & 3 deletions src/generators/kotlin/okhttp/sigil_emit_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,11 @@ fn emit_method_body(plan: &OpPlan<'_>) -> CodeBlock {
dedup_fields.push(f);
}
}
cb.add(
&format!("return {}({})", plan.response_type, dedup_fields.join(", ")),
(),
cb.add_code(
sigil_quote!(Kotlin {
return $N(plan.response_type.as_str())($for(field in &dedup_fields; separator = ", ") { $L(field.as_str()) })
})
.expect("typed response constructor return"),
);
} else {
cb.add(
Expand Down
11 changes: 5 additions & 6 deletions src/generators/python/httpx/emit_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,11 @@ fn build_method_body(plan: &OpPlan<'_>, ir: &IrSpec, error_type: &TypeName) -> C
request_args.push("headers=headers".to_string());
}

cb.add_statement(
&format!(
"response = self._client.request({})",
request_args.join(", "),
),
(),
cb.add_code(
sigil_quote!(Python {
response = self._client.request($for(arg in &request_args; separator = ", ") { $L(arg.as_str()) })
})
.expect("request call"),
);

// Error handling
Expand Down
20 changes: 6 additions & 14 deletions src/generators/python/httpx/emit_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,12 @@ fn format_type_alias(name: &str, members: &[TypeName]) -> CodeBlock {
})
.unwrap();
}
// Multi-member: CodeBlock::builder() for precise line-break control.
// Python sigil_quote! $for merges output inline (no leading \n), unlike
// Go mode which preserves template newlines. This is the only case where
// we deviate from sigil_quote! — see sigil-stitch issue.
let mut cb = CodeBlock::builder();
cb.add(
"type %N = (\n %T",
(NameArg(name.to_string()), members[0].clone()),
);
for member in &members[1..] {
cb.add("\n | %T", (member.clone(),));
}
cb.add("\n)", ());
cb.build_unwrap()
sigil_quote!(Python {
type $N(name) = (
$L(" ")$for(member in members; separator = "\n | ") { $T((*member).clone()) }
)
})
.unwrap()
}

// ---------------------------------------------------------------------------
Expand Down
11 changes: 5 additions & 6 deletions src/generators/python/requests/emit_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,11 @@ fn build_method_body(plan: &OpPlan<'_>, ir: &IrSpec, error_type: &TypeName) -> C
request_args.push("headers=headers".to_string());
}

cb.add_statement(
&format!(
"response = self._client.request({})",
request_args.join(", "),
),
(),
cb.add_code(
sigil_quote!(Python {
response = self._client.request($for(arg in &request_args; separator = ", ") { $L(arg.as_str()) })
})
.expect("request call"),
);

// Error handling
Expand Down
20 changes: 6 additions & 14 deletions src/generators/python/requests/emit_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,12 @@ fn format_type_alias(name: &str, members: &[TypeName]) -> CodeBlock {
})
.unwrap();
}
// Multi-member: CodeBlock::builder() for precise line-break control.
// Python sigil_quote! $for merges output inline (no leading \n), unlike
// Go mode which preserves template newlines. This is the only case where
// we deviate from sigil_quote! — see sigil-stitch issue.
let mut cb = CodeBlock::builder();
cb.add(
"type %N = (\n %T",
(NameArg(name.to_string()), members[0].clone()),
);
for member in &members[1..] {
cb.add("\n | %T", (member.clone(),));
}
cb.add("\n)", ());
cb.build_unwrap()
sigil_quote!(Python {
type $N(name) = (
$L(" ")$for(member in members; separator = "\n | ") { $T((*member).clone()) }
)
})
.unwrap()
}

// ---------------------------------------------------------------------------
Expand Down
Loading
Loading