Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ConfigSyncApiSwaggerGenOptions overrides Umbraco behavior #629

Closed
senneclaeskens opened this issue Apr 19, 2024 · 4 comments
Closed

Comments

@senneclaeskens
Copy link

senneclaeskens commented Apr 19, 2024

Describe the bug
https://github.com/KevinJump/uSync/blob/v14/dev/uSync.Backoffice.Management.Api/Configuration/ConfigSyncApiSwaggerGenOptions.cs#L21C9-L21C88

options.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["action"]}");

This code overrides the default Umbraco implementation

https://github.com/umbraco/Umbraco-CMS/blob/v14/dev/src/Umbraco.Cms.Api.Common/Configuration/ConfigureUmbracoSwaggerGenOptions.cs#L46

swaggerGenOptions.CustomOperationIds(description => _operationIdSelector.OperationId(description));

To Reproduce
Upon installing the usync nuget, the umbraco behavior is overwritten because of the double CustomOperationIds.

Expected behavior
Implementation of OperationIdSelector, which would have them work both: https://docs.umbraco.com/umbraco-cms/reference/api-versioning-and-openapi#adding-custom-schema-ids

Upon checking, it might be better to use IOperationIdHandler, since otherwise, any custom logic might be skipped.

Additional context
Umbraco + usync 14.0.0-rc1

@KevinJump
Copy link
Owner

Thanks for this, i didn't spot that.

but i am concerned the umbraco solution isn't sustainable for multiple packages 🤔

If i implement a Custom OperationIdSelector that calls umbraco base selector. but then another package comes along and implements a custom operations selector that overrides the base, doesn't all my config get lost because my class is no longer registered?) .

It might just be that i only need to impliment something on my site i get the swagger from, because once the client is built it doesn't matter ?

I will raise this with someone in the core see what they say.

@senneclaeskens
Copy link
Author

You are totally right about that, that's why I made an edit, suggesting IOperationIdHandler.

Basically, you can create a handler like this:

    public bool CanHandle(ApiDescription apiDescription)
    {
        if (apiDescription.ActionDescriptor is not ControllerActionDescriptor controllerActionDescriptor)
        {
            return false;
        }

        return CanHandle(apiDescription, controllerActionDescriptor);
    }
    
    public bool CanHandle(ApiDescription apiDescription, ControllerActionDescriptor controllerActionDescriptor)
        => controllerActionDescriptor.ControllerTypeInfo.Namespace?.StartsWith("uSync") is true;
    
    public string Handle(ApiDescription apiDescription)
    {
        // custom logic which returns the operationId
    }

Info taken from umbraco/Umbraco-CMS#16062

@KevinJump
Copy link
Owner

thanks, I've added that - I think there is a RC2 of Umbraco on the horizon, so will merge a few things and hopefully release it all for that.

KevinJump added a commit that referenced this issue Apr 19, 2024
* From v13: Fixes (#590) - missing null check

* From v13: Fixes #604. don't prepend path with ~ (for no random reason!)

* From v13: Fix #224 - Observe root folder value in rootfolder array if set (and root folders array is not set). (#606)

* From v13: Throw for duplicates ( Jumoo/uSync.Complete.Issues#225 )

* Add serializers and handlers for webhooks. (#613)

* Add serializers and handlers for webhooks.

* Webhook Comments

* From v13: Add serializers and handlers for webhooks. (#613)

* From v13: Fix #609 Default language importing. (#614)

* From v13: Use folders provided in options over config (#610)

* From v13: fix #605 - check delete by serializing item one last time. (#616)

* From v13: Fix - delete entries show up twice in report and actions. (#617)

* From v13: #612 - couple of extra checks so we never try to create an XCData section with a null value. (#618)

* Fix for #619. don't report property deletes as changes when they have… (#621)

* Fix for #619. don't report property deletes as changes when they have already happened

* Add fix for #620 - don't recreate items that are deleted.

* v13 - > v14 null checks.

* From v13: DataType merging Empty items alway win

* update build script

* tidy up logging.

* consistant JSON options

* Add Extra saves for content (not sure we need them! - might be a rc1 issue)

* Add Ability to change the editor alias on import

* Post RC1 - migration fixes.

* chore: project things

* fixes #629 have a custom Operations handler just for uSync swagger endpoint.
@KevinJump
Copy link
Owner

we did this, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants