Skip to content
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

Is there support for server variables? #89

Closed
Nitwel opened this issue May 30, 2020 · 6 comments
Closed

Is there support for server variables? #89

Nitwel opened this issue May 30, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@Nitwel
Copy link

Nitwel commented May 30, 2020

My current problem is that my api server is configured like this:

servers:
  - url: 'https://demo.directus.io/{project}'
    variables:
      project:
        default: thumper
        description: The project name

But when I try to make a request like https://demo.directus.io/thumper/auth/authenticate I get the error that the path does not match.

The error:

FAIL tests/activity.test.ts
  GET /auth/authenticate
    × should satisfy OpenAPI spec (498 ms)

  ● GET /auth/authenticate › should satisfy OpenAPI spec

    expect(received).toSatisfyApiSpec() // Matches 'received' to a response defined in your API spec, then validates 'received' against it

    expected received to satisfy a '200' response defined for endpoint 'POST /thumper/auth/authenticate' in your API spec
    received had request path /thumper/auth/authenticate, but your API spec has no matching path

    Paths found in API spec: /activity, /activity/{id}, /activity/comment, /activity/comment/{id}, /items/{collection}, /items/{collection}/{id}, /auth/authenticate, /auth/refresh, /collection_presets, /collection_presets/{id}, /collections, /collections/{id}, /interfaces, /layouts, /modules, /fields, /fields/{collection}, /fields/{collection}/{field}, /folders, /folders/{id}, /mail, /permissions, /permissions/{id}, /permissions/me, /permissions/me/{collection}, /{project}, /server/projects, /server/projects/{project}, /relations, /relations/{id}, /revisions, /revisions/{id}, /roles, /roles/{id}, /scim/v2/Users, /scim/v2/Users/{id}, /scim/v2/Groups, /scim/v2/Groups/{id}, /server/info, /server/ping, /settings, /settings/{id}, /users, /users/{id}, /users/me, /users/invite, /users/invite/{token}, /users/{id}/tracking/page, /users/{id}/revisions, /users/{id}/revisions/{offset}, /utils/hash, /utils/hash/match, /utils/random/string, /utils/utils/2fa_secret, /files, /files/{id}, /files/{id}/revisions, /files/{id}/revisions/{offset}, /auth/password/request, /auth/password/reset, /auth/sso, /auth/sso/{provider}, /assets/{key}

    '/thumper/auth/authenticate' matches no servers

    Servers found in API spec: https://demo.directus.io/{project}

      16 |
      17 |       expect(res.status).toEqual(200);
    > 18 |       expect(res).toSatisfyApiSpec();
         |                   ^
      19 |     });
      20 |   });

      at Object.<anonymous> (tests/activity.test.ts:18:19)
      at step (tests/activity.test.ts:33:23)
      at Object.next (tests/activity.test.ts:14:53)
      at fulfilled (tests/activity.test.ts:5:58)


@rwalle61
Copy link
Collaborator

Hi @Nitwel, thanks for raising this! We don't support server variables at the moment, but it sounds like a valid enhancement, and I'm happy to take an PR for it.

The code for matching responses to OpenAPI paths is here. Whoever fixes this should probably edit getMatchingServerBasePaths() to take account of server variables :)

@rwalle61
Copy link
Collaborator

For reference, the relevant part of the official OpenAPI 3 specification is https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#server-object

@Xotabu4
Copy link
Contributor

Xotabu4 commented Nov 14, 2020

Before i saw this package i created my own, and i added special setting to ignore part of request path in validator, probably same approach can be used?

image

@rwalle61
Copy link
Collaborator

@Xotabu4, I think your suggestion may be a bit different to @Nitwel's issue. OpenAPI 3 has servers and server variables, and Nitwel is asking that we correctly parse these variables if the user defines them in their OpenAPI spec.

I'm not sure how manually configuring our validator to ignore parts of the API spec would accomplish that goal. In any case, I think this package should be as easy to use as possible, so we should try to avoid manual config and arguments unless vital.

What do you think? Let me know if I have misunderstood you

@rwalle61
Copy link
Collaborator

As a general update on this issue, both @JonnySpruce and I have branches with this feature implemented, but we are both too busy at the moment to review our work and get it merged. Anyone who wants us to prioritise this higher, please +1 the issue at the top :)

@rwalle61
Copy link
Collaborator

rwalle61 commented Mar 6, 2021

Published! https://github.com/openapi-library/OpenAPIValidators/releases/tag/v0.13.0

Thanks to everyone for their patience and @JonnySpruce for a lot of the work.

@Nitwel and others who requested this, would you mind confirming the issue is fixed? Please reopen if needed :)

@rwalle61 rwalle61 closed this as completed Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants