Problem/Motivation

Sorry for the poor detail here. This patch applies after applying the following patches: https://github.com/contentacms/contenta_jsonapi/blob/8.x-3.x/composer.js...

Problems this fixes:

  1. Some routes were missing (GET individual) because they were getting overridden.
  2. When JSON Schemas are embedded in other schemas, JSON Path references need to be fixed.
  3. The definition for 'data' is not predetermined when building the schema for collections
  4. Exclude some JSON:API routes that are creating intense schema bloat with references.
  5. Include the resourceVersion parameter when appropriate.
  6. Include the include parameter when appropriate.
  7. Add query string parameters description.
  8. Do not rewrite all the schema for collection resources.

Comments

e0ipso created an issue. See original summary.

e0ipso’s picture

Status: Active » Needs review
StatusFileSize
new4.94 KB

Proposed patch.

e0ipso’s picture

Issue summary: View changes
e0ipso’s picture

Issue summary: View changes
StatusFileSize
new2.89 KB
new7.33 KB

Some extra fixes. I updated the IS.

e0ipso’s picture

Issue summary: View changes
StatusFileSize
new11.5 KB
new4.85 KB

Some more extra fixes. I updated the IS again.

e0ipso’s picture

Issue summary: View changes
StatusFileSize
new18.56 KB
new5.55 KB
new421.73 KB

This is the final result after all the iterations. I'll be using this patch in the Contenta CMS. I could also implement this as a plugin in Contenta CMS if you think it's more appropriate, but I thought to contribute back.

Thanks!

e0ipso’s picture

StatusFileSize
new11.62 KB
new1.16 KB

Sorry for the duplicate patch. This is the correct one.

e0ipso’s picture

Title: Miscellaneus fixes for JSON:API » Miscellaneous fixes for JSON:API

Status: Needs review » Needs work

The last submitted patch, 7: 3053264--misc-fixes--7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

richgerdes’s picture

The current patch looks like an improvement, but it appears the patch drops schema for the relationship routes. For example, the /taxonomy_term/bundle/{entity}/parent and /taxonomy_term/bundle/{entity}/relationships/parent routes have been removed are not being generated by the expectations doc. As a result, this patch still needs some work, before we can merge it.

It looks like this is the result of the below change.

