- 
                Notifications
    
You must be signed in to change notification settings  - Fork 221
 
Description
Example of an Unnamed Enum in Smithy
In Smithy, an unnamed enum (or "string enum") would be defined like this:
namespace example.api
@enum([
    {value: "SMALL"},
    {value: "MEDIUM"},
    {value: "LARGE"}
])
string SizeThis is an unnamed enum because the variants don't have explicit names separate from their values. In contrast, a named enum would include both name and value for each variant.
Current Generated Python Code
The current implementation generates code like this:
impl Size {
    #[getter]
    pub fn name(&self) -> &str {
        match self {
            Size::SMALL => null,  // Error: 'null' is not defined
            Size::MEDIUM => null, // Error: 'null' is not defined
            Size::LARGE => null,  // Error: 'null' is not defined
        }
    }
    #[getter]
    pub fn value(&self) -> &str {
        self.as_str()
    }
    fn __repr__(&self) -> String {
        self.as_str().to_owned()
    }
    fn __str__(&self) -> String {
        self.as_str().to_owned()
    }
}Issue
The problem is that for unnamed enums, the name() method is attempting to return a name for each variant, but since these are unnamed enums, there is no separate name defined in the Smithy model. The generated code incorrectly uses null as the return value, which isn't defined, causing compilation errors.
Expected Behavior
For unnamed enums, the name() method should not be generated at all, since these enums only have values without separate names. The code generator should detect whether an enum is named or unnamed and only generate the name() method for named enums.
Proposed Solution
Modify the code generator to skip generating the name() method when processing unnamed enums in Smithy models.