scramble icon indicating copy to clipboard operation
scramble copied to clipboard

fix: issue with extensions being overwritten by built-in extensions

Open horlarme opened this issue 1 year ago • 4 comments

This is a fix for this issue/question https://github.com/dedoc/scramble/discussions/442

The order of the types of extensions caused the issue. All the other extension types are merged by putting the custom ones at the end of the array. Still, in the case of TypeTransformer it was at the beginning which caused custom extensions to be overridden by the built-in extensions.

horlarme avatar Aug 23 '24 20:08 horlarme

Thanks for so much for the PR!

We have the same issue and it would be great if this would be released. There were already two PRs (#361 and #347) that did the same, but they were closed. Let's hope it works out this time 🙏

korridor avatar Aug 29 '24 15:08 korridor

I think the real issue we're having, is that we can't choose exactly when our extensions are being used. I'm thinking a priority property, a before/after hook, or some resolution logic to replace one of the default extensions would be ideal. In my case, I still want the EnumToSchema, JsonResourceTypeToSchema, ModelToSchema, and EloquentCollectionToSchema to be called before my PaginatedResourceCollectionTypeToSchema.

The simplest solution would be for the package classes to have public int $priority = 10; // increments of 10, allowing us to put 9 (or more if same priority won't break functionality) extensions in between each of the defaults. Custom extensions would have a default priority of 1, so the existing behavior is unchanged.

If no one else implements this, I'll start working on it this weekend.

@romalytvynenko Would this be an acceptable solution?

hn-seoai avatar Sep 04 '24 05:09 hn-seoai

@hn-seoai this is indeed something to be thought off. Please wait before working on it, as I'm still thinking about the solution

romalytvynenko avatar Sep 04 '24 06:09 romalytvynenko

@korridor @hn-seoai @horlarme Just to be clear, I agree this is the real issue and needs to be addressed. Thanks for raising the issue

romalytvynenko avatar Sep 04 '24 06:09 romalytvynenko

Closing this PR, as the issue is fixed by this one: https://github.com/dedoc/scramble/pull/570

Thanks!

romalytvynenko avatar Oct 08 '24 19:10 romalytvynenko