Steps to reproduce
Description
When client_postfix is set to an empty string in swagger_parser.yaml, the generated root client file produces an incorrect import path with a trailing underscore.
swagger_parser version
1.43.0
Configuration
swagger_parser:
name: my_api
root_client: true
root_client_name: MyApiClient
client_postfix: ''
put_in_folder: false
This causes a compilation error because the actual file is named my_api.dart.
Root cause
In lib/src/generator/templates/dart_root_client_template.dart, line 61 unconditionally adds an underscore between the name and postfix:
"${snakeName}_${postfix.toSnake}.dart"
When postfix is empty, this produces my_api_.dart instead of my_api.dart.
Minimal reproduction
swagger_parser.yaml
swagger_parser:
schema_path: api.yaml
output_directory: lib/generated
name: my_api
language: dart
root_client: true
root_client_name: MyApiClient
client_postfix: ''
put_in_folder: false
Steps:
- Run
dart pub get
- Run
dart run swagger_parser
- Check
lib/generated/my_api_client.dart - import has trailing underscore
Expected results
The generated import should be:
import 'my_api/my_api.dart';
Actual results
The generated import is:
import 'my_api/my_api_.dart';
Your OpenApi snippet
openapi: 3.0.0
info:
title: Test API
version: '1.0'
paths:
/users:
get:
operationId: getUsers
responses:
'200':
description: Success
content:
application/json:
schema:
type: array
items:
type: object
Code sample
Not relevant.
Logs
Suggested fix
Handle empty postfix in the template:
// Current:
"${snakeName}_${postfix.toSnake}.dart"
// Fixed:
"${snakeName}${postfix.isEmpty ? '' : '_${postfix.toSnake}'}.dart"
Dart version and used packages versions
pubspec.yaml
name: swagger_parser_bug_repro
environment:
sdk: ^3.0.0
dependencies:
dio: ^5.0.0
retrofit: ^4.0.0
dev_dependencies:
swagger_parser: ^1.43.0
Steps to reproduce
Description
When
client_postfixis set to an empty string inswagger_parser.yaml, the generated root client file produces an incorrect import path with a trailing underscore.swagger_parser version
1.43.0
Configuration
This causes a compilation error because the actual file is named
my_api.dart.Root cause
In
lib/src/generator/templates/dart_root_client_template.dart, line 61 unconditionally adds an underscore between the name and postfix:"${snakeName}_${postfix.toSnake}.dart"When postfix is empty, this produces
my_api_.dartinstead ofmy_api.dart.Minimal reproduction
swagger_parser.yaml
Steps:
dart pub getdart run swagger_parserlib/generated/my_api_client.dart- import has trailing underscoreExpected results
The generated import should be:
Actual results
The generated import is:
Your OpenApi snippet
Code sample
Not relevant.
Logs
Suggested fix
Handle empty postfix in the template:
Dart version and used packages versions
pubspec.yaml