Skip to content
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

[BUG][typescript-*][possibly other languages] Missing fields when using allOf composition #16150

Open
Digirik opened this issue Jul 21, 2023 · 16 comments

Comments

@Digirik
Copy link
Contributor

Digirik commented Jul 21, 2023

Description

When working on an enhancement of the typescript-axios generation I've noticed fields missing in the generated classes.
This PR changed the way inline schemas are handled. This was done among other things in order to remove dangling/useless *allOf classes that existed in e.g. java. During this commit changes to the typescript examples have been comittet that removed the *allOf classes withouth regard of them now missing fields. This can for e.g. be seen when comparing the generated flat-stock-pick-order-dto.ts with the corresponding spec file.

I've tried using --inline-schema-name-defaults REFACTOR_ALLOF_INLINE_SCHEMAS=true with the locally build jar of the current master but couldn't get that to work. I'll include my command line arguments used, I probably did something wrong.

This also seems to be a problem for the atleast the typescript-rxjs/allOf-composition example aswell, where SuperBoy, SuperBaby & Superman are missing properties now.

openapi-generator version

Current master

OpenAPI declaration file content or url

Spec File

Command line used for generation

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g typescript-axios -i modules/openapi-generator/src/test/resources/3_0/typescript-axios/with-separate-models-and-api-inheritance.yaml -o samples/client/others/typescript-axios/with-separate-models-and-api-inheritance --additional-properties=withSeparateModelsAndApi=true --additional-properties=apiPackage=api --additional-properties=modelPackage=model --additional-properties=legacyDiscriminatorBehavior=false --inline-schema-name-defaults REFACTOR_ALLOF_INLINE_SCHEMAS=true

Steps to reproduce
  1. Check out the current master of the openapi-generator project
  2. Build the project
  3. Either run previously mentioned command line arguments for genrator or generate the mentioned example using ./bin/generate-samples.sh ./bin/configs/typescript-axios-with-separate-models-and-api-inheritance.yaml
  4. Compare the generated files and the spec to see that fields are missing in the generated files.
Related issues/PRs

Related Pull Requests: #15682

Suggest a fix/enhancement

If --inline-schema-name-defaults REFACTOR_ALLOF_INLINE_SCHEMAS=true works (which again maybe i was just too dumb to get to work) and fixes this issue it should probably be enabled by default for the typescript generators the same way it is for the csharp client generators as mentioned in the PR.
Additionally, tests should be added that check if properties are missing in generated types. As *typescript-axios/with-separate-models-and-api-inheritance was added by our team we would be willing to add those in a PR once the issue has been resolved.

@wing328
Copy link
Member

wing328 commented Jul 21, 2023

in the latest master, the option name is inlineSchemaOptions, e.g.

--inline-schema-options ARRAY_ITEM_SUFFIX=_array_item,MAP_ITEM_SUFFIX=_map_item,RESOLVE_INLINE_ENUMS=true

https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#inline-schema-naming

@wing328
Copy link
Member

wing328 commented Jul 21, 2023

I did a test with java client generator:

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/3_0/typescript-axios/with-separate-models-and-api-inheritance.yaml -o /tmp/java23/

but don't see missing properties. Maybe I missed missing.

What properties are missing?

@Digirik
Copy link
Contributor Author

Digirik commented Jul 21, 2023

Hi,
thank you for the quick response. I just ran it with the new option name and this time the tool ran without throwing an error. Yet it didn't fix the problem.

I think it is only broken for functional languages that don't have inheritance, e.g. typescript/js. When using the typescript-axios sample (and using the typescript axios generator) it used to create the following:

export type FlatStockPickOrderDto = AbstractFlatStockPickOrderBaseDto & FlatStockPickOrderDtoAllOf; where AbstractFlatStockPickOrderBaseDto and FlatStockPickOrderDtoAllOf were interfaces that had the corresponding fields. Now the generator generates export type FlatStockPickOrderDto = AbstractFlatStockPickOrderBaseDto; and the properties blockedUntil and blockedById which previously were defined in interface FlatStockPickOrderDtoAllOf are missing.

@wing328
Copy link
Member

wing328 commented Jul 21, 2023

I assume you've tried to use the rule/option REFACTOR_ALLOF_INLINE_SCHEMAS to fallback to previous behaviour but it still didn't work as expected, right?

@Digirik
Copy link
Contributor Author

Digirik commented Jul 21, 2023

I just did that right now, before that i just copied your answer, sorry.
With REFACTOR_ALLOF_INLINE_SCHEMAS it works the way it did before now. Thus my proposition of making it the default behaviour still stands.

@wing328
Copy link
Member

wing328 commented Jul 21, 2023

ok. please use the rule/option for fallback for the time being.

Do you know if all TS generators need this fallback or just typescript-axios needs the inline schemas created automatically?

@wing328
Copy link
Member

wing328 commented Jul 21, 2023

cc @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)

@Digirik
Copy link
Contributor Author

Digirik commented Jul 21, 2023

As far as i can see it atleast also affects the typescript-rxjs generator. I talked abouth this with a corworker and he suspects that probably all functional languages need the fallback.

@Mettbrot
Copy link

Mettbrot commented Jan 18, 2024

This problem still persists with the latest version 7.2.0 in typescript-axios generator.
Using Dto: allOf -BaseDto -properties: ...) generates a model like this
export type Dto = BaseDto;
so the additional properties obviously do not land in the Dto, it only has the properties of BaseDto.

gibiw pushed a commit to qase-tms/specs that referenced this issue Mar 27, 2024
--
Add the following changes:
- support for earlier version of bash (the default bash version is 3.2.57 on MacOS)
- add a workaround for this issue: OpenAPITools/openapi-generator#16150
- update version of openapi-generator to 7.4.0
gibiw pushed a commit to qase-tms/specs that referenced this issue Mar 28, 2024
--
Add the following changes:
- support for earlier version of bash (the default bash version is 3.2.57 on MacOS)
- add a workaround for this issue: OpenAPITools/openapi-generator#16150
- update version of openapi-generator to 7.4.0
@Mettbrot
Copy link

Mettbrot commented Apr 9, 2024

This problem is still present with the latest version 7.4.0

@codeart1st
Copy link

codeart1st commented Apr 9, 2024

This problem is still present with the latest version 7.4.0

Same boat. We still use 6.6.0 because of this issue.

@Mettbrot
Copy link

This issue is still in Version 7.5.0

@macjohnny
Copy link
Member

This issue is still in Version 7.5.0

you are welcome to send a PR to fix this

@bobvandevijver
Copy link

Also hit by this issue, but it can be solved by setting REFACTOR_ALLOF_INLINE_SCHEMAS to true within the inlineSchemaOptions.

@codeart1st
Copy link

Also hit by this issue, but it can be solved by setting REFACTOR_ALLOF_INLINE_SCHEMAS to true within the inlineSchemaOptions.

Good call

@Milananas
Copy link

Milananas commented Jun 28, 2024

Maybe I am missing something, but I have tried setting this option, yet it does not solve the issue for me.
I've setup a reproduction repo here: https://github.com/Milananas/openapi-generator-example

After running generate.sh it produces the following code:

/**
 * @type Test200Response
 * @export
 */
export type Test200Response = ApiResult;

If I set withSeparateModelsAndApi to false it does produce the correct interfaces, but I prefer the separated version for multiple reasons.

I'm running generator version 7.6.0 (latest as of writing).

EDIT: It is working, I made a mistake with the setting I used. My bad, sorry for the confusion!

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

No branches or pull requests

7 participants