viagogo / HalKit

A lightweight .NET library for creating and consuming HAL hypermedia APIs
MIT License
16 stars 8 forks source link

Incompatibility with Swashbuckle.AspNetCore #27

Closed laszlozold closed 2 years ago

laszlozold commented 2 years ago

I started using HalKit in one of my projects along with Swashbuckle.AspNetCore. Unfortunately Swashbuckle.AspNetCore throws an exception when it tries to construct the JSON schema of a given type and HalKit's ResourceContractResolver is being used. The problem occurs because HalKit sets the DeclaredType property of the JsonProperties it creates for the reserved Hal properties (_links, _embedded) however, does not set the UnderlyingName property because obviously, they have no underlying properties. They are not really declared in the resource type causing trouble to Swashbuckle:

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.Newtonsoft/SchemaGenerator/JsonPropertyExtensions.cs#L12

I assume it's a bug in HalKit as these JsonProperties (the underlying properties at least) are not declared in the resource class, so these "reserved" JSON properties should not have a DeclaredType set.

What do you think about it?