Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dart] Use raw strings for json/header parameter names #8131

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class {{classname}} {
{{/isFile}}
{{/isMultipart}}
{{^isMultipart}}
formData['{{baseName}}'] = parameterToString(_serializers, {{paramName}});
formData[r'{{baseName}}'] = parameterToString(_serializers, {{paramName}});
{{/isMultipart}}
{{/formParams}}
bodyData = FormData.fromMap(formData);
Expand Down
10 changes: 5 additions & 5 deletions modules/openapi-generator/src/main/resources/dart2/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ class {{{classname}}} {

{{#headerParams}}
{{#required}}
headerParams['{{{baseName}}}'] = parameterToString({{{paramName}}});
headerParams[r'{{{baseName}}}'] = parameterToString({{{paramName}}});
{{/required}}
{{^required}}
if ({{{paramName}}} != null) {
headerParams['{{{baseName}}}'] = parameterToString({{{paramName}}});
headerParams[r'{{{baseName}}}'] = parameterToString({{{paramName}}});
}
{{/required}}
{{/headerParams}}
Expand All @@ -109,13 +109,13 @@ class {{{classname}}} {
{{^isFile}}
if ({{{paramName}}} != null) {
hasFields = true;
mp.fields['{{{baseName}}}'] = parameterToString({{{paramName}}});
mp.fields[r'{{{baseName}}}'] = parameterToString({{{paramName}}});
}
{{/isFile}}
{{#isFile}}
if ({{{paramName}}} != null) {
hasFields = true;
mp.fields['{{{baseName}}}'] = {{{paramName}}}.field;
mp.fields[r'{{{baseName}}}'] = {{{paramName}}}.field;
mp.files.add({{{paramName}}});
}
{{/isFile}}
Expand All @@ -127,7 +127,7 @@ class {{{classname}}} {
{{#formParams}}
{{^isFile}}
if ({{{paramName}}} != null) {
formParams['{{{baseName}}}'] = parameterToString({{{paramName}}});
formParams[r'{{{baseName}}}'] = parameterToString({{{paramName}}});
}
{{/isFile}}
{{/formParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ class ApiClient {
{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
_authentications['{{{name}}}'] = HttpBasicAuth();
_authentications[r'{{{name}}}'] = HttpBasicAuth();
{{/isBasicBasic}}
{{#isBasicBearer}}
_authentications['{{{name}}}'] = HttpBearerAuth();
_authentications[r'{{{name}}}'] = HttpBearerAuth();
{{/isBasicBearer}}
{{/isBasic}}
{{#isApiKey}}
_authentications['{{{name}}}'] = ApiKeyAuth({{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{^isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}{{/isKeyInCookie}}, '{{{keyParamName}}}');
_authentications[r'{{{name}}}'] = ApiKeyAuth({{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{^isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}{{/isKeyInCookie}}, '{{{keyParamName}}}');
{{/isApiKey}}
{{#isOAuth}}
_authentications['{{{name}}}'] = OAuth();
_authentications[r'{{{name}}}'] = OAuth();
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
Expand Down
64 changes: 32 additions & 32 deletions modules/openapi-generator/src/main/resources/dart2/class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ class {{{classname}}} {
if ({{{name}}} != null) {
{{#isDateTime}}
{{#pattern}}
json['{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
json[r'{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
? {{{name}}}.millisecondsSinceEpoch
: {{{name}}}.toUtc().toIso8601String();
{{/pattern}}
{{^pattern}}
json['{{{baseName}}}'] = {{{name}}}.toUtc().toIso8601String();
json[r'{{{baseName}}}'] = {{{name}}}.toUtc().toIso8601String();
{{/pattern}}
{{/isDateTime}}
{{#isDate}}
{{#pattern}}
json['{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
json[r'{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
? {{{name}}}.millisecondsSinceEpoch
: _dateFormatter.format({{{name}}}.toUtc());
{{/pattern}}
{{^pattern}}
json['{{{baseName}}}'] = _dateFormatter.format({{{name}}}.toUtc());
json[r'{{{baseName}}}'] = _dateFormatter.format({{{name}}}.toUtc());
{{/pattern}}
{{/isDate}}
{{^isDateTime}}
{{^isDate}}
json['{{{baseName}}}'] = {{{name}}};
json[r'{{{baseName}}}'] = {{{name}}};
{{/isDate}}
{{/isDateTime}}
}
Expand All @@ -90,106 +90,106 @@ class {{{classname}}} {
: {{{classname}}}(
{{#vars}}
{{#isDateTime}}
{{{name}}}: json['{{{baseName}}}'] == null
{{{name}}}: json[r'{{{baseName}}}'] == null
? null
{{#pattern}}
: _dateEpochMarker == '{{{pattern}}}'
? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true)
: DateTime.parse(json['{{{baseName}}}']),
? DateTime.fromMillisecondsSinceEpoch(json[r'{{{baseName}}}'] as int, isUtc: true)
: DateTime.parse(json[r'{{{baseName}}}']),
{{/pattern}}
{{^pattern}}
: DateTime.parse(json['{{{baseName}}}']),
: DateTime.parse(json[r'{{{baseName}}}']),
{{/pattern}}
{{/isDateTime}}
{{#isDate}}
{{{name}}}: json['{{{baseName}}}'] == null
{{{name}}}: json[r'{{{baseName}}}'] == null
? null
{{#pattern}}
: _dateEpochMarker == '{{{pattern}}}'
? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true)
: DateTime.parse(json['{{{baseName}}}']),
? DateTime.fromMillisecondsSinceEpoch(json[r'{{{baseName}}}'] as int, isUtc: true)
: DateTime.parse(json[r'{{{baseName}}}']),
{{/pattern}}
{{^pattern}}
: DateTime.parse(json['{{{baseName}}}']),
: DateTime.parse(json[r'{{{baseName}}}']),
{{/pattern}}
{{/isDate}}
{{^isDateTime}}
{{^isDate}}
{{#complexType}}
{{#isArray}}
{{#items.isArray}}
{{{name}}}: json['{{{baseName}}}'] == null
{{{name}}}: json[r'{{{baseName}}}'] == null
? null
: (json['{{{baseName}}}'] as List).map(
: (json[r'{{{baseName}}}'] as List).map(
{{#items.complexType}}
{{items.complexType}}.listFromJson(json['{{{baseName}}}'])
{{items.complexType}}.listFromJson(json[r'{{{baseName}}}'])
{{/items.complexType}}
{{^items.complexType}}
(e) => e == null ? null : (e as List).cast<{{items.items.dataType}}>()
{{/items.complexType}}
).toList(growable: false),
{{/items.isArray}}
{{^items.isArray}}
{{{name}}}: {{{complexType}}}.listFromJson(json['{{{baseName}}}']),
{{{name}}}: {{{complexType}}}.listFromJson(json[r'{{{baseName}}}']),
{{/items.isArray}}
{{/isArray}}
{{^isArray}}
{{#isMap}}
{{#items.isArray}}
{{{name}}}: json['{{{baseName}}}'] == null
{{{name}}}: json[r'{{{baseName}}}'] == null
? null
{{#items.complexType}}
: {{items.complexType}}.mapListFromJson(json['{{{baseName}}}']),
: {{items.complexType}}.mapListFromJson(json[r'{{{baseName}}}']),
{{/items.complexType}}
{{^items.complexType}}
: (json['{{{baseName}}}'] as Map).cast<String, List>(),
: (json[r'{{{baseName}}}'] as Map).cast<String, List>(),
{{/items.complexType}}
{{/items.isArray}}
{{^items.isArray}}
{{{name}}}: json['{{{baseName}}}'] == null
{{{name}}}: json[r'{{{baseName}}}'] == null
? null
: {{{complexType}}}.mapFromJson(json['{{{baseName}}}']),
: {{{complexType}}}.mapFromJson(json[r'{{{baseName}}}']),
{{/items.isArray}}
{{/isMap}}
{{^isMap}}
{{#isBinary}}
{{{name}}}: null, // No support for decoding binary content from JSON
{{/isBinary}}
{{^isBinary}}
{{{name}}}: {{{complexType}}}.fromJson(json['{{{baseName}}}']),
{{{name}}}: {{{complexType}}}.fromJson(json[r'{{{baseName}}}']),
{{/isBinary}}
{{/isMap}}
{{/isArray}}
{{/complexType}}
{{^complexType}}
{{#isArray}}
{{#isEnum}}
{{{name}}}: {{{classname}}}{{{items.datatypeWithEnum}}}.listFromJson(json['{{{baseName}}}']),
{{{name}}}: {{{classname}}}{{{items.datatypeWithEnum}}}.listFromJson(json[r'{{{baseName}}}']),
{{/isEnum}}
{{^isEnum}}
{{{name}}}: json['{{{baseName}}}'] == null
{{{name}}}: json[r'{{{baseName}}}'] == null
? null
: (json['{{{baseName}}}'] as List).cast<{{{items.datatype}}}>(),
: (json[r'{{{baseName}}}'] as List).cast<{{{items.datatype}}}>(),
{{/isEnum}}
{{/isArray}}
{{^isArray}}
{{#isMap}}
{{{name}}}: json['{{{baseName}}}'] == null ?
{{{name}}}: json[r'{{{baseName}}}'] == null ?
null :
(json['{{{baseName}}}'] as Map).cast<String, {{{items.datatype}}}>(),
(json[r'{{{baseName}}}'] as Map).cast<String, {{{items.datatype}}}>(),
{{/isMap}}
{{^isMap}}
{{#isNumber}}
{{{name}}}: json['{{{baseName}}}'] == null ?
{{{name}}}: json[r'{{{baseName}}}'] == null ?
null :
json['{{{baseName}}}'].toDouble(),
json[r'{{{baseName}}}'].toDouble(),
{{/isNumber}}
{{^isNumber}}
{{^isEnum}}
{{{name}}}: json['{{{baseName}}}'],
{{{name}}}: json[r'{{{baseName}}}'],
{{/isEnum}}
{{#isEnum}}
{{{name}}}: {{{classname}}}{{{enumName}}}.fromJson(json['{{{baseName}}}']),
{{{name}}}: {{{classname}}}{{{enumName}}}.fromJson(json[r'{{{baseName}}}']),
{{/isEnum}}
{{/isNumber}}
{{/isMap}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ class PetApi {
List<String> contentTypes = ["application/x-www-form-urlencoded"];

Map<String, dynamic> formData = {};
formData['name'] = parameterToString(_serializers, name);
formData['status'] = parameterToString(_serializers, status);
formData[r'name'] = parameterToString(_serializers, name);
formData[r'status'] = parameterToString(_serializers, status);
bodyData = FormData.fromMap(formData);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class PetApi {
final formParams = <String, String>{};

if (apiKey != null) {
headerParams['api_key'] = parameterToString(apiKey);
headerParams[r'api_key'] = parameterToString(apiKey);
}

final contentTypes = <String>[];
Expand Down Expand Up @@ -485,21 +485,21 @@ class PetApi {
final mp = MultipartRequest(null, null);
if (name != null) {
hasFields = true;
mp.fields['name'] = parameterToString(name);
mp.fields[r'name'] = parameterToString(name);
}
if (status != null) {
hasFields = true;
mp.fields['status'] = parameterToString(status);
mp.fields[r'status'] = parameterToString(status);
}
if (hasFields) {
postBody = mp;
}
} else {
if (name != null) {
formParams['name'] = parameterToString(name);
formParams[r'name'] = parameterToString(name);
}
if (status != null) {
formParams['status'] = parameterToString(status);
formParams[r'status'] = parameterToString(status);
}
}

Expand Down Expand Up @@ -575,19 +575,19 @@ class PetApi {
final mp = MultipartRequest(null, null);
if (additionalMetadata != null) {
hasFields = true;
mp.fields['additionalMetadata'] = parameterToString(additionalMetadata);
mp.fields[r'additionalMetadata'] = parameterToString(additionalMetadata);
}
if (file != null) {
hasFields = true;
mp.fields['file'] = file.field;
mp.fields[r'file'] = file.field;
mp.files.add(file);
}
if (hasFields) {
postBody = mp;
}
} else {
if (additionalMetadata != null) {
formParams['additionalMetadata'] = parameterToString(additionalMetadata);
formParams[r'additionalMetadata'] = parameterToString(additionalMetadata);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ part of openapi.api;
class ApiClient {
ApiClient({this.basePath = 'http://petstore.swagger.io/v2'}) {
// Setup authentications (key: authentication name, value: authentication).
_authentications['api_key'] = ApiKeyAuth('header', 'api_key');
_authentications['petstore_auth'] = OAuth();
_authentications[r'api_key'] = ApiKeyAuth('header', 'api_key');
_authentications[r'petstore_auth'] = OAuth();
}

final String basePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class ApiResponse {
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
if (code != null) {
json['code'] = code;
json[r'code'] = code;
}
if (type != null) {
json['type'] = type;
json[r'type'] = type;
}
if (message != null) {
json['message'] = message;
json[r'message'] = message;
}
return json;
}
Expand All @@ -60,9 +60,9 @@ class ApiResponse {
static ApiResponse fromJson(Map<String, dynamic> json) => json == null
? null
: ApiResponse(
code: json['code'],
type: json['type'],
message: json['message'],
code: json[r'code'],
type: json[r'type'],
message: json[r'message'],
);

static List<ApiResponse> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class Category {
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
if (id != null) {
json['id'] = id;
json[r'id'] = id;
}
if (name != null) {
json['name'] = name;
json[r'name'] = name;
}
return json;
}
Expand All @@ -51,8 +51,8 @@ class Category {
static Category fromJson(Map<String, dynamic> json) => json == null
? null
: Category(
id: json['id'],
name: json['name'],
id: json[r'id'],
name: json[r'name'],
);

static List<Category> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
Expand Down
Loading