-      if (!$route->getDefault(JsonApiRoutes::JSON_API_ROUTE_FLAG_KEY) || $route->getPath() == $jsonapi_base_path) {
+      $is_jsonapi = $route->getDefault(JsonApiRoutes::JSON_API_ROUTE_FLAG_KEY);
+      $is_entry_point = $route->getPath() === $jsonapi_base_path;
+      $is_related = preg_match('/(\.related)$/', $route_name);
+      $is_relationship = preg_match('/(\.relationship\.)((delete)|(get)|(patch)|(post))$/', $route_name);
+      if (!$is_jsonapi || $is_entry_point || $is_related || $is_relationship) {
         continue;
       }

Previous to this patch, the logic only skipped non jsonapi routes, it now skips all routes which aren't root entity level routes. Is there a reason why these routes were removed here? Is there additional logic which is required to build these routes to have them added back into the doc? I am less familiar with how this is supposed to work, and it would be faster if someone else took a stab at fixing it. To generate expectations locally, set const GENERATE_EXPECTATION_FILES = true; in RequestTest . Then run the test library. I'm happy to worry about doing this if the test failures can be reduced to eliminating following formatted lines or to have a new generic route added.

- /taxonomy_term/taxonomy_term_test/{entity}/relationships/parent' => Array (...)

richgerdes’s picture

StatusFileSize
new189.75 KB
new201.37 KB

Forgot to include patch with updated expectations.

Even if the above patch passes, this still not finished pending resolution of the issue noted in #10.

e0ipso’s picture

Those routes were removed for several reasons:

  1. The generated documentation was very hard to read. For the recipes resource there were a dozen links with different schemas. The one you would expect (the one that contains the schema for recipes) was buried in the middle without nothing special to highlight it.
  2. The additional information added by the related routes is redundant. You could find the tags documentation under article->tags but also under the Tags resource.
  3. The relationship routes are also redundant. They are invariant and the same on all cases. They are covered by the spec's documentation & schema as well.

The only missing information that is missing is the fact that there is a route there. I think that is less relevant because it's explained in the documentation and made explicit by the related and relationship links in the responses. Since there is no clear solution to document that without the clutter I'll argue that we should merge this and address that in a follow up issue.

richgerdes’s picture

I think you have a valid point, however that's not OpenAPI's objective. The spec is designed and intended to be able to generate a fully working api client, so knowledge of the sup routes is critical. To put it simply, OpenAPI docs doesm't care about the Json:API spec or documentation what so ever and can't assume the user does either.

So yes, your points are valid for the purposes of ReDoc and Swagger, but are against the objectives of OpenAPI spec.

That still doesn't mean we can't build a ui and mechanisms to filter the redoc/swagger uis to limit the data which is returned and displayed in the UIs, and this is what I would suggest as the correct way to implement this as opposed simply removing them. There isn't a spec that I am aware of to implement this, but we currently already have a format for filtering the results by entity type and bundle.

There are already a few open issues for addressing the concerns which you bring up about extra/redundant data cluttering the UIs

e0ipso’s picture

@richgerdes what is the next step? Should we commit the patch without that part then I can write a patch so I can use it in Contenta CMS?

richgerdes’s picture

I think the next step here is to update the patch with one that add the features that were previously missing, and doesn't remove anything.

I don't think Contenta should probably not be patching OpenAPI to alter its functionality, since if this is highly error prone when OpenAPI makes a new release. I think the best path forward is to implement a system of filters, which can be defined by a given generator, and then exposed on the ReDoc and swagger pages, so the user can filter the results to what's relevant. Content can then use a hook alter or another mechanism to default the filters to the limited view.

OpenAPI already supports the passing of the options url parameter to the generator. Currently the available options are only used to control the entity types which are included in the generated doc. This parameter could be used to implement the same functionality for route types and methods as well. Maybe also filtering by tag could be helpful.

Right now there is no api to determine the available filters, so this would be necessary in order to move forward with building a ui to set the filters in ReDoc and Swagger. I may have time to work on this later this week, but no promises. My only thought this far is to have a "getAvailableOption" function on OpenApiGeneratorBase which then can be extended by JsonApiGenerator , to define the relevant filters. I hadn't thought much what kind of data would be returned here. Possibly Data Definitions or JsonSchema. I'm open to recommendations.

My main question for you is to determine what the desired options/filters would be for the jsonapi routes, so that we can start moving this forward.

Thoughts?

e0ipso’s picture

While I agree with you on the best course of action, since very little of the outlined solution is ready, Contenta will need to be patched until all of the APIs and features are available.

Do you see any other workaround?

richgerdes’s picture

I'm can try and focus on the implementation, if you can give me an idea of what you would be expecting to be able to do with it?

With the current api, the $options variable is already exposed, so you can implement the filter code as is. There just isn't a pretty way to display the filter fields in the redoc/swagger ui at the moment. Though, once the filter logic is added, which could be done in your patch, then there is no reason contenta couldn't then alter the redoc page to specify the options that you are looking for

e0ipso’s picture

Though, once the filter logic is added, which could be done in your patch, then there is no reason contenta couldn't then alter the redoc page to specify the options that you are looking for

Sadly I don't have available cycles to implement this 😔

richgerdes’s picture

Sadly I don't have available cycles to implement this 😔

I know that feeling all too well. No pressure there. Since you understand what's going on with the current patch better then I, if are able to find the time to get this patch to a point where it no longer removes information, I can will commit it and work on adding the described filtering functionality later this week.

e0ipso’s picture

StatusFileSize
new679.25 KB
new1.1 MB

I got convinced about leaving the related and relationship resources in the spec document. However the generated docs were widely inaccurate and with a confusing naming scheme. This patch should address that.

richgerdes’s picture

This patch is massive and looks like it reverts a large number of changes to the current HEAD. This includes changes to link names, routes, and other side effects which I don't believe were intentional or relevant to the module. Can you please verify that the patch applies to the lastest head with only the intended changes?

e0ipso’s picture

Status: Needs work » Needs review
StatusFileSize
new663.9 KB

Merged the changes from 8.x-1.x. Luckily it was mostly my changes so I could fix the merge conflicts. This is the list of commits from the patch in #7:

8ee96b6 (HEAD -> 3053264--misc-fixes) Patch #22
bb7c326 Merge branch '8.x-1.x' into 3053264--misc-fixes
4941fe5 Patch #20
2a88d82 (origin/HEAD, origin/8.x-1.x, 8.x-1.x) Issue #3064552 by richgerdes, edisch: Replace "continue" with "continue 2" for PHP 7.3
f3f99db Issue #3001993 by e0ipso, richgerdes: Improve path method descriptions
4714b4c Issue #3000609 by e0ipso: Documentation for JSON API collections needs minor adjustments
22cae25 Issue #3000458 by e0ipso: Exclude disabled JSON API resources
a6f783b Issue #3053406 by richgerdes: Tests fail against PHP7.2 & D8.7.0
524256b Issue #3053406: Remove jsonapi as a composer dev dependency with core 8.7+.

  • richgerdes committed 3374d88 on 8.x-1.x authored by e0ipso
    Issue #3053264 by e0ipso, richgerdes: Miscellaneous fixes for JSON:API
    
richgerdes’s picture

The patch looks good. I've committed it to dev.

richgerdes’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.