Browse Source

Merge pull request #157 from provokateurin/feature/skip-default-parameters

dynamite,nextcloud: Skip default parameters
pull/158/head
Kate 2 years ago committed by GitHub
parent
commit
e6a4141944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      packages/dynamite/lib/src/openapi_builder.dart
  2. 52
      packages/nextcloud/lib/src/nextcloud.openapi.dart

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

@ -573,6 +573,10 @@ class OpenAPIBuilder implements Builder {
parameter.schema!,
);
final defaultValueCode = parameter.schema?.default_ != null
? _valueToEscapedValue(result.name, parameter.schema!.default_!.toString())
: null;
b.optionalParameters.add(
Parameter(
(final b) {
@ -581,17 +585,6 @@ class OpenAPIBuilder implements Builder {
..name = _toDartName(parameter.name)
..required = parameter.required ?? false;
if (parameter.schema != null) {
if (parameter.schema!.default_ != null) {
final value = parameter.schema!.default_!.toString();
final result = resolveType(
spec,
state,
parameter.schema!.type!,
parameter.schema!,
);
b.defaultTo = Code(_valueToEscapedValue(result.name, value));
}
b.type = refer(
_makeNullable(
result.name,
@ -599,6 +592,9 @@ class OpenAPIBuilder implements Builder {
),
);
}
if (defaultValueCode != null) {
b.defaultTo = Code(defaultValueCode);
}
},
),
);
@ -611,6 +607,9 @@ class OpenAPIBuilder implements Builder {
result.serialize(_toDartName(parameter.name)),
onlyChildren: isPlainList && parameter.in_ == 'query',
);
if (defaultValueCode != null && parameter.in_ != 'path') {
code.write('if (${_toDartName(parameter.name)} != $defaultValueCode) {');
}
switch (parameter.in_) {
case 'path':
code.write(
@ -630,6 +629,9 @@ class OpenAPIBuilder implements Builder {
default:
throw Exception('Can not work with parameter in "${parameter.in_}"');
}
if (defaultValueCode != null) {
code.write('}');
}
if (nullable) {
code.write('}');
}

52
packages/nextcloud/lib/src/nextcloud.openapi.dart

@ -262,12 +262,24 @@ class CoreClient {
final queryParameters = <String, dynamic>{};
final headers = <String, String>{};
Uint8List? body;
if (file != '') {
queryParameters['file'] = file.toString();
}
if (x != 32) {
queryParameters['x'] = x.toString();
}
if (y != 32) {
queryParameters['y'] = y.toString();
}
if (a != 0) {
queryParameters['a'] = a.toString();
}
if (forceIcon != 1) {
queryParameters['forceIcon'] = forceIcon.toString();
}
if (mode != 'fill') {
queryParameters['mode'] = mode.toString();
}
final response = await rootClient.doRequest(
'get',
Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(),
@ -584,12 +596,24 @@ class NewsClient {
final queryParameters = <String, dynamic>{};
final headers = <String, String>{};
Uint8List? body;
if (type != 3) {
queryParameters['type'] = type.toString();
}
if (id != 0) {
queryParameters['id'] = id.toString();
}
if (getRead != 1) {
queryParameters['getRead'] = getRead.toString();
}
if (batchSize != -1) {
queryParameters['batchSize'] = batchSize.toString();
}
if (offset != 0) {
queryParameters['offset'] = offset.toString();
}
if (oldestFirst != 0) {
queryParameters['oldestFirst'] = oldestFirst.toString();
}
final response = await rootClient.doRequest(
'get',
Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(),
@ -611,9 +635,15 @@ class NewsClient {
final queryParameters = <String, dynamic>{};
final headers = <String, String>{};
Uint8List? body;
if (type != 3) {
queryParameters['type'] = type.toString();
}
if (id != 0) {
queryParameters['id'] = id.toString();
}
if (lastModified != 0) {
queryParameters['lastModified'] = lastModified.toString();
}
final response = await rootClient.doRequest(
'get',
Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(),
@ -719,9 +749,15 @@ class NotesClient {
if (category != null) {
queryParameters['category'] = category.toString();
}
if (exclude != '') {
queryParameters['exclude'] = exclude.toString();
}
if (pruneBefore != 0) {
queryParameters['pruneBefore'] = pruneBefore.toString();
}
if (chunkSize != 0) {
queryParameters['chunkSize'] = chunkSize.toString();
}
if (chunkCursor != null) {
queryParameters['chunkCursor'] = chunkCursor.toString();
}
@ -753,11 +789,21 @@ class NotesClient {
final queryParameters = <String, dynamic>{};
final headers = <String, String>{};
Uint8List? body;
if (category != '') {
queryParameters['category'] = category.toString();
}
if (title != '') {
queryParameters['title'] = title.toString();
}
if (content != '') {
queryParameters['content'] = content.toString();
}
if (modified != 0) {
queryParameters['modified'] = modified.toString();
}
if (favorite != 0) {
queryParameters['favorite'] = favorite.toString();
}
final response = await rootClient.doRequest(
'post',
Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(),
@ -780,7 +826,9 @@ class NotesClient {
final headers = <String, String>{};
Uint8List? body;
path = path.replaceAll('{id}', Uri.encodeQueryComponent(id.toString()));
if (exclude != '') {
queryParameters['exclude'] = exclude.toString();
}
if (ifNoneMatch != null) {
headers['If-None-Match'] = ifNoneMatch.toString();
}
@ -822,7 +870,9 @@ class NotesClient {
if (category != null) {
queryParameters['category'] = category.toString();
}
if (favorite != 0) {
queryParameters['favorite'] = favorite.toString();
}
if (ifMatch != null) {
headers['If-Match'] = ifMatch.toString();
}
@ -1023,7 +1073,9 @@ class NotificationsClient {
Uint8List? body;
path = path.replaceAll('{userId}', Uri.encodeQueryComponent(userId.toString()));
queryParameters['shortMessage'] = shortMessage.toString();
if (longMessage != '') {
queryParameters['longMessage'] = longMessage.toString();
}
final response = await rootClient.doRequest(
'post',
Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(),

Loading…
Cancel
Save