cosullivan / Hypermedia

Hypermedia library for .NET
http://cainosullivan.com/Hypermedia
MIT License
47 stars 12 forks source link

Debugging Difficulties and Documentation Improvements #25

Closed hughesjs closed 2 years ago

hughesjs commented 2 years ago

I'm attempting to use this library but there seems to be a lack of information in the docs that's making this difficult.

For instance, it's not clear to me whether .BackingField() is required or not. It's also not clear when we have to use the various relationship building methods.

The best guess I can make from the quick-start is that .With() is used for each type your API can return and then you use BelongsTo() or HasMany() for any relationships that get returned for that object. However, that then raises the question of what we do when there's a single has relationship (there's no .Has()) or when an object might belong to many other objects.

This has currently led to me having developed quite a complicated model for the ESA's discosWeb API but I'm unable to get it to work. I get this error:

System.ArgumentException: "EqualityContract" property not found on type "DISCOSweb_Sdk.Models.ResponseModels.DiscosObjects.DiscosObject".

System.ArgumentException
"EqualityContract" property not found on type "DISCOSweb_Sdk.Models.ResponseModels.DiscosObjects.DiscosObject".
Check your contract resolver configuration. (Parameter 'field')
   at Hypermedia.Metadata.Runtime.RuntimeFieldAccessor.From[T](String field)
   at Hypermedia.Configuration.FieldBuilder`1..ctor(IContractBuilder`1 builder, RuntimeField field)
   at Hypermedia.Configuration.ContractBuilder`1.Field(String name)
   at Hypermedia.Configuration.ReflectionTypeDiscovery.Discover[TEntity](ContractBuilder`1 builder, TypeInfo type)
   at Hypermedia.Configuration.ReflectionTypeDiscovery.Discover[TEntity](IBuilder parent)
   at Hypermedia.Configuration.Builder.With[TEntity](ITypeDiscovery discovery)
   at Hypermedia.Configuration.BuilderExtensions.With[TEntity](IBuilder builder, String name)
   at DISCOSweb_Sdk.Mapping.JsonApi.DiscosObjects.DiscosObjectContractBuilder.WithDiscosObject(IBuilder builder) in /home/james/repos/DISOSweb-sdk/src/DISCOSweb-Sdk/DISCOSweb-Sdk/Mapping/JsonApi/DiscosObjects/DiscosObjectContractBuilder.cs:line 21
   at DISCOSweb_Sdk.Mapping.JsonApi.DiscosObjectResolver.CreateResolver() in /home/james/repos/DISOSweb-sdk/src/DISCOSweb-Sdk/DISCOSweb-Sdk/Mapping/JsonApi/DiscosObjectResolver.cs:line 22
   at DISCOSweb_Sdk.Tests.Client.ClientTests.CanFetchADiscosObject() in /home/james/repos/DISOSweb-sdk/src/DISCOSweb-Sdk/DISCOSweb-Sdk.Tests/Client/ClientTests.cs:line 20
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 264
--- End of stack trace from previous location ---
   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\ExecutionTimer.cs:line 48
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in C:\Dev\xunit\xunit\src\xunit.core\Sdk\ExceptionAggregator.cs:line 90

But because of the lack of docs, I'm not even sure where to start. If you'd take a look at this PR and point me in the right direction, I'd really appreciate it.

If someone would be so kind as to explain this to me in a bit of detail, I'm more than happy to prepare additional docs and to contribute them with a PR.

hughesjs commented 2 years ago

Thanks @cosullivan for answering my SO question related to many-many relationships which helps somewhat with this but I would still appreciate some further guidance please. Then I'll be more than happy to contribute to the docs.

hughesjs commented 2 years ago

So I think my issue isn't actually to do with what I thought it was, so I'm closing this and opening a new issue for the actual issue.