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.
- copy the provided openapi spec (includes correct enum name)
- run
dart run swagger_parser && dart run build_runner build
- 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
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 theswagger_parserignores the openapi spec and applies pascal camel case regardless.dart run swagger_parser && dart run build_runner buildk_user_status.dartEven trying to apply smart regex in
replacementconfig gets overwritten by case-fixing logic.The PR #459 fixes that adds a new config key named
preserve_schema_casingwhich defaults tofalseto 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 buildLogs
Logs
Not needed.
Dart version and used packages versions
Dart version
3.11.5 (stable) macos_arm64Packages version
1.43.1