Bug Report Checklist
Description
--import-mappings in dart-dio only works partially. Model files that reference the mapped type get the correct custom import, but serializers.dart and the barrel file (<pub>.dart) always hardcode the model/ path. The mapped model file itself is also still generated even though it shouldn't be.
I tried --schema-mappings and --model-name-mappings as well, same result.
We're currently working around this with sed + rm after generation, which works but is ugly.
openapi-generator version
7.17.0 (Homebrew), also reproduced on latest master.
OpenAPI declaration file content or url
openapi: "3.1.0"
info:
title: Example
version: "1.0.0"
paths:
/orders:
get:
operationId: getOrders
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/OrderOut"
components:
schemas:
Address:
type: object
required: [street, city]
properties:
street:
type: string
city:
type: string
OrderOut:
type: object
required: [id, shippingAddress]
properties:
id:
type: integer
shippingAddress:
$ref: "#/components/schemas/Address"
Generation Details
openapi-generator generate \
-i spec.yaml \
-g dart-dio \
-o out/ \
--type-mappings "Address=CustomAddress" \
--import-mappings "CustomAddress=package:my_api/src/custom_models/custom_address.dart"
Steps to reproduce
- Save the spec above as
spec.yaml.
- Run the generation command.
- Check the imports in the generated files:
out/lib/src/model/order_out.dart — works, picks up the custom path:
import 'package:my_api/src/custom_models/custom_address.dart';
out/lib/src/serializers.dart — ignores the mapping, uses the default model/ path:
import 'package:my_api/src/model/custom_address.dart';
out/lib/my_api.dart (barrel) — same problem:
export 'package:my_api/src/model/custom_address.dart';
out/lib/src/model/custom_address.dart is also generated even though it should be skipped for import-mapped types.
Related issues/PRs
Suggest a fix
I traced this to two mustache templates that loop over all models and always emit model/<classFilename>.dart, without checking import mappings:
serializers.mustache:
{{#models}}{{#model}}import 'package:{{pubName}}/{{sourceFolder}}/{{modelPackage}}/{{classFilename}}.dart';
{{/model}}{{/models}}
lib.mustache:
{{#models}}{{#model}}export 'package:{{pubName}}/{{sourceFolder}}/{{modelPackage}}/{{classFilename}}.dart';
{{/model}}{{/models}}
These need to skip (or redirect) import-mapped models. The generator should also suppress the model file for these types, similar to how it already skips free-form objects.
Bug Report Checklist
Description
--import-mappingsin dart-dio only works partially. Model files that reference the mapped type get the correct custom import, butserializers.dartand the barrel file (<pub>.dart) always hardcode themodel/path. The mapped model file itself is also still generated even though it shouldn't be.I tried
--schema-mappingsand--model-name-mappingsas well, same result.We're currently working around this with
sed+rmafter generation, which works but is ugly.openapi-generator version
7.17.0 (Homebrew), also reproduced on latest master.
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
spec.yaml.out/lib/src/model/order_out.dart— works, picks up the custom path:out/lib/src/serializers.dart— ignores the mapping, uses the defaultmodel/path:out/lib/my_api.dart(barrel) — same problem:out/lib/src/model/custom_address.dartis also generated even though it should be skipped for import-mapped types.Related issues/PRs
Suggest a fix
I traced this to two mustache templates that loop over all models and always emit
model/<classFilename>.dart, without checking import mappings:serializers.mustache:lib.mustache:These need to skip (or redirect) import-mapped models. The generator should also suppress the model file for these types, similar to how it already skips free-form objects.