Skip to content

Generate an enum of all operationIds #954

Open

Description

@czechboy0

Although I was thinking more along the lines of having all the operationId string values being consolidated in an enum, not necessarily the operations themselves. My use case would be for permissions checking:

// Given a state where operationId is enum based
// Somewhere generated:
enum OperationId: String, RawRepresentable, Codable, Sendable, CaseIterable {
  case .userCreate = Operations.UserCreate.id
  case .userUpdate = Operations.UserUpdate.id
  case .userDelete = Operations.UserDelete.id
}

static let restrictedRoutes: [OperationId] { 
  [
    .userDelete
  ]
}

Then in middleware, server, even a SwiftUI project you could check it a little easier. It's possible now through manually entering the raw values into [String] for restrictedRoutes (which I think I'm gonna end up doing) but either what you had written before or something like this feels like it'd be a bit more fun to use.

EDIT: my apologies I think this isn't necessarily the right issue for what I was thinking of.

Originally posted by @mheh in #32

Activity

  1. mheh commented on Sep 28, 2026

    @mheh

    I appreciate the new issue. I'm still down for the above in some form. Do you have ideas on where the OperationId enum would live or a different view of the types written above?

  2. czechboy0 commented on Sep 28, 2026

    @czechboy0
    ContributorAuthor

    My initial instinct is a top-level OperationIDs enum. But I haven't given it much thought yet. Open to other ideas.

  3. mheh commented on Sep 29, 2026

    @mheh

    Considering:

    let operationId1: String = "operation1"
    
    enum OperationId: String, RawRepresentable<String>, Codable, CaseIterable {
        case operation1 = operationId1
    }

    isn't possible due Raw value for enum case must be a literal error. How do you feel about the inverse?

    enum OperationId: String, RawRepresentable<String>, Codable, CaseIterable {
        case operation1 = "operation1"
    }
    
    let operationId1: String = OperationId.operation1.rawValue

    it seems like a bit of a pattern change, rather since the current Operations.OperationName.id is the reference string type atm. It'd shift it to the OperationId enum.
    If could be opt-in to generate in addition to the outputted types.
    Or since this is a generator, if you're OK with having duplicates. I assume there's overhead that's not negligible doing duplicates though.

  4. czechboy0 commented on Sep 29, 2026

    @czechboy0
    ContributorAuthor

    I'm not concerned about the duplication, but I like the id property simply referencing the value from the new enum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/generatorAffects: plugin, CLI, config file.kind/featureNew feature.status/needs-designNeeds further discussion and a concrete proposal.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions