-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
When OpenAPI enum values contain special characters (like @
, /
, -
, .
), Hawaii generates F# discriminated union cases that require backticks or have invalid identifiers. Better sanitization with [<CompiledName>]
attributes would improve code quality.
OpenAPI Source
# From Cloudflare Vectorize OpenAPI spec
vectorizeindex-preset:
type: string
enum:
- "@cf/baai/bge-small-en-v1.5" # Special characters: @, /, -, .
- "@cf/baai/bge-base-en-v1.5"
- "openai/text-embedding-ada-002"
- "cohere/embed-multilingual-v2.0"
Current Hawaii Output
// From CloudflareFS: src/Management/CloudFlare.Management.Vectorize/Types.fs (line 40)
[<Fable.Core.StringEnum; RequireQualifiedAccess>]
type ``vectorizeindex-preset`` =
| [<CompiledName "@cf/baai/bge-small-en-v1.5">] ``@cfBaaiBgeSmallEnV1Numeric_5``
| [<CompiledName "@cf/baai/bge-base-en-v1.5">] ``@cfBaaiBgeBaseEnV1Numeric_5``
| [<CompiledName "openai/text-embedding-ada-002">] OpenaiTextEmbeddingAdaNumeric_002
member this.Format() =
match this with
| ``@cfBaaiBgeSmallEnV1Numeric_5`` -> "@cf/baai/bge-small-en-v1.5"
| ``@cfBaaiBgeBaseEnV1Numeric_5`` -> "@cf/baai/bge-base-en-v1.5"
// ...
Problems
- Backticks required: Cases starting with
@
need backticks (`@cfBaaiBge...`
) - Inconsistent naming: Some cases have backticks, others don't
- Poor readability:
Numeric_5
suffix is unclear (represents.5
from version number) - Pattern matching awkward: Users must remember which cases need backticks
Proposed Improvement
[<Fable.Core.StringEnum; RequireQualifiedAccess>]
type ``vectorizeindex-preset`` =
| [<CompiledName "@cf/baai/bge-small-en-v1.5">] CfBaaiBgeSmallEnV15
| [<CompiledName "@cf/baai/bge-base-en-v1.5">] CfBaaiBgeBaseEnV15
| [<CompiledName "@cf/baai/bge-large-en-v1.5">] CfBaaiBgeLargeEnV15
| [<CompiledName "openai/text-embedding-ada-002">] OpenAiTextEmbeddingAda002
| [<CompiledName "cohere/embed-multilingual-v2.0">] CohereEmbedMultilingualV20
member this.Format() =
match this with
| CfBaaiBgeSmallEnV15 -> "@cf/baai/bge-small-en-v1.5"
| CfBaaiBgeBaseEnV15 -> "@cf/baai/bge-base-en-v1.5"
// ...
Benefits
// Clean pattern matching - no backticks needed
match preset with
| CfBaaiBgeSmallEnV15 -> "Small model"
| CfBaaiBgeBaseEnV15 -> "Base model"
| OpenAiTextEmbeddingAda002 -> "OpenAI model"
// JSON serialization still works correctly:
// "@cf/baai/bge-small-en-v1.5"
Sanitization Rules
- Remove leading special characters (
@
,-
, etc.) - Convert
/
,-
,.
to word boundaries for PascalCase - Convert version numbers intelligently:
v1.5
→V15
, notV1Numeric_5
- Always use
[<CompiledName>]
to preserve original JSON value - Ensure all cases use consistent naming (all with or all without backticks)
CloudflareFS Workaround
We accept the generated backticks and work with them in pattern matching. The Format()
member method provides a way to get the original string value.
Metadata
Metadata
Assignees
Labels
No labels