Browse Source

fix _toDartName

pull/201/head
Nikolas Rimikis 2 years ago
parent
commit
929dab205e
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 34
      packages/dynamite/lib/src/openapi_builder.dart

34
packages/dynamite/lib/src/openapi_builder.dart

@ -975,37 +975,27 @@ class OpenAPIBuilder implements Builder {
String _clientName(final String tag) => '${_toDartName(tag, uppercaseFirstCharacter: true)}Client'; String _clientName(final String tag) => '${_toDartName(tag, uppercaseFirstCharacter: true)}Client';
String _toDartName( String _toDartName(
final String input, { final String name, {
final bool uppercaseFirstCharacter = false, final bool uppercaseFirstCharacter = false,
}) { }) {
final result = StringBuffer(); var result = '';
var upperCase = uppercaseFirstCharacter;
final parts = input.split(''); var firstCharacter = !uppercaseFirstCharacter;
for (var i = 0; i < parts.length; i++) { for (final char in name.split('')) {
var char = parts[i];
final prevChar = i > 0 ? parts[i - 1] : null;
if (_isNonAlphaNumericString(char)) { if (_isNonAlphaNumericString(char)) {
continue; upperCase = true;
}
if (prevChar != null && _isNonAlphaNumericString(prevChar)) {
char = char.toUpperCase();
}
if (i == 0) {
if (uppercaseFirstCharacter) {
char = char.toUpperCase();
} else { } else {
char = char.toLowerCase(); result += firstCharacter ? char.toLowerCase() : (upperCase ? char.toUpperCase() : char);
} upperCase = false;
firstCharacter = false;
} }
result.write(char);
} }
final out = result.toString(); if (_dartKeywords.contains(result) || RegExp(r'^[0-9]+$', multiLine: true).hasMatch(result)) {
if (_dartKeywords.contains(out) || RegExp(r'^[0-9]+$', multiLine: true).hasMatch(out)) { return '\$$result';
return '\$$out';
} }
return out; return result;
} }
final _dartKeywords = [ final _dartKeywords = [

Loading…
Cancel
Save