Open frederikprijck opened 1 year ago
I can confirm, we have the same issue with v6.4.0
(since v6.1.0
), for polymorphic models it is even worse, as it tries to use instanceOf<ChildModel>
. With version v6.0.0
everything is working for us.
We use the following options:
--additional-properties=withInterfaces=true,stringEnums=true
Thanks for chiming in @Linus-Boehm, to avoid confusion, I want to mention that the issue being reported here is not entirly fixed when pinning to 6.0.0.
The instanceOf part of the issue is, but the FromJSON / ToJSON are not.
Nevertheless, that's good information to know.
I think some related issues are:
Thanks @jackkinsella.
There's definetly one (ts-fetch) related to the instanceof issue, but not the FromJson/ToJson. Regardless, Great to get these connected! Thanks
The other two seems to be unrelated, one is even about golang, which is an entirly different generator. The other is about incorrect import path.
Just mentioning to avoid confusion.
I had both instanceOf and spread types errors and rolling back to 5.4.0 resolved both of them. Obviously, it's not ideal, but if you roll back to 5.4.0 does it solve both issues for you?
Are there any updates with this?
Any updates here?
Getting the same issue. Any updates?
I am also running into this - any updates?
Running into the same issue, any updates or plans to address this?
We ended up adding a post processing layer using handlebars to parse for problematic output and convert it into correct output.
On Thu, Mar 7, 2024 at 10:36 PM Patrick El-Hage @.***> wrote:
Running into the same issue, any updates or plans to address this?
— Reply to this email directly, view it on GitHub https://github.com/OpenAPITools/openapi-generator/issues/14763#issuecomment-1984670074, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABE5JX6IGQI7P2XQVZOBCLYXDTWZAVCNFSM6AAAAAAVB4CO7SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBUGY3TAMBXGQ . You are receiving this because you were mentioned.Message ID: @.***>
Any news???
hey any news on this?
Same issue here. Any updates?
@frederikprijck I think I've created a fix for a similar issue: https://github.com/OpenAPITools/openapi-generator/pull/18154
Can you check if this fixes your issue? It solved mine.
Two temporary solutions:
"SomeType": {
"oneOf": [ {
"$ref": "#/components/schemas/Blah1"
}, {
"$ref": "#/components/schemas/Blah2"
} ],
"type": "object",
"properties": {
"objectType": {
"type": "string"
}
},
"required": [ "objectType" ],
"discriminator": {
"propertyName": "objectType",
//add this, which is the same as oneOf above:
"mapping": {
"Blah1": "#/components/schemas/Blah1",
"Blah2": "#/components/schemas/Blah2"
}
}
},
npx @openapitools/openapi-generator-cli generate -i ./openapi.json -g typescript-axios -o packages/openapi/out -c ./openapiconfig.json --global-property models,supportingFiles
Same issue on 7.7.0.
My solution is to add ts-nocheck
to files with oneOf:
diff --git a/src/api/models/JobPostArgs.ts b/src/api/models/JobPostArgs.ts
--- a/src/api/models/JobPostArgs.ts
+++ b/src/api/models/JobPostArgs.ts
@@ -1,3 +1,4 @@
+// @ts-nocheck
/* tslint:disable */
/* eslint-disable */
/**
patch -p1 < ./api-hotfix.patch
Bug Report Checklist
Description
When using
oneOf
with theTypeScript-Fetch
generator, the models are generated incorrectly in two ways:An example repository can be found at https://github.com/frederikprijck/openapi-typescript-fetch-one-of, which includes a minimal spec file, as well as the generated code.
The generated output can be seen on the reproduction repository on GitHub, but here are the relevant bits:
As you can see:
stringFromJSONTyped
,instanceOfArray
andstringToJSON
do not existArray<string>FromJSONTyped
,instanceOfArray<string>
andArray<string>ToJSON
do not exist but are also not valid.The first issue appears with different types as well, such as number. While the second is a bit of a different issue and not sure it requires a different issue report. Happy to do so if needed.
openapi-generator version
@openapitools/openapi-generator-cli
version 2.5.2 on NPM with6.3.0
in the OpenAPITools.json.OpenAPI declaration file content or url
The entire (minimal) file is available at the reproduction repository on GitHub, but here are the relevant bits:
Generation Details
You can run
npm run generate
after cloning the sample repository, or use:Steps to reproduce
git@github.com:frederikprijck/openapi-typescript-fetch-one-of.git
Or using Docker:
Followed by
cat out/typescript-fetch/models/TestUrl.ts
Related issues/PRs
There are a lot of issues regarding
oneOf
and TypeScript, but couldn't really find much that felt related apart from this one:https://github.com/OpenAPITools/openapi-generator/issues/12510
This looks as if it's exactly the same issue as the first of the issues (so not the generic Array one), but for query parameters instead of schema properties. I also noticed that the issue is closed, has a merged PR linked but I am still seeing the exact same output on the latest master, see my comment on the issue.
Suggest a fix
I don't think I have any idea. I would be happy to help fix this, but will need some pointers.