-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
OpenAPI: Hide inaccessible links #1518
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## openapi #1518 +/- ##
===========================================
+ Coverage 90.77% 90.85% +0.07%
===========================================
Files 394 396 +2
Lines 12993 13115 +122
Branches 2058 2078 +20
===========================================
+ Hits 11795 11916 +121
+ Misses 782 781 -1
- Partials 416 418 +2 ☔ View full report in Codecov by Sentry. |
@bkoelman Will this feature be released soon? |
This is available for use from the GitHub NuGet feed, see https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/README.md#trying-out-the-latest-build. The overall progress of adding OpenAPI support is tracked at #1046. It'll take a while to complete that, after which it'll be published to NuGet. To speed that up, you can help if you want by working on open issues. |
This PR updates OpenAPI to take into account whether JSON:API links are available.
My first take on implementing this was to declare nearly all links as required in the component schemas. Then at runtime remove the links we know can't be returned, which can be determined from the cascading links configuration.
However, because links can be configured per resource type, this requires expansion of the link schema types. For example,
linksInResourceData
becomeslinksInTodoItemData
,linksInPersonData
,linksInTagData
, etc. This introduces many new schemas for questionable gain, as using OpenAPI typically makes users care less about links. But it gets worse. Relationship links can be overruled per relationship within a resource type. This means we need to expand link schema types for them as well. But the relationship links are defined on the relationship left-type, whereas the currently produced schemas for relationships reflect their right-type. For example,todoItems
contains relationshipsowner
andassignee
, both of typepeople
. Let's assume both relationships are required. In that case, a single schematoOnePersonInResponse
is produced for both relationships' right-side types, because they have the same data structure. Now taking expansion for relationship links into account, we'd need to generate separate schemas:ownerToOnePersonInResponse
andassigneeToOnePersonInResponse
. As a result, consumers can't write the following code anymore, because different schemas would be produced:For the reasons mentioned above, I chose not to implement schema expansion at all. The next best thing is to determine which links can be eliminated by taking a union of the configured link types. So if all links are turned off, but
todoItems
turns on the top-levelself
link, then all resource types get only the top-levelself
link. Likewise, if theowner
relationship turns on therelated
relationship-level link, while theassignee
relationship turns on theself
link, then all relationship schemas get both links. If no link overrules are used and links are turned off in options, then no links appear in the component schemas.As a result, all links must be declared as non-required in the component schemas, because now the schemas may contain links that won't actually be returned at runtime (and we haven't eliminated them from the schema).
Closes #1062.
QUALITY CHECKLIST