1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/routes
Thomas Heartman 003b0e7a4e
#1391: ensure all tags are valid (#2124)
## What

This PR does two things:

1. Add tests to ensure that all OpenAPI tags are listed in the root-level `tags` property of the spec.
2. Changes the tags for endpoints that use any of the deprecated tags (specifically `admin`).

## Why

When we moved to using the docusaurus OpenAPI doc generator, we made some changes to existing tags. Moving away from having just 'admin', 'client', and one or two more, we now use a more granular system, which makes it easier to find an endpoint by category.

However, there's currently nothing enforcing this and this bit of knowledge hasn't been clearly communicated to anyone. Because of this, we have some endpoints that are currently just grouped under a general 'admin' tag.

This has two drawbacks:

-   In Swagger UI, all these endpoints are grouped together. This means that they break with the expectation that each endpoint has its own category. Further, being lumped together means that the 'admin' group is hard to read.
-   The 'admin' tag is (on purpose) not included in the root-level `tags` property of the generated OpenAPI spec. This means that the OpenAPI docusaurus generator doesn't pick up those endpoints, which means that they're not included in the docs on docs.getunleash.io.

## How

By implementing tests that:

1. Check that the tags included in the spec are a subset of the "approved" tags

2. By checking each path in the OpenAPI spec and making sure that all its tags are listed in the root-level tag list. If this is not the case, the test fails and it logs an error explaining what is wrong to the console. An example of such a message is:

```
The OpenAPI spec contains path-level tags that are not listed in the root-level tags object. The relevant paths, operation ids, and tags are as follows:

POST /api/admin/feedback (operation id: createFeedback) has the following invalid tags: "admin"

PUT /api/admin/feedback/{id} (operation id: updateFeedback) has the following invalid tags: "admin"

For reference, the root-level tags are: "Addons", "Admin UI", "API tokens", "Archive", "Auth", "Client", "Context", "Edge", "Environments", "Events", "Features", "Import/Export", "Metrics", "Operational", "Playground", "Projects", "Public signup tokens", "Strategies", "Tags", "Unstable", "Users"
```

## Commits

* fix: ensure that all root-level tags in the spec are 'approved tags'

* fix: test that all listed path tags exist in the root-level tags

* fix: use "API tokens" tag for PAT endpoints

* fix: add comment explaining why tags test is there

* fix: Update snapshot

* fix: ensure that spec tags are a subset of the approved Tags

* fix: improve error message when tags don't match

* fix: further tweaks in log format
2022-10-06 15:01:12 +00:00
..
admin-api #1391: ensure all tags are valid (#2124) 2022-10-06 15:01:12 +00:00
auth docs: prep to add OpenAPI spec to Unleash docs (#1907) 2022-08-12 11:37:57 +02:00
client-api Personal access tokens backend (#2064) 2022-09-16 10:54:27 +03:00
edge-api Create endpoint that validates tokens for edge (#2039) 2022-09-01 13:26:26 +00:00
proxy-api fix: use correct proxy logger name (#2027) 2022-08-31 16:02:22 +02:00
backstage.test.ts
backstage.ts Feat/options need types (#794) 2021-04-22 10:07:10 +02:00
controller.ts Added login endpoint rate limit (#2074) 2022-09-26 10:58:58 +03:00
health-check.test.ts
health-check.ts docs: prep to add OpenAPI spec to Unleash docs (#1907) 2022-08-12 11:37:57 +02:00
index.ts Feat/invite user (#2061) 2022-09-30 13:01:32 +02:00
logout.test.ts fix: deletes all sessions for user on logout (#2071) 2022-09-23 14:19:17 +02:00
logout.ts fix: deletes all sessions for user on logout (#2071) 2022-09-23 14:19:17 +02:00
public-invite.test.ts Feat/invite user (#2061) 2022-09-30 13:01:32 +02:00
public-invite.ts Feat/invite user (#2061) 2022-09-30 13:01:32 +02:00
unleash-types.ts Add support for req.logout with passport version 0.6.0 and onwards (#2041) 2022-09-13 09:59:34 +02:00
util.ts