Open sambolias opened 1 year ago
I'm having a similar issue, but first, your type mapping line seems off:
--type-mappings yyyy-mm-ddThh:MM:ssZ=DateTimeString
You're listing a date format, not a type. I would expect something like Date=DateTimeString
That said, I also can't get the generator to use a type I have defined separately. I'm using Generator 7.0.1 and an OAS 3.0.1 definition with a Product schema defined. I'm trying to get the generator to use the interface I've defined. I have in my Gradle plugin:
configOptions.put("withSeparateModelsAndApi", "true")
configOptions.put("modelPackage", "model")
configOptions.put("apiPackage", "api")
languageSpecificPrimitives.set(["Product"]) // optional
importMappings.put("Product", "../../domain")
typeMappings.put("Product", "Product")
No combination seems to work - the generator is intent on generating it's own model. Setting languageSpecificPrimitives
only makes it generate a ModelProduct
interface so there is no name collision.
It's possible this feature is not supported. From https://openapi-generator.tech/docs/usage#examples:
Most generators allow for types bound to the OpenAPI Specification's types to be remapped to a user's desired types.
Emphasis mine, but when I look at the import mapping sections of other generators like Java, there is a list of types that are mapped, suggesting those specifically can be overridden. Generator docs are consistently formatted it looks like they have forbidden maintainers from providing any additional text to direct users, explain options, etc.
I'd be grateful if someone could just confirm this is not a supported feature for typescript-axios.
@madeupname my type mapping is working as expected. I can't really use the type there, since that is just string. The definition didn't seem to work for that mapping, format was the only thing that worked.
For a temporary workaround on this I am using sed to write my desired import line to the generated code, and adding that command to my generation script so it can be automated. Hopefully this import mapping issue can be fixed, or explained better, so I no longer have to do that.
Has the same issue, Hope resolve.
Bug Report Checklist
Description
Using the typescript-axios generator I am trying to import some custom types in the generated file so I can map to them. I add the option
--import-mappings CustomType=<relativepath to ts file that exports it>
but no import is generated. I can use a type mapping to translate desired types to my custom type. I am just forced to manually import after generation, and that does not work well with pipeline.openapi-generator version
tested with 5.4.0, 7.0.1, and 7.1.0 via docker
OpenAPI declaration file content or url
relevant part of spec
Generation Details
Most details don't seem very important. Everything works except the generated import. I am working on a react project and using npm installed openapi-generator-cli.
Steps to reproduce
I have the custom types file defined with a simple type alias
and without the type mapping the type generated for this field is
string
.the command to try to map and import my types is
As described this generates the api client, it assigns the
DateTimeString
type to myDTO
dateTime
field, but it does not import the file that defines that type.Related issues/PRs
Could not find any.
Suggest a fix
I would think it would add the line
import { DateTimeString } from '<specified import path>'
to the generated file so that the mapped types could use the custom type. If I am mistaken on that then my suggestion is improving the docs. But the description for import-mappingsseems clear enough that I assume this is just not working with the typescript-axios generator.