OpenAPITools / OpenAPITools/openapi-generator

[BUG] Using dart-dio generator with custom source folder produce invalid import statements on Windows

Open
#17,109 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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
image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.