highsidelabs / saloon-sdk-generator

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

Aggressive caching in OpenApi Normalizer #4

Closed michalbundyra closed 4 months ago

michalbundyra commented 5 months ago

This caching is too aggressive:

https://github.com/highsidelabs/saloon-sdk-generator/blob/eacbcf7f53e9030bbcd5a2a92c0dd60ad7b2f51b/src/Normalizers/OpenApiNormalizer.php#L127-L129

as we treat properties as schemas, so if the items property is used anywhere before, then the second usage will get the cached value with the wrong schema reference:

See: https://github.com/jlevers/selling-partner-api/issues/726

The quick (and nasty) solution might be not to cache any "schema" starting with lowercase letter, something like:

$firstLetter = substr($name ?? '', 0, 1);

// We occasionally want schemas to be anonymous, like an inline schema in an allOf.
// There's no good way to name them, and we can parse them without a name
if ($name && $firstLetter === strtoupper($firstLetter)) {
    $this->normalizedSchemas[$name] = $schema;
}

but I guess there is a better option there. It was just my quick digging around what's wrong when trying to migrate to v6.

jlevers commented 4 months ago

Thanks for point this out – fixed in v2.1.0.