cddl-codegen
cddl-codegen copied to clipboard
Handle runs of uppercase letters for name generation
Previous handling of uppercase letters in @name generation was not ideal
Notably, @name NFT would result in the generated rust code having functions like new_n_f_t instead of new_nft
This PR should fix this.
Two other things this PR does:
- Fixed the clippy error (doesn't look like it was caused by this PR)
- Adds the missing
WASM_BINDGEN_WEAKREF=1that should be added to the generatedpackage.json
Shelley_m_a
I figured out the bug here (it happens even if the name is just m_a
What is happening is that the value passed to convert_to_snake_case is not the comment DSL value as-is. Rather, the label gets converted to camel case first
In both parse_group and create_variants_from_type_choices we do
let variant_ident = VariantIdent::new_custom(convert_to_camel_case(&ident_name));
EnumVariant::new(variant_ident, ty, serialize_as_embedded)
so if you start with m_a
convert_to_camel_case("m_a")→MAconvert_to_snake_case("MA")→ma(with this new PR)
not sure what is the best way to solve this in the code without making a mess of everything
@SebastienGllmt I updated this and fixed the issues we had with things like shelley_ma, etc. The general approach seems to be to either do ShelleyMA or for general cddl consistency/similarity to our usual cddl defs from IOHK shelley_MA (snake case everywhere but runs of uppercases are recommended to be in all-caps e.g. IP_address, VRF_vkey, etc)