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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpdonadio created an issue. See original summary.

mpdonadio’s picture

dawehner’s picture

Issue summary: View changes
FileSize
54.06 KB

@mpdonadio I cannot longer reproduce this issue ...

mpdonadio’s picture

Open the dropdown. On my install (which is latest):

This site is HTTPS, and it is prepending the /jsonapi

dawehner’s picture

Status: Active » Needs review
FileSize
1.07 KB

Oh I see, sorry @mpdonadio. Thank you I was able to reproduce it. Here should be a fix for that.

mpdonadio’s picture

Status: Needs review » Needs work
FileSize
20.77 KB

Path is fixed, but didn't pick up URL protocol:

dawehner’s picture

Status: Needs work » Needs review
FileSize
1.7 KB
646 bytes

Nice observation ...

mpdonadio’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
20.8 KB

LGTM.

Sorry I couldn't help with this. Need to get local certs going on my dev machine.

szeidler’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.7 KB
702 bytes

Patch #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.

richgerdes’s picture

I 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.

richgerdes’s picture

Status: Needs review » Needs work

The last submitted patch, 11: 2897665-11-wrong-server-urls.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tedbow’s picture

Thanks 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?

richgerdes’s picture

Status: Needs work » Needs review
FileSize
11.41 KB

Tests have been reworked to pass for both 8.4 and 8.5. Re rolled the patch around the latest dev version.

  • richgerdes authored e90b7ff on 8.x-1.x
    Issue #2897665 by richgerdes, dawehner, szeidler, mpdonadio: Wrong...
richgerdes’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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