← Back to Home

Frameworks & Tools

Full Ecosystem

Frameworks & Tools Ecosystem Enum Guide

Enum usage spans the entire tech stack—from backend frameworks to API documentation, from game engines to hardware description languages. This guide summarizes enum implementation approaches in mainstream frameworks and tools, helping you use enums correctly in various scenarios.

This guide covers enum support in ecosystems like Rails, Laravel, Pydantic, Swagger/OpenAPI, GraphQL, Godot, Unity, SystemVerilog.

Backend Frameworks: Rails, Laravel, Django, Phoenix

Backend frameworks typically provide enum support, but implementation approaches vary. Understanding each framework's characteristics helps you choose the most suitable solution.

Rails · ActiveRecord enum

class Order < ApplicationRecord
  enum status: {
    pending: 'pending',
    paid: 'paid',
    refunded: 'refunded'
  }, _prefix: true
end

# i18n:
# en:
#   activerecord:
#     attributes:
#       order/status:
#         pending: Pending

Rails' enum macro automatically generates query methods and scopes, very convenient. Combined with i18n, it enables multilingual display.

Laravel & PHP 8.1 Enum

enum OrderStatus: string
{
    case Pending = 'pending';
    case Paid = 'paid';
    case Refunded = 'refunded';
}

// Eloquent attribute casting
protected $casts = [
    'status' => OrderStatus::class,
];

PHP 8.1 introduced native enums, Laravel 9+ fully supports them. Eloquent automatically handles type conversion.

Pydantic & FastAPI

Use enums in Python environments to generate OpenAPI documentation, with `Enum`/`StrEnum` preserving string values.

Pydantic automatically validates enum values, FastAPI lists all options in Swagger documentation.

Elixir Enum (Enum Module)

Although Elixir doesn't have native enums, `Ecto.Enum` and functions like `Enum.reduce`, `Enum.all?` are commonly used for restricted sets.

Ecto provides Enum field types that can automatically convert between database and application layers.

API Documentation & Frontend Integration

Enum definitions in API documentation are key to frontend-backend collaboration. Protocols like OpenAPI and GraphQL support enums, making interfaces clearer and easier to use.

Swagger / OpenAPI

status:
  type: string
  enum: [pending, paid, refunded]
  description: Order processing stage
  examples:
    - pending

OpenAPI's enum field supports adding descriptions and examples, Swagger UI automatically displays dropdown lists.

GraphQL & ProtoBuf

GraphQL enum definitions, client caching strategies; ProtoBuf enums and version compatibility (handling `no enum constant` issues).

GraphQL enums are part of the type system, ProtoBuf enums need attention to compatibility during version evolution.

Game Engines & Domain Specialization

In scenarios like Godot, Unity, SystemVerilog, enums typically play roles in configuration, state, and signals.

Godot & GDScript

enum State {
  IDLE,
  RUN,
  JUMP
}

@export var player_state: State

func _process(delta):
  match player_state:
    State.IDLE:
      pass
    State.RUN:
      pass

Godot's @export annotation allows enums to display as dropdown lists in the editor, convenient for configuration.

Unity & C# / SystemVerilog

Display enums in Unity Inspector, `[Flags]` extension; SystemVerilog `typedef enum` and `$cast` usage points.

Unity also supports exporting enums to the editor; SystemVerilog is used for hardware description, enums make state machines clearer.

Framework Integration Playbooks

  • Rails / Laravel / Django enum field checklist
  • GraphQL & Swagger enum consistency test scripts
  • Godot / Unity enum naming templates
  • Quick case overview: rails enum, laravel enum, swagger enum, graphql enum, godot enum, systemverilog enum

FAQ

How to display descriptions in Swagger enum?

Add `description` and `examples` in the schema, and provide explanations in tables corresponding to enum values. Combine with `.net core swagger schema enum values description example` template.

Does Rails enum support string values?

Yes, from Rails 7 onwards supports `enum status: { pending: 'pending' }`, and can combine with `_prefix`, `_suffix` to avoid method conflicts.

Can Godot enums be exported to the editor?

Use `@export var state: State` to select enum values in Inspector, combine with `match` to write state machines.

How to maintain multilingual descriptions in GraphQL enums?

Provide multilingual descriptions at schema comment and documentation levels, and map to i18n text in client code; GraphQL spec allows custom directives.