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

Make the GetKey protected & virtual to allow overriding it #1353

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

mikoskinen
Copy link
Contributor

@mikoskinen mikoskinen commented Apr 7, 2021

Hi,

In this change the JsonSchemaResolver's GetKey is made protected & virtual in order to use additional information than just the FullName as the mapping key. In our case we would like to use Assembly version in addition to fullname.

In our scenario controllers are loaded runtime and there might be two classes with the exact same FullName coming from two different assemblies and we need to generate schemas for both of them as the types may be different (different properties etc.).

@RicoSuter
Copy link
Owner

Shouldnt we fix that directly instead of externally? ie. change the current impl to fix your issue?

@mikoskinen
Copy link
Contributor Author

Thanks for the comment! The idea was to break as little as possible :) This way the developer can override the JsonSchemaResolver (or OpenApiSchemaResolver) and provide their own implementation.

Using the Type.Assembly and its version in addition to Type.FullName isn't always possible as the assemblies can be dynamic. For example in one of our cases we are generating the assemblies on the fly using Roslyn and the assembly is memory only and missing the version details. In this case the current implementation works fine as we must rely on the Type.FullName.

In another case it may be that we use the Type's FullName to map it to some other non-type related data, for example to Nuget package. In this scenario the application may have loaded two versions of the same Nuget-package as plugins (using Plugin Framework) and even though both packages have different versions, the assemblies inside them may have the same 1.0.0 version. We need some application specific mechanism for deciding if we expect the schema's to be the same or not.

@RicoSuter RicoSuter merged commit 3a1a9b7 into RicoSuter:master Apr 8, 2021
@RicoSuter
Copy link
Owner

Renamed to GetTypeKey

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

Successfully merging this pull request may close these issues.

2 participants