Skip to content

BUG: lower case enum converted to upper case + fixing PR provided #458

Description

@iOSonntag

Steps to reproduce

We have an internal guideline that prefixes every enum with the letter k (lower case) enforced by a custom Dart linter. Currently the swagger_parser ignores the openapi spec and applies pascal camel case regardless.

  1. copy the provided openapi spec (includes correct enum name)
  2. run dart run swagger_parser && dart run build_runner build
  3. find generated k_user_status.dart

Even trying to apply smart regex in replacement config gets overwritten by case-fixing logic.

The PR #459 fixes that adds a new config key named preserve_schema_casing which defaults to false to preserve legacy behavior. Upon activation, it respects the exact casings in the openapi spec.

Expected results

... enum kUserStatus { ...

Actual results

... enum KUserStatus { ...

Your OpenApi snippet

{
  "openapi": "3.0.2",
  "paths": {
    "/something": {
      "patch": {
        "parameters": [],
        "operationId": "changeStatus",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangeStatusRequest"
              }
            }
          }
        },
        "responses": {}
      }
    }
  },
  "components": {
    "schemas": {
      "kUserStatus": {
        "type": "string",
        "enum": [
          "PENDING",
          "ACTIVE"
        ],
        "title": "kUserStatus"
      },
      "ChangeStatusRequest": {
        "type": "object",
        "properties": {
          "newStatus": {
            "$ref": "#/components/schemas/kUserStatus"
          }
        },
        "title": "ChangeStatusRequest"
      }
    }
  }
}

Code sample

Code sample
dart run swagger_parser && dart run build_runner build

Logs

Logs

Not needed.

Dart version and used packages versions

Dart version
3.11.5 (stable) macos_arm64
Packages version
1.43.1

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions