crescat-io / saloon-sdk-generator

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

feat: OpenAPI security scheme parsing and connector auth for API keys #14

Closed bobbyshaw closed 8 months ago

bobbyshaw commented 11 months ago

The goal of this change is to support API key as parameters to Connectors and declaring the authentication mechanism. Only API key authentication is supported at this time, e.g.

public function __construct(protected string $authToken) {
    $this->withTokenAuth($authToken);
}

I've added some unit tests for the OpenAPI parser and the ConnectorGenerator classes - just for the changed sections at this time.

I had a decision to make during this what classes to create to capture the security schemes and requirements. I appreciate that you also support parsing Postman Collections which I'm less familiar with. Looking at their specification, they appear less comprehensive and less verbose than OpenAPI specs. I've chosen to align the the OpenAPI format as it's likely easier to convert postman to open API format than the other way around without losing fidelity of information.

bobbyshaw commented 11 months ago

@HelgeSverre apologies to add to the same PR but I've built on this functionality further so that it now copes when the OpenAPI base URL has a variable, e.g. https://api-{region}.example.com.

For my SDK it then generates a connector like so:

    public function __construct(
        protected string $storeHash,
        protected string $authToken,
    ) {
        $this->withTokenAuth($authToken);
    }

    public function resolveBaseUrl(): string
    {
        return "https://api.bigcommerce.com/stores/{$this->storeHash}/v3";
    }
HelgeSverre commented 11 months ago

Very nice, will review this closer later today (or whenever i get time, life etc)

HelgeSverre commented 8 months ago

merged in manually to the dev branch, closing this for now.