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

Swagger sub types selectors (take 2) #17132

Merged
merged 7 commits into from
Sep 30, 2024
Merged

Conversation

kjac
Copy link
Contributor

@kjac kjac commented Sep 26, 2024

Prerequisites

  • I have added steps to test this contribution in the description below

Description

This is a replacement PR for #17072 ... description is still valid, and originates from the original PR.

This PR introduces a new ISubTypesSelector and ISubTypesHandler implementation to allow overriding how Swagger resolves subtypes of a type based on both the base type and the API document name.

This is required as the current default behaviour is to resolve all type implementations of the base type across all app domain assemblies. This poses a problem if you have (like we do in Umbraco Commerce) a shared base class used by multiple Swagger documents. In this scenario Swagger will throw an exception as it attempts to load the types from all endpoint definitions, not just the for the given API, casing duplicate schema to be generated.

With this PR in the same way ISchemaIdSelector and IOperationIdSelector allow developers to customise the default behaviour of Umbraco whilst generating Swagger Schemas, this new ISubTypesSelector lets you override the sub type resolution process.

In order to maintain backwards compatibility I have set the default ISchemaIdSelector to use the previous functionality if no explicit ISubTypesSelector is defined that can handle the supplied type.

Copy link
Contributor

@mattbrailsford mattbrailsford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me 👍

@kjac kjac merged commit 79ff0e0 into v15/dev Sep 30, 2024
12 of 17 checks passed
@kjac kjac deleted the v15/feature/swagger-sub-types branch September 30, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants