Problem/Motivation
Json api by default uses the prefix /jsonapi
. That was hard coded into the OpenAPI implementation of the JsonAPI specs. The JsonApi Extras module allows the user to change the api prefix. This results in the base path in the OpenAPI spec remaining /jsonapi
and for all urls to be prefixed with the customized prefix.
Proposed resolution
Add support of the the jsonapi_extras module, by refactoring how the prefix is determined. We should calculate the api prefix in getBasePath()
and then strip that value from all the jsonapi routes.
API changes
This makes a change the to the OpenApiGeneratorBase
class in order to have complete dependency injection and not use \Drupal in the class definition. This is an acceptable change to make as the project is still alpha, and it follows coding standards. The patch resolves all instances of the service instantiation.
Original report by mpdonadio
I am seeing two problems with the Server URLs for the endpoints listed in the `admin/api` path:
In this case
http://kb.example.com/jsonapi/api/files
should be
https://kb.example.com/api/files
1. This particular server is HTTPS, but the sample path us HTTP
2. 'jsonapi' is being added to the path.
I'm assuming this is a problem in `OpenApiDocs::generateDocsFromQuery()`, but didn't see exactly what was wrong.
Comment | File | Size | Author |
---|---|---|---|
#14 | 2897665-14-wrong-server-urls.patch | 11.41 KB | richgerdes |
#6 | Screen Shot 2017-09-25 at 4.10.41 PM.png | 20.77 KB | mpdonadio |
#5 | 2897665-5.patch | 1.07 KB | dawehner |
#4 | Screen Shot 2017-09-15 at 8.20.32 AM.png | 20.82 KB | mpdonadio |
#3 | Screen Shot 2017-09-15 at 00.35.15.jpg | 54.06 KB | dawehner |
Comments
Comment #2
mpdonadioThis was discovered in https://github.com/contentacms/contenta_jsonapi/issues/160
Comment #3
dawehner@mpdonadio I cannot longer reproduce this issue ...
Comment #4
mpdonadioOpen the dropdown. On my install (which is latest):
This site is HTTPS, and it is prepending the /jsonapi
Comment #5
dawehnerOh I see, sorry @mpdonadio. Thank you I was able to reproduce it. Here should be a fix for that.
Comment #6
mpdonadioPath is fixed, but didn't pick up URL protocol:
Comment #7
dawehnerNice observation ...
Comment #8
mpdonadioLGTM.
Sorry I couldn't help with this. Need to get local certs going on my dev machine.
Comment #9
szeidler CreditAttribution: szeidler at Ramsalt Lab commentedPatch #7 is working fine for me, BUT I found another nitpick. The server url is not including a port, when the API is served using a non default port.
The attached patch should fix this, too.
Comment #10
richgerdesI have improved the patch in #9 to use best practices and to generate correct openapi standards. Removing the
basePath
should not be done, and the altered prefix (the result of using JsonApi Extras) should be set there and then stripped from all routes when creating the specifications.Additionally, I merged the changes for handling the protocol and including the port number in the specifications, from #9 to ensure that we best support the variance in platforms as we can and removed the use of
\Drupal
in these files, replacing it with relevant dependency injection, to match Drupal coding standards.Comment #11
richgerdesFixed variable typo.
Comment #13
tedbowThanks everyone for the work here!
After #2936116: Test fail against current core verison. the tests here still fail. Would it make sense to solve #2930810: Make tests more resilient to changes in Drupal core first?
Comment #14
richgerdesTests have been reworked to pass for both 8.4 and 8.5. Re rolled the patch around the latest dev version.
Comment #16
richgerdes