Skip to content

Commit

Permalink
wit-parser: use serde kebab-case (bytecodealliance#1964)
Browse files Browse the repository at this point in the history
Fixes an issue in JSON serialization where error-context serialized to errorcontext.
  • Loading branch information
ydnar authored Dec 26, 2024
1 parent 57b1ace commit 8229bc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions crates/wit-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct InterfaceSpan {

#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum AstItem {
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_id"))]
Interface(InterfaceId),
Expand Down Expand Up @@ -471,7 +471,7 @@ impl WorldKey {

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum WorldItem {
/// An interface is being imported or exported from a world, indicating that
/// it's a namespace of functions.
Expand Down Expand Up @@ -557,7 +557,7 @@ pub struct TypeDef {

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum TypeDefKind {
Record(Record),
Resource,
Expand Down Expand Up @@ -609,7 +609,7 @@ impl TypeDefKind {

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum TypeOwner {
/// This type was defined within a `world` block.
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_id"))]
Expand All @@ -625,7 +625,7 @@ pub enum TypeOwner {

#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum Handle {
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_id"))]
Own(TypeId),
Expand Down Expand Up @@ -886,7 +886,7 @@ pub struct Function {

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum FunctionKind {
Freestanding,
#[cfg_attr(feature = "serde", serde(serialize_with = "serialize_id"))]
Expand Down Expand Up @@ -1154,7 +1154,7 @@ fn find_futures_and_streams(resolve: &Resolve, ty: Type, results: &mut Vec<TypeI
/// annotations were added to WIT.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde_derive::Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum Stability {
/// `@since(version = 1.2.3)`
///
Expand Down
4 changes: 2 additions & 2 deletions crates/wit-parser/tests/ui/error-context.wit.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
"types": [
{
"name": "t1",
"kind": "errorcontext",
"kind": "error-context",
"owner": {
"interface": 0
}
},
{
"name": null,
"kind": "errorcontext",
"kind": "error-context",
"owner": null
},
{
Expand Down

0 comments on commit 8229bc6

Please sign in to comment.