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

fix: fix broken OpenAPI spec #1846

Merged
merged 24 commits into from
Jul 28, 2022
Merged

fix: fix broken OpenAPI spec #1846

merged 24 commits into from
Jul 28, 2022

Conversation

thomasheartman
Copy link
Contributor

This PR fixes a few OpenAPI spec issues that we had. It also introduces an extra validation step of the API description that we generate to help us stay more in line with the spec going forward.

Background and fixes

Using the online Swagger editor, I realized we had a number of minor issues that should be resolved. They were (primarily):

Using examples instead of example

examples is apparently a newer addition to the spec (3.1.0; we're on 3.0.3), and isn't recognized by a number of parsers (or generators). While this is easy to change, ajv, which we use for validating our data, didn't recognize example.

To rectify this, I have added example as a valid keyword. It seems that ajv might be validation against version 3.1.0 of the spec, but I'm not sure. You'd think it'd be easy to change, but I haven't found any docs for it.

Empty required lists

According to Smartbear's documentation:

An empty list required: [] is not valid. If all properties are optional, do not specify the required keyword.

But there was nothing validating this for our schemas and we had a few empty lists. I found an openapi validator that catches this and created tests for it. That should stop it from happening going forward.

Missing query parameters

The way we document query parameters (in the state (export) endpoint at least), did not conform to the spec, and no query parameters showed up in the swagger editor. Query parameters do not use typical object schemas. Instead, they must be a list of 'ParameterObject's. I created a query-parameters module to handle this.

Generating types from a query param list that you can use for express's query param object, isn't easy, but a bit of TS black magic fixes that up just fine.

@vercel
Copy link

vercel bot commented Jul 22, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
unleash-docs ⬜️ Ignored (Inspect) Jul 27, 2022 at 7:21AM (UTC)

@github-actions
Copy link

github-actions bot commented Jul 22, 2022

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
90.05% (-1.33% 🔻)
5934/6590
🟢 Branches 80.03% 918/1147
🟢 Functions
83% (-3.22% 🔻)
1299/1565
🟢 Lines
90.06% (-1.25% 🔻)
5797/6437
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / ensureStringValue.ts
100% 100% 100% 100%
🟢
... / isDefined.ts
100% 100% 100% 100%
🟢
... / map-values.ts
100% 100% 100% 100%
🔴
... / group-store.ts
34.55% 25% 25.93% 33.33%
🟢 lib/types/group.ts 90% 0% 100% 90%
🟢 lib/util/env.ts 100% 100% 100% 100%
🟢
... / validateJsonString.ts
100% 100% 100% 100%
🟢 lib/util/semver.ts 92.86% 100% 100% 91.67%
🔴
... / group-service.ts
13.58% 0% 5.71% 14.67%
🟢
... / create-request-schema.ts
100% 100% 100% 100%
🟢
... / create-response-schema.ts
100% 100% 100% 100%
🟢
... / token-user-schema.ts
100% 100% 100% 100%
🟢
... / role-schema.ts
100% 100% 100% 100%
🟢
... / standard-responses.ts
100% 100% 100% 100%
🟢
... / user-schema.ts
100% 100% 100% 100%
🟢
... / serialize-dates.ts
100% 100% 100% 100%
🟢
... / environment-schema.ts
100% 100% 100% 100%
🟢
... / strategies-schema.ts
100% 100% 100% 100%
🟢
... / anonymise.ts
100% 100% 100% 100%
🟢
... / endpoint-descriptions.ts
100% 100% 100% 100%
🟢
... / events-schema.ts
100% 100% 100% 100%
🟢
... / event-schema.ts
100% 100% 100% 100%
🟢
... / feature-events-schema.ts
100% 100% 100% 100%
🟢
... / playground.ts
100% 100% 100% 100%
🟢
... / playground-response-schema.ts
100% 100% 100% 100%
🟢
... / sdk-context-schema.ts
100% 100% 100% 100%
🟢
... / playground-request-schema.ts
100% 100% 100% 100%
🟢
... / playground-feature-schema.ts
100% 100% 100% 100%
🟢
... / me-schema.ts
100% 100% 100% 100%
🟢
... / permission-schema.ts
100% 100% 100% 100%
🟢
... / feedback-schema.ts
100% 100% 100% 100%
🟢
... / ui-config-schema.ts
100% 100% 100% 100%
🟢
... / version-schema.ts
100% 100% 100% 100%
🟢
... / context-field-schema.ts
100% 100% 100% 100%
🟢
... / legal-value-schema.ts
100% 100% 100% 100%
🟢
... / feature-usage-schema.ts
100% 100% 100% 100%
🟢
... / feature-environment-metrics-schema.ts
100% 100% 100% 100%
🟢
... / feature-metrics-schema.ts
100% 100% 100% 100%
🟢
... / bootstrap-ui.ts
100% 100% 100% 100%
🟢
... / bootstrap-ui-schema.ts
100% 100% 100% 100%
🟢
... / feature-type-schema.ts
100% 100% 100% 100%
🟢
... / tag-type-schema.ts
100% 100% 100% 100%
🟢
... / project-schema.ts
100% 100% 100% 100%
🟢
... / export-query-parameters.ts
100% 100% 100% 100%
🟢
... / tags-schema.ts
100% 100% 100% 100%
🟢
... / tag-with-version-schema.ts
100% 100% 100% 100%
🟢
... / addon-schema.ts
100% 100% 100% 100%
🟢
... / addons-schema.ts
100% 100% 100% 100%
🟢
... / addon-type-schema.ts
100% 100% 100% 100%
🟢
... / addon-parameter-schema.ts
100% 100% 100% 100%
🟢
... / api-token.ts
93.02% 60% 100% 92.86%
🟢
... / api-tokens-schema.ts
100% 100% 100% 100%
🟢
... / api-token-schema.ts
100% 100% 100% 100%
🟢
... / users-schema.ts
100% 100% 100% 100%
🟢
... / users-search-schema.ts
100% 100% 100% 100%
🟢
... / reset-password-schema.ts
100% 100% 100% 100%
🟢
... / users-groups-base-schema.ts
100% 100% 100% 100%
🟢
... / group-schema.ts
100% 100% 100% 100%
🟢
... / group-user-model-schema.ts
100% 100% 100% 100%
🟢
... / user-feedback.ts
100% 71.43% 100% 100%
🟢
... / user-splash.ts
100% 100% 100% 100%
🟢
... / splash-schema.ts
100% 100% 100% 100%
🟢
... / health-overview-schema.ts
100% 100% 100% 100%
🟢
... / health-report-schema.ts
100% 100% 100% 100%
🟢
... / projects-schema.ts
100% 100% 100% 100%
🟢
... / environments.ts
100% 100% 100% 100%
🟢
... / environments-schema.ts
100% 100% 100% 100%
🟢
... / client-feature-schema.ts
100% 100% 100% 100%
🟢
... / client-variant-schema.ts
100% 100% 100% 100%
🟢
... / client-features-schema.ts
100% 100% 100% 100%
🟢
... / client-features-query-schema.ts
100% 100% 100% 100%
🟢
... / segment-schema.ts
100% 100% 100% 100%
🟢
... / application-schema.ts
100% 100% 100% 100%
🟢
... / applications-schema.ts
100% 100% 100% 100%
🟢
... / change-password-schema.ts
100% 100% 100% 100%
🟢
... / client-application-schema.ts
100% 100% 100% 100%
🟢
... / client-metrics-schema.ts
100% 100% 100% 100%
🟢
... / date-schema.ts
100% 100% 100% 100%
🟢
... / context-fields-schema.ts
100% 100% 100% 100%
🟢
... / create-api-token-schema.ts
100% 100% 100% 100%
🟢
... / create-feature-strategy-schema.ts
100% 100% 100% 100%
🟢
... / create-user-schema.ts
100% 100% 100% 100%
🟢
... / email-schema.ts
100% 100% 100% 100%
🟢
... / feature-environment-schema.ts
100% 100% 100% 100%
🟢
... / feature-strategy-segment-schema.ts
100% 100% 100% 100%
🟢
... / feature-tag-schema.ts
100% 100% 100% 100%
🟢
... / feature-types-schema.ts
100% 100% 100% 100%
🟢
... / feature-variants-schema.ts
100% 100% 100% 100%
🟢
... / health-check-schema.ts
100% 100% 100% 100%
🟢
... / id-schema.ts
100% 100% 100% 100%
🟢
... / login-schema.ts
100% 100% 100% 100%
🟢
... / name-schema.ts
100% 100% 100% 100%
🟢
... / omit-keys.ts
100% 100% 100% 100%
🟢
... / password-schema.ts
100% 100% 100% 100%
🟢
... / patches-schema.ts
100% 100% 100% 100%
🟢
... / patch-schema.ts
100% 100% 100% 100%
🟢
... / project-environment-schema.ts
100% 100% 100% 100%
🟢
... / set-strategy-sort-order-schema.ts
100% 100% 100% 100%
🟢
... / sort-order-schema.ts
100% 100% 100% 100%
🟢
... / state-schema.ts
100% 100% 100% 100%
🟢
... / tag-types-schema.ts
100% 100% 100% 100%
🟢
... / update-api-token-schema.ts
100% 100% 100% 100%
🟢
... / update-feature-schema.ts
100% 100% 100% 100%
🟢
... / update-feature-strategy-schema.ts
100% 100% 100% 100%
🟢
... / update-tag-type-schema.ts
100% 100% 100% 100%
🟢
... / update-user-schema.ts
100% 100% 100% 100%
🟢
... / upsert-context-field-schema.ts
100% 100% 100% 100%
🟢
... / upsert-strategy-schema.ts
100% 100% 100% 100%
🟢
... / validate-password-schema.ts
100% 100% 100% 100%
🟢
... / validate-tag-type-schema.ts
100% 100% 100% 100%
🟢
... / variants-schema.ts
100% 100% 100% 100%
🟢
... / groups-schema.ts
100% 100% 100% 100%
🟢
... / validate.ts
100% 66.67% 100% 100%
🟢
... / client-spec-service.ts
100% 100% 100% 100%
🟢
... / playground-service.ts
100% 87.5% 100% 100%
🟢
... / offline-unleash-client.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 lib/types/events.ts
92.15% (-7.85% 🔻)
100%
86.36% (-13.64% 🔻)
92.15% (-7.85% 🔻)
🟢
... / addon-store.ts
82.5%
76.92% (-3.08% 🔻)
76.92% 82.5%
🟢
... / feature-strategy-store.ts
90.91% 79.31% 83.33% 91.53%
🟢
... / feature-toggle-client-store.ts
98.57% (-1.43% 🔻)
79.31% (+2.39% 🔼)
100%
98.57% (-1.43% 🔻)
🟢
... / create-config.ts
96.69%
91.11% (+6.04% 🔼)
90% (-10% 🔻)
96.61%
🟡
... / access-service.ts
80% 93.1%
80.7% (-1.3% 🔻)
78.72%
🟢 lib/routes/util.ts
84.85% (-3.03% 🔻)
73.68% (-5.26% 🔻)
100%
84.38% (-3.13% 🔻)
🟢
... / constraint-types.ts
93.33% (-3.44% 🔻)
83.33% (-16.67% 🔻)
85.71%
91.67% (-4.17% 🔻)
🟡
... / project-service.ts
75.16% (-16.57% 🔻)
61.11% (-7.64% 🔻)
71.43% (-20.88% 🔻)
75.86% (-15.52% 🔻)
🟢
... / controller.ts
96.88% (-3.13% 🔻)
100%
93.33% (-6.67% 🔻)
96.77% (-3.23% 🔻)
🟢
... / user-admin.ts
84.69% (-2.21% 🔻)
66.67% (-13.33% 🔻)
62.5% (-20.83% 🔻)
85.57% (-1.34% 🔻)
🟢
... / features.ts
92.24% 100% 90% 92.24%
🟢
... / metrics.ts
88.89% (-2.02% 🔻)
33.33% 100%
88.89% (-2.02% 🔻)
🟡
... / health-service.ts
66.67% (-33.33% 🔻)
100%
50% (-50% 🔻)
66.67% (-33.33% 🔻)
🟢
... / user-service.ts
88.97% (-1.18% 🔻)
69.39% (-1.34% 🔻)
86.36%
89.55% (-1.22% 🔻)
🔴
... / password-undefined.ts
14.29% (-85.71% 🔻)
100%
0% (-100% 🔻)
14.29% (-85.71% 🔻)
🟡
... / user-splash-service.ts
69.23% (-2.2% 🔻)
0% 80%
69.23% (-2.2% 🔻)

Test suite run success

1066 tests passing in 180 suites.

Report generated by 🧪jest coverage report action from 98d8784

Copy link
Contributor

@chriswk chriswk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Also reasonable to keep 3.0 compatibility (examples/example). 👍

@thomasheartman thomasheartman merged commit 6afc0a6 into main Jul 28, 2022
@thomasheartman thomasheartman deleted the fix/fix-openapi-spec branch July 28, 2022 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants