Skip to content

Fix typescript-fetch broken files when mixing basic types and refs in oneOf #21057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 14, 2025

Conversation

GregoryMerlet
Copy link
Contributor

Closes #19909

Based on #20193 and improved to support any basic type, not just strings.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

TypeScript committee members: @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)

@macjohnny
Copy link
Member

thanks for your contribution!

@macjohnny macjohnny merged commit a94b8f9 into OpenAPITools:master Apr 14, 2025
15 checks passed
@wing328 wing328 added this to the 7.13.0 milestone Apr 27, 2025
@b0g3r
Copy link

b0g3r commented Apr 27, 2025

Hi folks! Our build with 7.13.0 starts to fail, I suspect that because of changes from this pull request. Basically, imports are absent for some reason in model files, e.g.

/* tslint:disable */
/* eslint-disable */
/**
 * ...
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


/**
 * @type Access
 * 
 * @export
 */
export type Access = { accessType: 'manual' } & SoftwareAccess ...

Note that it has no import even so it uses SoftwareAccess and json later one. Could it be related to these changes and how to troubleshoot the issue without sharing the openapi file? 👀

A few uncommon things that I was able to find about our API ref is that we're prefixing our OneOf with _, for example:

"access": {
    "oneOf": [
        {
        "$ref": "#/components/schemas/_SoftwareAccess"
        },
        {
        "$ref": "#/components/schemas/_AnotherModel"
        }
    ],
    "title": "Access",
    ...

And that we're using discriminators for these oneofs

@macjohnny
Copy link
Member

@GregoryMerlet @b0g3r do you want to fix this?

@GregoryMerlet
Copy link
Contributor Author

I can try to fix it if there's a way to reproduce it. @b0g3r would you be able to create an openapi file with the minimal informations to reproduce your problem please ?

@b0g3r
Copy link

b0g3r commented Apr 29, 2025

Was able to craft a reproducible example: https://gist.github.com/b0g3r/4610d89d3a06e99792a9f6f7747d5504, the issue with a oneof field with discriminator

Another one was spotted as well, in "ToJSONTyped" function return json is used instead of return value for discriminator fields

@ruoat
Copy link

ruoat commented May 19, 2025

We stubled upon the same issue. Is there any news on fixing this in the future or do we need to use the older generator?

@etremblay
Copy link
Contributor

etremblay commented May 22, 2025

We just updated from 7.7 to 7.13 and we have the same problem.

If I revert this commit, the imports are fixed but there is still a bug in ToJSONTyped

I think it's caused by #20983

The return json should be return value in the default case.

etremblay added a commit to kronostechnologies/openapi-generator that referenced this pull request May 22, 2025
@ruoat
Copy link

ruoat commented Jun 9, 2025

@b0g3r should you create a new issue about the problem? It seems that nobody is going to address the problem in this Merged pull request. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] [typescript-fetch] Broken files when mixing basic types and refs in oneOf
6 participants