Skip to content

Commit

Permalink
Rename to original_http_response
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik committed Oct 20, 2023
1 parent 3fa8a32 commit 976b765
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
3 changes: 3 additions & 0 deletions swagger_parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.10.3
- Add new config parameter `original_http_response`(only for dart) ([#115](https://github.com/Carapacik/swagger_parser/issues/115))

## 1.10.2
- Fix error in `body` with name in dart template

Expand Down
3 changes: 3 additions & 0 deletions swagger_parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ swagger_parser:
# Optional. Set 'false' to not put a comment at the beginning of the generated files.
mark_files_as_generated: true
# Optional (dart only). Set 'true' to wrap all request return types with HttpResponse.
original_http_response: false
# Optional. Set regex replacement rules for the names of the generated classes/enums.
# All rules are applied in order.
replacement_rules:
Expand Down
13 changes: 7 additions & 6 deletions swagger_parser/lib/src/config/yaml_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class YamlConfig {
this.enumsToJson,
this.enumsPrefix,
this.markFilesAsGenerated,
this.withHttpResponse,
this.originalHttpResponse,
this.replacementRules = const [],
});

Expand Down Expand Up @@ -210,10 +210,10 @@ final class YamlConfig {
);
}

final withHttpResponse = yamlConfig['with_http_response'];
if (withHttpResponse is! bool?) {
final originalHttpResponse = yamlConfig['original_http_response'];
if (originalHttpResponse is! bool?) {
throw const ConfigException(
"Config parameter 'with_http_response' must be bool.",
"Config parameter 'original_http_response' must be bool.",
);
}

Expand Down Expand Up @@ -262,7 +262,8 @@ final class YamlConfig {
putClientsInFolder: putClientsInFolder ?? rootConfig?.putClientsInFolder,
squashClients: squashClients ?? rootConfig?.squashClients,
pathMethodName: pathMethodName ?? rootConfig?.pathMethodName,
withHttpResponse: withHttpResponse ?? rootConfig?.withHttpResponse,
originalHttpResponse:
originalHttpResponse ?? rootConfig?.originalHttpResponse,
enumsToJson: enumsToJson ?? rootConfig?.enumsToJson,
enumsPrefix: enumsPrefix ?? rootConfig?.enumsPrefix,
markFilesAsGenerated:
Expand Down Expand Up @@ -361,6 +362,6 @@ final class YamlConfig {
final bool? enumsToJson;
final bool? enumsPrefix;
final bool? markFilesAsGenerated;
final bool? withHttpResponse;
final bool? originalHttpResponse;
final List<ReplacementRule> replacementRules;
}
12 changes: 6 additions & 6 deletions swagger_parser/lib/src/generator/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class Generator {
String? rootClientName,
bool? putClientsInFolder,
bool? squashClients,
bool? withHttpResponse,
bool? originalHttpResponse,
bool? pathMethodName,
bool? putInFolder,
bool? enumsToJson,
Expand All @@ -62,7 +62,7 @@ final class Generator {
_clientPostfix = clientPostfix ?? 'Client',
_putClientsInFolder = putClientsInFolder ?? false,
_squashClients = squashClients ?? false,
_withHttpResponse = withHttpResponse ?? false,
_originalHttpResponse = originalHttpResponse ?? false,
_pathMethodName = pathMethodName ?? false,
_putInFolder = putInFolder ?? false,
_enumsToJson = enumsToJson ?? false,
Expand All @@ -86,7 +86,7 @@ final class Generator {
clientPostfix: yamlConfig.clientPostfix,
putClientsInFolder: yamlConfig.putClientsInFolder,
squashClients: yamlConfig.squashClients,
withHttpResponse: yamlConfig.withHttpResponse,
originalHttpResponse: yamlConfig.originalHttpResponse,
pathMethodName: yamlConfig.pathMethodName,
putInFolder: yamlConfig.putInFolder,
enumsToJson: yamlConfig.enumsToJson,
Expand Down Expand Up @@ -141,8 +141,8 @@ final class Generator {
/// Squash all clients in one client.
final bool _squashClients;

/// Generate request methods with http response.
final bool _withHttpResponse;
/// Generate request methods with HttpResponse<Entity>
final bool _originalHttpResponse;

/// If true, use the endpoint path for the method name, if false, use operationId
final bool _pathMethodName;
Expand Down Expand Up @@ -263,7 +263,7 @@ final class Generator {
name: _name,
squashClients: _squashClients,
replacementRules: _replacementRules,
withHttpResponse: _withHttpResponse,
originalHttpResponse: _originalHttpResponse,
);
_openApiInfo = parser.parseOpenApiInfo();
_restClients = parser.parseRestClients();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class UniversalRequest {
this.isMultiPart = false,
this.isFormUrlEncoded = false,
this.isDeprecated = false,
this.isWithHttpResponse = false,
this.isOriginalHttpResponse = false,
});

/// Request name
Expand Down Expand Up @@ -46,8 +46,8 @@ final class UniversalRequest {
/// Value indicating whether this request is deprecated
final bool isDeprecated;

/// Wrap request return type with HttpResponse.
final bool isWithHttpResponse;
/// Wrap request return type with HttpResponse
final bool isOriginalHttpResponse;

@override
bool operator ==(Object other) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ String _toClientRequest(UniversalRequest request) {
'''
${descriptionComment(request.description, tabForFirstLine: false, tab: ' ', end: ' ')}${request.isDeprecated ? "@Deprecated('This method is marked as deprecated')\n " : ''}${request.isMultiPart ? '@MultiPart()\n ' : ''}${request.isFormUrlEncoded ? '@FormUrlEncoded()\n ' : ''}@${request.requestType.name.toUpperCase()}('${request.route}')
Future<${request.isWithHttpResponse ? 'HttpResponse<$responseType>' : responseType}> ${request.name}(''',
Future<${request.isOriginalHttpResponse ? 'HttpResponse<$responseType>' : responseType}> ${request.name}(''',
);
if (request.parameters.isNotEmpty) {
sb.write('{\n');
Expand Down
8 changes: 4 additions & 4 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class OpenApiParser {
bool enumsPrefix = false,
bool pathMethodName = false,
bool squashClients = false,
bool withHttpResponse = false,
bool originalHttpResponse = false,
List<ReplacementRule> replacementRules = const <ReplacementRule>[],
}) : _name = name,
_pathMethodName = pathMethodName,
_enumsPrefix = enumsPrefix,
_squashClients = squashClients,
_withHttpResponse = withHttpResponse,
_originalHttpResponse = originalHttpResponse,
_replacementRules = replacementRules {
_definitionFileContent = isYaml
? (loadYaml(fileContent) as YamlMap).toMap()
Expand Down Expand Up @@ -64,7 +64,7 @@ class OpenApiParser {
final bool _enumsPrefix;
final String? _name;
final bool _squashClients;
final bool _withHttpResponse;
final bool _originalHttpResponse;
final List<ReplacementRule> _replacementRules;
late final Map<String, dynamic> _definitionFileContent;
late final OAS _version;
Expand Down Expand Up @@ -475,7 +475,7 @@ class OpenApiParser {
route: path,
isMultiPart: isMultiPart,
isFormUrlEncoded: isFormUrlEncoded,
isWithHttpResponse: _withHttpResponse,
isOriginalHttpResponse: _originalHttpResponse,
returnType: returnType,
parameters: parameters,
isDeprecated: requestPath[_deprecatedConst].toString().toBool(),
Expand Down
2 changes: 1 addition & 1 deletion swagger_parser/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: swagger_parser
description: Package that generates REST clients and data classes from OpenApi definition file
version: 1.10.2
version: 1.10.3
repository: https://github.com/Carapacik/swagger_parser/tree/main/swagger_parser
homepage: https://omega-r.com
topics:
Expand Down

0 comments on commit 976b765

Please sign in to comment.