### OpenAPI Document Structure Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md This is an example of an OpenAPI 3.0.3 document structure containing schemas with enums. ```yaml openapi: 3.0.3 info: title: Example OpenApi description version: 0.0.0 components: schemas: Status: enum: - ACTIVE - INACTIVE type: string ColorsEnum: enum: - GREEN - RED type: string InvalidCase: enum: - SOME/WEIRD-Strings - another.weird.string - just(another)weird string type: string StartWithNumber: enum: - 250x330 - 70x40 - OTHER type: string WithCurlyBrackets: enum: - "{INSIDE_CURLY_BRACKETS}" ``` -------------------------------- ### Prefix Enum Keys Starting with Numbers Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md The `--prenum` option allows prefixing enum keys that start with a number. By default, an underscore is used. This example uses '$' as the prefix. ```typescript [...] export enum StartWithNumber { $250x330 = "250x330", $70x40 = "70x40", OTHER = "OTHER" } [...] ``` -------------------------------- ### Combining flags for full pipeline Source: https://context7.com/mrdannael/genum-openapi/llms.txt All flags can be composed together for a comprehensive enum generation pipeline. This example demonstrates combining normalize, uppercase, suffix, prefix, and exclude flags for a production-ready invocation. ```bash # schema.yaml has: AgencyInvoicingType, AgencyRevenueType, AgencyServiceTypeEnum, # AgencyStatus (with messy values), Email.Status npx genum-openapi ./schema.yaml \ --uppercase \ --normalize \ --suffix \ --prefix I \ --exclude AgencyRevenueType \ --output ./src/generated/enums.ts ``` -------------------------------- ### Generate Specific Enum with Exclusion Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md Use the `--exclude` option to generate only the desired enums. This example shows generating only `ColorsEnum` by excluding others. ```bash --exclude Status InvalidCase StartWithNumber WithCurlyBrackets ``` -------------------------------- ### Custom prefix for digit-starting keys Source: https://context7.com/mrdannael/genum-openapi/llms.txt Use `--prenum` to override the default `_` prefix for enum keys that start with a digit. The custom prefix can be any string consisting of `_`, `$`, or letters. An invalid prefix will result in an error. ```bash # Default behavior (underscore prefix) npx genum-openapi ./schema.yaml ``` ```bash # Custom $ prefix npx genum-openapi ./schema.yaml --prenum '$' ``` ```bash # Invalid prenum (only _, $, letters allowed) — throws error: npx genum-openapi ./schema.yaml --prenum '-' ``` -------------------------------- ### Basic Enum Generation to Stdout Source: https://context7.com/mrdannael/genum-openapi/llms.txt Generates TypeScript enums from an OpenAPI schema file and prints them to standard output. Handles schemas with string enums and automatically prefixes keys that start with digits. ```bash # Input: schema.yaml # openapi: 3.0.3 # components: # schemas: # AgencyInvoicingType: # enum: [INVOICE_PER_AGENCY, INVOICE_PER_ACCOUNT] # type: string # AgencyStatus: # enum: [ACTIVE, ARCHIVED] # type: string # ImageSize: # enum: [300x250, 180x150, OTHER] # values start with digits # Print to stdout npx genum-openapi ./schema.yaml # Expected stdout: # export enum AgencyInvoicingType { # INVOICE_PER_AGENCY = "INVOICE_PER_AGENCY", # INVOICE_PER_ACCOUNT = "INVOICE_PER_ACCOUNT" # } # # export enum AgencyStatus { # ACTIVE = "ACTIVE", # ARCHIVED = "ARCHIVED" # } # # export enum ImageSize { # _300x250 = "300x250", # digit-starting keys get a _ prefix automatically # _180x150 = "180x150", # OTHER = "OTHER" # } ``` -------------------------------- ### Custom String Replacements Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md The `--custom-replacers` option allows defining custom regular expressions and replacement strings. This example replaces curly braces `{}` with an empty string using a custom replacer. ```typescript [...] export enum WithCurlyBrackets { INSIDE_CURLY_BRACKETS = "{INSIDE_CURLY_BRACKETS}" } [...] ``` -------------------------------- ### Import and Use Generated Enums in TypeScript Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md After generating the enum file, import the desired enum and use it within your TypeScript code. This example shows how to check a status against a generated enum. ```typescript import { StatusEnum } from "./path/to/generated/enums"; export const App = () => { if (status === StatusEnum.SUCCESS) { console.log("Enum successfully generated and used"); } else { console.log("Enum failed to generate"); } }; ``` -------------------------------- ### Generated Enum from JSON Input Source: https://context7.com/mrdannael/genum-openapi/llms.txt Example of a TypeScript enum generated from a JSON OpenAPI schema. ```typescript export enum Status { ACTIVE = "ACTIVE", INACTIVE = "INACTIVE" } ``` -------------------------------- ### Add Prefix to Enum Names Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md The `--prefix` option adds a specified string to the beginning of all generated enum names. This example prefixes enum names with 'I'. ```typescript export enum IStatus { [...] } export enum IColorsEnum { [...] } export enum IInvalidCase { [...] } export enum IStartWithNumber { [...] } export enum IWithCurlyBrackets { [...] } ``` -------------------------------- ### Normalize and Uppercase Enum Keys Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md Use `--normalize` and `--uppercase` options to parse enum values and convert enum keys to uppercase. This example shows the transformation of `InvalidCase` enum. ```typescript [...] export enum INVALIDCASE { SOME_WEIRD_STRINGS = "SOME/WEIRD-Strings", ANOTHER__WEIRD__STRING = "another.weird.string" JUST_ANOTHER_WEIRD_STRING = "just(another)weird string" } [...] ``` -------------------------------- ### Development npm Scripts Source: https://context7.com/mrdannael/genum-openapi/llms.txt Common npm scripts for building, testing, and linting the gEnum OpenAPI project. ```bash # Build the CLI binary to ./bin/cli.js yarn build # Run the full test suite (builds first, then runs vitest) yarn test # Run tests with coverage report yarn test:coverage # Open the Vitest interactive UI with coverage yarn test:ui # Type-check without emitting yarn typecheck # Lint TypeScript source files yarn lint:ts # Format all files with Prettier yarn prettier ``` -------------------------------- ### Generate Enums with Custom Options Source: https://context7.com/mrdannael/genum-openapi/llms.txt Use the -uns, -p, and -x flags to normalize, prefix, and exclude specific enums during generation. ```bash npx genum-openapi ./schema.yaml -uns -p I -x AgencyRevenueType -o ./src/generated/enums.ts ``` -------------------------------- ### Integrate with openapi-typescript Source: https://context7.com/mrdannael/genum-openapi/llms.txt Generate TypeScript interfaces and enums from the same OpenAPI file for consistent type definitions. ```bash # Step 1: Generate TypeScript interfaces npx openapi-typescript ./api/openapi.yaml -o ./src/generated/schema.d.ts # Step 2: Generate TypeScript enums npx genum-openapi ./api/openapi.yaml -o ./src/generated/enums.ts ``` -------------------------------- ### Custom regex substitutions for normalization Source: https://context7.com/mrdannael/genum-openapi/llms.txt Use `--custom-replacers` or `-r` with a JSON array of `{ regExp, replaceWith }` objects to apply custom regex substitutions on top of default replacements during normalization. The special string `"empty"` is treated as an empty string `""`. This option must be used with `--normalize` (or its variants) to take effect. ```bash # schema has BasedOnEnum with key: {INSIDE_CURLY_BRACES} # Goal: strip the { and } characters npx genum-openapi ./schema.yaml \ --custom-replacers '[{ "regExp":"[{}]", "replaceWith": "empty" }]' \ --normalize ``` ```bash # Multiple custom replacers npx genum-openapi ./schema.yaml \ --custom-replacers '[{"regExp":"[{}]","replaceWith":"empty"},{"regExp":"[@]","replaceWith":"AT"}]' \ --normalize ``` -------------------------------- ### Convert names and keys to uppercase Source: https://context7.com/mrdannael/genum-openapi/llms.txt Use `--uppercase` or `-u` to convert all generated enum names and keys to uppercase. This is often combined with `--normalize` for clean ALL_CAPS identifiers. Use `--uppercase-keys` or `--uppercase-names` to target only one side. ```bash # schema has AgencyInvoicingType with keys: Invoice_per_agency, Invoice_per_account npx genum-openapi ./schema.yaml --uppercase ``` ```bash # Keys only npx genum-openapi ./schema.yaml --uppercase-keys ``` ```bash # Names only npx genum-openapi ./schema.yaml --uppercase-names ``` -------------------------------- ### Generate Enums from JSON OpenAPI Source: https://context7.com/mrdannael/genum-openapi/llms.txt gEnum OpenAPI supports JSON input files. The file extension determines the input format. ```bash npx genum-openapi ./openapi.json ``` -------------------------------- ### Generate TypeScript Enums from OpenAPI Schema Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md Use this command to generate a TypeScript file containing enums from your OpenAPI schema. Specify the input schema file and the desired output file path. ```bash npx genum-openapi ./path/to/the/schema.yaml -o ./path/to/generated/enums.ts ``` -------------------------------- ### Generate Enums and Save to File Source: https://context7.com/mrdannael/genum-openapi/llms.txt Generates TypeScript enums from an OpenAPI schema and saves them to a specified output file. This is useful for organizing generated types within your project. ```bash # Write to a file npx genum-openapi ./schema.yaml --output ./src/generated/enums.ts # 🔥 genum-openapi v0.7.0 # 🚢 Enums generated successfully! [12ms] ``` ```typescript // Then import in application code: // import { AgencyStatus } from "./src/types/enums"; // // if (agency.status === AgencyStatus.ACTIVE) { // console.log("Agency is active"); // } ``` -------------------------------- ### Use Generated Types and Enums Source: https://context7.com/mrdannael/genum-openapi/llms.txt Import and utilize generated TypeScript interfaces and enums in your application code. ```typescript # import type { components } from "./generated/schema"; # import { AgencyStatus } from "./generated/enums"; # # type Agency = components["schemas"]["Agency"]; # # function isActive(agency: Agency): boolean { # return agency.status === AgencyStatus.ACTIVE; # } ``` -------------------------------- ### Add Prefix to Enum Names Source: https://context7.com/mrdannael/genum-openapi/llms.txt Prepends a specified string to all generated enum names using the `--prefix` flag. This is often used for namespacing or adhering to naming conventions. ```bash npx genum-openapi ./schema.yaml --prefix I # schema has: AgencyInvoicingType, AgencyStatus # Output: # export enum IAgencyInvoicingType { # INVOICE_PER_AGENCY = "INVOICE_PER_AGENCY", # INVOICE_PER_ACCOUNT = "INVOICE_PER_ACCOUNT" # } # # export enum IAgencyStatus { # ACTIVE = "ACTIVE", # ARCHIVED = "ARCHIVED" # } ``` -------------------------------- ### Exclude Specific Enum Schemas Source: https://context7.com/mrdannael/genum-openapi/llms.txt Generates TypeScript enums while skipping specified schemas using the `--exclude` flag. This is useful for avoiding conflicts or unnecessary types. ```bash # schema.yaml has: AgencyServiceTypeEnum, AgencyStatus, Email.Status, AgencyInvoicingType npx genum-openapi ./schema.yaml --exclude AgencyServiceTypeEnum AgencyStatus "Email.Status" # Output contains only AgencyInvoicingType — the three excluded names are skipped entirely. # export enum AgencyInvoicingType { # INVOICE_PER_AGENCY = "INVOICE_PER_AGENCY", # INVOICE_PER_ACCOUNT = "INVOICE_PER_ACCOUNT" # } ``` -------------------------------- ### Add Suffix to Enum Names Source: https://context7.com/mrdannael/genum-openapi/llms.txt Appends a string to generated enum names using the `--suffix` flag. If no value is provided, it defaults to 'Enum'. It avoids duplicating the suffix if the name already ends with it. ```bash # Default suffix "Enum" npx genum-openapi ./schema.yaml --suffix # Status → StatusEnum (suffix added) # ColorsEnum → ColorsEnum (already ends with "Enum", not duplicated) # Custom suffix npx genum-openapi ./schema.yaml --suffix TSEnum # Status → StatusTSEnum # ColorsEnum → ColorsEnumTSEnum ``` -------------------------------- ### Normalize invalid identifier characters Source: https://context7.com/mrdannael/genum-openapi/llms.txt Use `--normalize` or `-n` to replace characters illegal in TypeScript identifiers within enum names and keys. Default replacements map `.` to `__` and `-`, `/`, `(`, `)`, and space to `_`. This is applied to both names and keys simultaneously. Use `--normalize-names` or `--normalize-keys` to target only one side. ```bash npx genum-openapi ./schema.yaml --normalize ``` ```bash # Normalize only keys, leave names untouched npx genum-openapi ./schema.yaml --normalize-keys ``` ```bash # Normalize only names, leave keys untouched npx genum-openapi ./schema.yaml --normalize-names ``` -------------------------------- ### Add Suffix to Enum Names Source: https://github.com/mrdannael/genum-openapi/blob/master/README.md The `--suffix` option appends a specified string to the end of all generated enum names. If not provided, 'Enum' is used as the default suffix. ```typescript export enum StatusEnum { [...] } export enum ColorsEnum { [...] } export enum InvalidCaseEnum { [...] } export enum StartWithNumberEnum { [...] } export enum WithCurlyBracketsEnum { [...] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.