crescat-io / saloon-sdk-generator

Generate Saloon SDKs from Postman Collections and OpenAPI Specifications.
MIT License
109 stars 17 forks source link

[Help/debugging] POST headers & body not being generated #9

Open nikspyratos opened 12 months ago

nikspyratos commented 12 months ago

šŸ‘‹ Heyo! Finally got around to working on more of my banking sdk. Thought I'd make an issue for investigation instead of going on socials just for better visibility/tracking.

I'm using the OpenAPI specification files from the bank's API, for example this one. On that page you'll see a download button for the OpenAPI file that I'm using with the generator.

The generator generates all the requests, connectors, etc. correctly. The issues I'm having are that some headers and POST bodies are not being populated in the requests. I'm going to assume this is due to the OpenAPI spec file being quirky and having more complex specs maybe?

Let's take the Post Category request for example. The generated CreateCategory request class is bare:

Screenshot 2023-09-18 at 22 16 23

Meanwhile, the Swagger editor seems to pick the header & body up correctly:

Screenshot 2023-09-18 at 22 17 29

All requests in this api also require an intermediaryId header value, but this is not picked up in any of the generation.


Command-wise, what I'm running is:

sdkgenerator generate:sdk ~/Downloads/CIBForIntermediaries.json --type=openapi --namespace=InvestecSdkPhp

Any ideas? Is the OpenAPI spec file being weird, or am I doing something wrong?

HelgeSverre commented 12 months ago

Ahh, this package currently don't support header values.

Want to try to tackle this in a PR, what specifically has to be done is to add a "headers" array to the Endpoint class similarly to how we do it for these:

// ...
public array $queryParameters = [],
public array $pathParameters = [],
public array $bodyParameters = [],
// ...

Then in the OpenAPI parser it has to be parsed out from the Operation (i'm assuming), here:

https://github.com/crescat-io/saloon-sdk-generator/blob/master/src/Parsers/OpenApiParser.php#L75-L78

Then add code generation in the RequestGenerator, around here-ish:

https://github.com/crescat-io/saloon-sdk-generator/blob/master/src/Generators/RequestGenerator.php#L87

I think this one might be fairly simple to implement (famous last words nervous laughter)

nikspyratos commented 12 months ago

Oooh noice, will have a go at it for the headers.

Any idea for the body?

tuarrep commented 6 months ago

I think the issue about the body is related to #21