oxidecomputer / progenitor

An OpenAPI client generator
428 stars 55 forks source link

progenitor fails processing the commercetools OpenAPI spec #661

Open mseele opened 7 months ago

mseele commented 7 months ago

I want to generate a commercetools OpenAPI client and tried to process the OpenAPI spec from commercetools:

https://github.com/commercetools/commercetools-api-reference/blob/main/oas/api/openapi.yaml

Unfortunalty then generation failed pretty quickly:

cargo progenitor -i openapi.yaml -o ct_prog -n ct_prog -v 0.0.1

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
[1]    11024 abort      cargo progenitor -i openapi.yaml -o ct_prog -n ct_prog -v 0.0.1
ahl commented 7 months ago

Do you know what version of cargo progenitor you have installed? cargo install-update --list cargo-progenitor

The good news is that in the main branch, we're not blowing the stack. The bad news is that we're running into this error: UnexpectedFormat("unexpected content type: application/graphql"). It looks like the right thing to do is just serialize it as though that's application/json:

https://github.com/commercetools/commercetools-sdk-java-v2/blob/d9216d2dac170a118a26c2eaa04727ba4cc656a3/commercetools/commercetools-sdk-java-api/src/main/java-generated/com/commercetools/api/client/ByProjectKeyGraphqlPost.java#L67-L69

https://github.com/commercetools/commercetools-sdk-php-v2/blob/04d386636420813425d471bb5ae147c9c571a91b/lib/commercetools-api/src/Client/Resource/ByProjectKeyGraphqlPost.php#L44

If we patch that, we see another unhandled mime type: */*. I think we can make that text/plain.

Then we have an issue of multiple response types:

thread 'main' panicked at progenitor-impl/src/method.rs:1261:9:
assertion failed: response_types.len() <= 1

It looks like like each error actually uses the same type, but with a wrapper to indicate the meaning of the response code (a bit useless, but whatever). That will require a fix for #344.

mseele commented 7 months ago

Thank you for looking into it so fast. I've used github, so the version is the latest commit 15 hours ago.

ahl commented 7 months ago

That's very odd as I think I'm running the same version. What OS are you on? What's your default stack size?

mseele commented 7 months ago

I'm running mac os on a macbook pro m1. I have no idea what the default stack size is. sorry.

ahl commented 6 months ago

Do you have a record of the stack when it overflowed? Thanks

mseele commented 6 months ago

Sorry for answering so late...how to record the stack on macos?

ahl commented 6 months ago

I believe the proximate stack overflow has been addressed. You can cargo uninstall cargo-progenitor and cargo install --git https://github.com/oxidecomputer/progenitor cargo-progenitor. It will, however, still fail on the errors noted above.

For future reference, the way I examine stacks on crashes on macOS is to hit the "report" button when the "your program crashed" dialog pops up. The stack is in the subsequent dialog box.

mseele commented 6 months ago

@ahl Thanks, the stack overflow is gone and it's now failing with the following error (as you mentioned):

cargo progenitor -i openapi.yaml -o ct_prog -n ct_prog -v 0.0.1
gen fail: UnexpectedFormat("unexpected content type: application/graphql")
Error: generation experienced errors