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

Fix multipart requests generation #155

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix docs for parametrs in multipart
StarProxima committed Jan 20, 2024
commit d1ec1e5f8668ffdcfd5ba00a86bcbfa03ece4b44
16 changes: 9 additions & 7 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ class OpenApiParser {
types.add(
UniversalRequestType(
parameterType: HttpParameterType.part,
description: requestBody[_descriptionConst]?.toString(),
description: currentType.description,
type: UniversalType(
type: currentType.type,
name: 'file',
@@ -344,9 +344,10 @@ class OpenApiParser {
contentType[_schemaConst] as Map<String, dynamic>;
if (schemaContent.containsKey(_propertiesConst)) {
final requiredParameters =
(schemaContent[_requiredConst] as List<dynamic>)
.map((e) => e.toString())
.toList();
(schemaContent[_requiredConst] as List<dynamic>?)
?.map((e) => e.toString())
.toList() ??
[];

for (final e
in (schemaContent[_propertiesConst] as Map<String, dynamic>)
@@ -363,7 +364,7 @@ class OpenApiParser {
UniversalRequestType(
parameterType: HttpParameterType.part,
name: e.key,
description: requestBody[_descriptionConst]?.toString(),
description: currentType.description,
type: UniversalType(
type: currentType.type,
name: e.key,
@@ -393,7 +394,7 @@ class OpenApiParser {
types.add(
UniversalRequestType(
parameterType: HttpParameterType.body,
description: requestBody[_descriptionConst]?.toString(),
description: currentType.description,
type: UniversalType(
type: currentType.type,
name: _bodyConst,
@@ -546,14 +547,15 @@ class OpenApiParser {
final parametersDescription = parameters
.where((e) => e.description != null)
.map((e) => '[${e.name?.toCamel ?? 'body'}] - ${e.description}')
.join('\n')
.join('\n\n')
.trim();
description = switch ((description, parametersDescription)) {
(null, '') || ('', '') => null,
(_, '') => description,
(null, _) || ('', _) => parametersDescription,
(_, _) => '$description\n\n$parametersDescription',
};
// End build full description

String requestName;

2 changes: 1 addition & 1 deletion swagger_parser/lib/src/utils/type_utils.dart
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ final _nameRegExp = RegExp(r'^[a-zA-Z_][a-zA-Z\d_]*$');
(null, null) => null,
(null, _) => error,
(_, null) => description,
(_, _) => '$description\n\n$error',
(_, _) => '$description\n$error',
},
);
}
1 change: 1 addition & 0 deletions swagger_parser/test/generator/rest_clients_test.dart
Original file line number Diff line number Diff line change
@@ -969,6 +969,7 @@ interface ClassNameClient {
const fillController = FillController();
final filledContent = fillController.fillRestClientContent(restClient);
const expectedContents = '''
import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';