OpenAPITools / OpenAPITools/openapi-generator
[BUG] Using dart-dio generator with custom source folder produce invalid import statements on Windows
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When using dart-dio generator with custom source folder on Windows produces invalid import statements
import 'package:openapi/test\source/auth/api_key_auth.dart';
import 'package:openapi/test\source/auth/basic_auth.dart';
import 'package:openapi/test\source/auth/bearer_auth.dart';
import 'package:openapi/test\source/auth/oauth.dart';
import 'package:openapi/test\source/api/auth_endpoint_api.dart';
should be
import 'package:openapi/test/source/auth/api_key_auth.dart';
import 'package:openapi/test/source/auth/basic_auth.dart';
import 'package:openapi/test/source/auth/bearer_auth.dart';
import 'package:openapi/test/source/auth/oauth.dart';
import 'package:openapi/test/source/api/auth_endpoint_api.dart';
so '\' must be replaced by '/'
openapi-generator version
from master branch - 7.2.0-SNAPSHOT
Generation Details
generator: dart-dio
additional config:
sourceFolder: test/source
Steps to reproduce
@Test
public void generateModel_withSourceFolder_expectValidImport() throws Exception {
final var inputSpec = "src/test/resources/3_0/petstore.json";
final var output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();
Assert.assertTrue(new File(inputSpec).exists());
final var configurator = new CodegenConfigurator()
.setGeneratorName("dart-dio")
.addAdditionalProperty(CodegenConstants.SOURCE_FOLDER, "test/source")
.setInputSpec(inputSpec)
.setOutputDir(output.getAbsolutePath());
final var clientOptInput = configurator.toClientOptInput();
new DefaultGenerator().opts(clientOptInput).generate();
var apiFile = new File(output, "/lib/test/source/api.dart");
Assert.assertTrue(apiFile.exists());
Assert.assertTrue(Files.readString(apiFile.toPath()).contains("import 'package:openapi/test/source/serializers.dart';"));
}
Suggest a fix
In all dart templates change property sourceFolder to new property importPrefix that will not contains windows folder separator char
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the dart-dio generator templates mentioned in the issue and the test method generateModel_withSourceFolder_expectValidImport. Run it on Windows or inspect the generated lib/test/source/api.dart output using petstore.json. Done means imports use forward slashes when sourceFolder is test/source and the test assertion passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100