1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/openapi/index.ts

274 lines
10 KiB
TypeScript
Raw Normal View History

import { OpenAPIV3 } from 'openapi-types';
feat: add playground API post endpoint (#1791) * Chore: add unleash-client dependency * Feat: add openapi specs for basic sdk contexts and playground reqs * Feat: add openapi spec for response * Feat: add openAPI entry for playground endpoint * Fix: remove required 'projects' property that doesn't exist * Refactor: add test placeholders for playground api * Chore: improve openAPI description for playground request * Refactor: align example project names * Fix: update openapi snapshot * Fix: summary -> description; example -> examples * Feat: add fast-check and stub out one test. The test doesn't work yet. * Feat: add test and generator for sdk context schema * Feat: add generators and tests for all new schemas * Feat: test that the same input is returned exactly * Feat: add more tests and more schemas * Refactor: clean up tests some * Refactor: simplify url friendliness check * Refactor: fix types for playground request schema generator * Feat: add bad request test * Fix: make parameters the correct shape in generator * Feat: scaffold out tests for service and endpoint Liberal use of @ts-expect-error * Fix: update snapshot with new model * Add missing appName * wip: stub out some extra tests * Feat: model strategies for testing * Feat: model variant payloads better * Refactor: input params for function * Refactor: use email address for user id generation * Chore: update comment * Wip: start stubbing out e2e tests * Refactor: move tests requiring db to e2e file * Fix: make e2e tests run as expected * Fix: make toggle generator test work as expected * Fix: increase timeout for long-running e2e test * Wip: map toggles test * Wip: test movement and cleanup * Refactor: remove `AllowedStrings` in favor of typeof X[number] * Wip: add e2e tests for the service * Wip: tests in progress * Feat: return fuller variant value * Wip: delete redundant test. Both those tests were testing versions of the same thing, so let's delete one of them * Feat: update openAPI snapshot * Feat: hook up the playground service * Feat: fix test cases for e2e api * Refactor: get rid of _one_ 'as unknown as x' cast * Fix: wait for the client to be ready before we pass it back * Fix: weights go to 1000! * Fix: fix some test assertions, add one more test to be sure * Wip: add some test parameters to hopefully avoid timeouts * Fix: don't init the client if there are no toggles If you don't provide it with any toggles to bootstrap, then the client will never be ready. This avoids that. This adds two ways around it because we'll probably get away with a bit less computation if we don't even try to initialize it. However, we also don't want anyone else to make this mistake. * Chore: modify test params * Feat: use the type system to avoid empty lists for initialization * Refactor: make tests simpler * Feat: test basic context values * Feat: test dynamic context values * Fix: make custom context field test more reliable * Feat: use unique arrays for toggles * Feat: make `appName` required in context * Fix: sdk context schema arbitrary: make appName at least 1 char long * Fix: add a minimum length on appName in the context schema * Fix: fix tests that fail due to new requirements * Fix: update a test: remove variant mapping testing * Fix: fix remaining tests * Feat: rename response.toggles -> response.features * Refactor: avoid single-letter predicate variables * Refactor: extract offlineclient into its own file * Refactor: move arbitraries into separate file * Refactor: move playground requests into util function * Fix: remove duplicate declaration of urlFriendlyString * Chore: update comment * Refactor: align on arbitrary generator naming * Feat: Export single strategy arbitrary
2022-07-12 13:01:10 +02:00
import { addonParameterSchema } from './spec/addon-parameter-schema';
import { addonSchema } from './spec/addon-schema';
import { addonsSchema } from './spec/addons-schema';
import { addonTypeSchema } from './spec/addon-type-schema';
import { apiTokenSchema } from './spec/api-token-schema';
import { apiTokensSchema } from './spec/api-tokens-schema';
import { applicationSchema } from './spec/application-schema';
import { applicationsSchema } from './spec/applications-schema';
import { bootstrapUiSchema } from './spec/bootstrap-ui-schema';
import { changePasswordSchema } from './spec/change-password-schema';
import { clientApplicationSchema } from './spec/client-application-schema';
import { clientFeatureSchema } from './spec/client-feature-schema';
import { clientFeaturesQuerySchema } from './spec/client-features-query-schema';
import { clientFeaturesSchema } from './spec/client-features-schema';
import { clientMetricsSchema } from './spec/client-metrics-schema';
import { clientVariantSchema } from './spec/client-variant-schema';
import { cloneFeatureSchema } from './spec/clone-feature-schema';
Complete open api schemas for project features controller (#1563) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * revert * revert * revert * revert * revert * mapper * revert * revert * revert * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * revert * revert * add mappers * add mappers * fix pr comments * ignore report.json * ignore report.json * Route permission required Co-authored-by: olav <mail@olav.io>
2022-05-18 15:17:09 +02:00
import { constraintSchema } from './spec/constraint-schema';
import { contextFieldSchema } from './spec/context-field-schema';
import { contextFieldsSchema } from './spec/context-fields-schema';
import { createApiTokenSchema } from './spec/create-api-token-schema';
import { createFeatureSchema } from './spec/create-feature-schema';
import { createFeatureStrategySchema } from './spec/create-feature-strategy-schema';
import { createUserSchema } from './spec/create-user-schema';
import { dateSchema } from './spec/date-schema';
import { emailSchema } from './spec/email-schema';
import { environmentSchema } from './spec/environment-schema';
import { environmentsSchema } from './spec/environments-schema';
import { eventSchema } from './spec/event-schema';
import { eventsSchema } from './spec/events-schema';
import { featureEnvironmentMetricsSchema } from './spec/feature-environment-metrics-schema';
import { featureEnvironmentSchema } from './spec/feature-environment-schema';
import { featureEventsSchema } from './spec/feature-events-schema';
import { featureMetricsSchema } from './spec/feature-metrics-schema';
Complete open api schemas for project features controller (#1563) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * revert * revert * revert * revert * revert * mapper * revert * revert * revert * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * revert * revert * add mappers * add mappers * fix pr comments * ignore report.json * ignore report.json * Route permission required Co-authored-by: olav <mail@olav.io>
2022-05-18 15:17:09 +02:00
import { featureSchema } from './spec/feature-schema';
import { featuresSchema } from './spec/features-schema';
import { featureStrategySchema } from './spec/feature-strategy-schema';
import { featureStrategySegmentSchema } from './spec/feature-strategy-segment-schema';
import { featureTagSchema } from './spec/feature-tag-schema';
import { featureTypeSchema } from './spec/feature-type-schema';
import { featureTypesSchema } from './spec/feature-types-schema';
import { featureUsageSchema } from './spec/feature-usage-schema';
import { featureVariantsSchema } from './spec/feature-variants-schema';
import { feedbackSchema } from './spec/feedback-schema';
import { healthCheckSchema } from './spec/health-check-schema';
import { healthOverviewSchema } from './spec/health-overview-schema';
import { healthReportSchema } from './spec/health-report-schema';
import { idSchema } from './spec/id-schema';
import { legalValueSchema } from './spec/legal-value-schema';
import { loginSchema } from './spec/login-schema';
import { mapValues } from '../util/map-values';
import { meSchema } from './spec/me-schema';
import { nameSchema } from './spec/name-schema';
import { omitKeys } from '../util/omit-keys';
import { overrideSchema } from './spec/override-schema';
Complete open api schemas for project features controller (#1563) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * Completed OpenAPI Schemas for ProjectFeatures Controller Completed OpenAPI Schemas for Feature Controller (tags) * bug fix * bug fix * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * fix merge conflicts, some refactoring * added emptyResponse, patch feature operation schemas and request * added emptyResponse, patch feature operation schemas and request * patch strategy * patch strategy * update strategy * update strategy * fix pr comment * fix pr comments * improvements * added operationId to schema for better generation * fix pr comment * fix pr comment * fix pr comment * improvements to generated and dynamic types * improvements to generated and dynamic types * improvements to generated and dynamic types * Update response types to use inferred types * Update addTag response status to 201 * refactor: move schema ref destructuring into createSchemaObject * made serialize date handle deep objects * made serialize date handle deep objects * add `name` to IFeatureStrategy nad fix tests * fix pr comments * fix pr comments * Add types to IAuthRequest * Sync StrategySchema for FE and BE - into the rabbit hole * Sync model with OAS spec * revert * revert * revert * revert * revert * mapper * revert * revert * revert * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * remove serialize-dates.ts * revert * revert * add mappers * add mappers * fix pr comments * ignore report.json * ignore report.json * Route permission required Co-authored-by: olav <mail@olav.io>
2022-05-18 15:17:09 +02:00
import { parametersSchema } from './spec/parameters-schema';
import { passwordSchema } from './spec/password-schema';
import { patchesSchema } from './spec/patches-schema';
import { patchSchema } from './spec/patch-schema';
import { permissionSchema } from './spec/permission-schema';
feat: add playground API post endpoint (#1791) * Chore: add unleash-client dependency * Feat: add openapi specs for basic sdk contexts and playground reqs * Feat: add openapi spec for response * Feat: add openAPI entry for playground endpoint * Fix: remove required 'projects' property that doesn't exist * Refactor: add test placeholders for playground api * Chore: improve openAPI description for playground request * Refactor: align example project names * Fix: update openapi snapshot * Fix: summary -> description; example -> examples * Feat: add fast-check and stub out one test. The test doesn't work yet. * Feat: add test and generator for sdk context schema * Feat: add generators and tests for all new schemas * Feat: test that the same input is returned exactly * Feat: add more tests and more schemas * Refactor: clean up tests some * Refactor: simplify url friendliness check * Refactor: fix types for playground request schema generator * Feat: add bad request test * Fix: make parameters the correct shape in generator * Feat: scaffold out tests for service and endpoint Liberal use of @ts-expect-error * Fix: update snapshot with new model * Add missing appName * wip: stub out some extra tests * Feat: model strategies for testing * Feat: model variant payloads better * Refactor: input params for function * Refactor: use email address for user id generation * Chore: update comment * Wip: start stubbing out e2e tests * Refactor: move tests requiring db to e2e file * Fix: make e2e tests run as expected * Fix: make toggle generator test work as expected * Fix: increase timeout for long-running e2e test * Wip: map toggles test * Wip: test movement and cleanup * Refactor: remove `AllowedStrings` in favor of typeof X[number] * Wip: add e2e tests for the service * Wip: tests in progress * Feat: return fuller variant value * Wip: delete redundant test. Both those tests were testing versions of the same thing, so let's delete one of them * Feat: update openAPI snapshot * Feat: hook up the playground service * Feat: fix test cases for e2e api * Refactor: get rid of _one_ 'as unknown as x' cast * Fix: wait for the client to be ready before we pass it back * Fix: weights go to 1000! * Fix: fix some test assertions, add one more test to be sure * Wip: add some test parameters to hopefully avoid timeouts * Fix: don't init the client if there are no toggles If you don't provide it with any toggles to bootstrap, then the client will never be ready. This avoids that. This adds two ways around it because we'll probably get away with a bit less computation if we don't even try to initialize it. However, we also don't want anyone else to make this mistake. * Chore: modify test params * Feat: use the type system to avoid empty lists for initialization * Refactor: make tests simpler * Feat: test basic context values * Feat: test dynamic context values * Fix: make custom context field test more reliable * Feat: use unique arrays for toggles * Feat: make `appName` required in context * Fix: sdk context schema arbitrary: make appName at least 1 char long * Fix: add a minimum length on appName in the context schema * Fix: fix tests that fail due to new requirements * Fix: update a test: remove variant mapping testing * Fix: fix remaining tests * Feat: rename response.toggles -> response.features * Refactor: avoid single-letter predicate variables * Refactor: extract offlineclient into its own file * Refactor: move arbitraries into separate file * Refactor: move playground requests into util function * Fix: remove duplicate declaration of urlFriendlyString * Chore: update comment * Refactor: align on arbitrary generator naming * Feat: Export single strategy arbitrary
2022-07-12 13:01:10 +02:00
import { playgroundFeatureSchema } from './spec/playground-feature-schema';
import { playgroundRequestSchema } from './spec/playground-request-schema';
import { playgroundResponseSchema } from './spec/playground-response-schema';
import { projectEnvironmentSchema } from './spec/project-environment-schema';
import { projectSchema } from './spec/project-schema';
import { projectsSchema } from './spec/projects-schema';
import { resetPasswordSchema } from './spec/reset-password-schema';
import { roleSchema } from './spec/role-schema';
feat: add playground API post endpoint (#1791) * Chore: add unleash-client dependency * Feat: add openapi specs for basic sdk contexts and playground reqs * Feat: add openapi spec for response * Feat: add openAPI entry for playground endpoint * Fix: remove required 'projects' property that doesn't exist * Refactor: add test placeholders for playground api * Chore: improve openAPI description for playground request * Refactor: align example project names * Fix: update openapi snapshot * Fix: summary -> description; example -> examples * Feat: add fast-check and stub out one test. The test doesn't work yet. * Feat: add test and generator for sdk context schema * Feat: add generators and tests for all new schemas * Feat: test that the same input is returned exactly * Feat: add more tests and more schemas * Refactor: clean up tests some * Refactor: simplify url friendliness check * Refactor: fix types for playground request schema generator * Feat: add bad request test * Fix: make parameters the correct shape in generator * Feat: scaffold out tests for service and endpoint Liberal use of @ts-expect-error * Fix: update snapshot with new model * Add missing appName * wip: stub out some extra tests * Feat: model strategies for testing * Feat: model variant payloads better * Refactor: input params for function * Refactor: use email address for user id generation * Chore: update comment * Wip: start stubbing out e2e tests * Refactor: move tests requiring db to e2e file * Fix: make e2e tests run as expected * Fix: make toggle generator test work as expected * Fix: increase timeout for long-running e2e test * Wip: map toggles test * Wip: test movement and cleanup * Refactor: remove `AllowedStrings` in favor of typeof X[number] * Wip: add e2e tests for the service * Wip: tests in progress * Feat: return fuller variant value * Wip: delete redundant test. Both those tests were testing versions of the same thing, so let's delete one of them * Feat: update openAPI snapshot * Feat: hook up the playground service * Feat: fix test cases for e2e api * Refactor: get rid of _one_ 'as unknown as x' cast * Fix: wait for the client to be ready before we pass it back * Fix: weights go to 1000! * Fix: fix some test assertions, add one more test to be sure * Wip: add some test parameters to hopefully avoid timeouts * Fix: don't init the client if there are no toggles If you don't provide it with any toggles to bootstrap, then the client will never be ready. This avoids that. This adds two ways around it because we'll probably get away with a bit less computation if we don't even try to initialize it. However, we also don't want anyone else to make this mistake. * Chore: modify test params * Feat: use the type system to avoid empty lists for initialization * Refactor: make tests simpler * Feat: test basic context values * Feat: test dynamic context values * Fix: make custom context field test more reliable * Feat: use unique arrays for toggles * Feat: make `appName` required in context * Fix: sdk context schema arbitrary: make appName at least 1 char long * Fix: add a minimum length on appName in the context schema * Fix: fix tests that fail due to new requirements * Fix: update a test: remove variant mapping testing * Fix: fix remaining tests * Feat: rename response.toggles -> response.features * Refactor: avoid single-letter predicate variables * Refactor: extract offlineclient into its own file * Refactor: move arbitraries into separate file * Refactor: move playground requests into util function * Fix: remove duplicate declaration of urlFriendlyString * Chore: update comment * Refactor: align on arbitrary generator naming * Feat: Export single strategy arbitrary
2022-07-12 13:01:10 +02:00
import { sdkContextSchema } from './spec/sdk-context-schema';
import { segmentSchema } from './spec/segment-schema';
import { setStrategySortOrderSchema } from './spec/set-strategy-sort-order-schema';
import { sortOrderSchema } from './spec/sort-order-schema';
import { splashSchema } from './spec/splash-schema';
import { stateSchema } from './spec/state-schema';
import { strategiesSchema } from './spec/strategies-schema';
import { strategySchema } from './spec/strategy-schema';
import { tagSchema } from './spec/tag-schema';
import { tagsSchema } from './spec/tags-schema';
import { tagTypeSchema } from './spec/tag-type-schema';
import { tagTypesSchema } from './spec/tag-types-schema';
import { tagWithVersionSchema } from './spec/tag-with-version-schema';
import { tokenUserSchema } from './spec/token-user-schema';
import { uiConfigSchema } from './spec/ui-config-schema';
import { updateApiTokenSchema } from './spec/update-api-token-schema';
import { updateFeatureSchema } from './spec/update-feature-schema';
import { updateFeatureStrategySchema } from './spec/update-feature-strategy-schema';
import { updateTagTypeSchema } from './spec/update-tag-type-schema';
import { updateUserSchema } from './spec/update-user-schema';
import { upsertContextFieldSchema } from './spec/upsert-context-field-schema';
import { upsertStrategySchema } from './spec/upsert-strategy-schema';
import { userSchema } from './spec/user-schema';
import { usersSchema } from './spec/users-schema';
import { usersSearchSchema } from './spec/users-search-schema';
import { validatePasswordSchema } from './spec/validate-password-schema';
import { validateTagTypeSchema } from './spec/validate-tag-type-schema';
import { variantSchema } from './spec/variant-schema';
import { variantsSchema } from './spec/variants-schema';
import { versionSchema } from './spec/version-schema';
feat: add playground API post endpoint (#1791) * Chore: add unleash-client dependency * Feat: add openapi specs for basic sdk contexts and playground reqs * Feat: add openapi spec for response * Feat: add openAPI entry for playground endpoint * Fix: remove required 'projects' property that doesn't exist * Refactor: add test placeholders for playground api * Chore: improve openAPI description for playground request * Refactor: align example project names * Fix: update openapi snapshot * Fix: summary -> description; example -> examples * Feat: add fast-check and stub out one test. The test doesn't work yet. * Feat: add test and generator for sdk context schema * Feat: add generators and tests for all new schemas * Feat: test that the same input is returned exactly * Feat: add more tests and more schemas * Refactor: clean up tests some * Refactor: simplify url friendliness check * Refactor: fix types for playground request schema generator * Feat: add bad request test * Fix: make parameters the correct shape in generator * Feat: scaffold out tests for service and endpoint Liberal use of @ts-expect-error * Fix: update snapshot with new model * Add missing appName * wip: stub out some extra tests * Feat: model strategies for testing * Feat: model variant payloads better * Refactor: input params for function * Refactor: use email address for user id generation * Chore: update comment * Wip: start stubbing out e2e tests * Refactor: move tests requiring db to e2e file * Fix: make e2e tests run as expected * Fix: make toggle generator test work as expected * Fix: increase timeout for long-running e2e test * Wip: map toggles test * Wip: test movement and cleanup * Refactor: remove `AllowedStrings` in favor of typeof X[number] * Wip: add e2e tests for the service * Wip: tests in progress * Feat: return fuller variant value * Wip: delete redundant test. Both those tests were testing versions of the same thing, so let's delete one of them * Feat: update openAPI snapshot * Feat: hook up the playground service * Feat: fix test cases for e2e api * Refactor: get rid of _one_ 'as unknown as x' cast * Fix: wait for the client to be ready before we pass it back * Fix: weights go to 1000! * Fix: fix some test assertions, add one more test to be sure * Wip: add some test parameters to hopefully avoid timeouts * Fix: don't init the client if there are no toggles If you don't provide it with any toggles to bootstrap, then the client will never be ready. This avoids that. This adds two ways around it because we'll probably get away with a bit less computation if we don't even try to initialize it. However, we also don't want anyone else to make this mistake. * Chore: modify test params * Feat: use the type system to avoid empty lists for initialization * Refactor: make tests simpler * Feat: test basic context values * Feat: test dynamic context values * Fix: make custom context field test more reliable * Feat: use unique arrays for toggles * Feat: make `appName` required in context * Fix: sdk context schema arbitrary: make appName at least 1 char long * Fix: add a minimum length on appName in the context schema * Fix: fix tests that fail due to new requirements * Fix: update a test: remove variant mapping testing * Fix: fix remaining tests * Feat: rename response.toggles -> response.features * Refactor: avoid single-letter predicate variables * Refactor: extract offlineclient into its own file * Refactor: move arbitraries into separate file * Refactor: move playground requests into util function * Fix: remove duplicate declaration of urlFriendlyString * Chore: update comment * Refactor: align on arbitrary generator naming * Feat: Export single strategy arbitrary
2022-07-12 13:01:10 +02:00
import { IServerOption } from '../types';
import { URL } from 'url';
import { groupSchema } from './spec/group-schema';
import { groupsSchema } from './spec/groups-schema';
import { groupUserModelSchema } from './spec/group-user-model-schema';
import { usersGroupsBaseSchema } from './spec/users-groups-base-schema';
// All schemas in `openapi/spec` should be listed here.
export const schemas = {
addonParameterSchema,
addonSchema,
addonsSchema,
addonTypeSchema,
apiTokenSchema,
apiTokensSchema,
applicationSchema,
applicationsSchema,
bootstrapUiSchema,
changePasswordSchema,
clientApplicationSchema,
clientFeatureSchema,
clientFeaturesQuerySchema,
clientFeaturesSchema,
clientMetricsSchema,
clientVariantSchema,
cloneFeatureSchema,
constraintSchema,
contextFieldSchema,
contextFieldsSchema,
createApiTokenSchema,
createFeatureSchema,
createFeatureStrategySchema,
createUserSchema,
dateSchema,
emailSchema,
environmentSchema,
environmentsSchema,
eventSchema,
eventsSchema,
featureEnvironmentMetricsSchema,
featureEnvironmentSchema,
featureEventsSchema,
featureMetricsSchema,
featureSchema,
featuresSchema,
featureStrategySchema,
featureStrategySegmentSchema,
featureTagSchema,
featureTypeSchema,
featureTypesSchema,
featureUsageSchema,
featureVariantsSchema,
feedbackSchema,
groupSchema,
groupsSchema,
groupUserModelSchema,
healthCheckSchema,
healthOverviewSchema,
healthReportSchema,
idSchema,
legalValueSchema,
loginSchema,
meSchema,
nameSchema,
overrideSchema,
parametersSchema,
passwordSchema,
patchesSchema,
patchSchema,
permissionSchema,
feat: add playground API post endpoint (#1791) * Chore: add unleash-client dependency * Feat: add openapi specs for basic sdk contexts and playground reqs * Feat: add openapi spec for response * Feat: add openAPI entry for playground endpoint * Fix: remove required 'projects' property that doesn't exist * Refactor: add test placeholders for playground api * Chore: improve openAPI description for playground request * Refactor: align example project names * Fix: update openapi snapshot * Fix: summary -> description; example -> examples * Feat: add fast-check and stub out one test. The test doesn't work yet. * Feat: add test and generator for sdk context schema * Feat: add generators and tests for all new schemas * Feat: test that the same input is returned exactly * Feat: add more tests and more schemas * Refactor: clean up tests some * Refactor: simplify url friendliness check * Refactor: fix types for playground request schema generator * Feat: add bad request test * Fix: make parameters the correct shape in generator * Feat: scaffold out tests for service and endpoint Liberal use of @ts-expect-error * Fix: update snapshot with new model * Add missing appName * wip: stub out some extra tests * Feat: model strategies for testing * Feat: model variant payloads better * Refactor: input params for function * Refactor: use email address for user id generation * Chore: update comment * Wip: start stubbing out e2e tests * Refactor: move tests requiring db to e2e file * Fix: make e2e tests run as expected * Fix: make toggle generator test work as expected * Fix: increase timeout for long-running e2e test * Wip: map toggles test * Wip: test movement and cleanup * Refactor: remove `AllowedStrings` in favor of typeof X[number] * Wip: add e2e tests for the service * Wip: tests in progress * Feat: return fuller variant value * Wip: delete redundant test. Both those tests were testing versions of the same thing, so let's delete one of them * Feat: update openAPI snapshot * Feat: hook up the playground service * Feat: fix test cases for e2e api * Refactor: get rid of _one_ 'as unknown as x' cast * Fix: wait for the client to be ready before we pass it back * Fix: weights go to 1000! * Fix: fix some test assertions, add one more test to be sure * Wip: add some test parameters to hopefully avoid timeouts * Fix: don't init the client if there are no toggles If you don't provide it with any toggles to bootstrap, then the client will never be ready. This avoids that. This adds two ways around it because we'll probably get away with a bit less computation if we don't even try to initialize it. However, we also don't want anyone else to make this mistake. * Chore: modify test params * Feat: use the type system to avoid empty lists for initialization * Refactor: make tests simpler * Feat: test basic context values * Feat: test dynamic context values * Fix: make custom context field test more reliable * Feat: use unique arrays for toggles * Feat: make `appName` required in context * Fix: sdk context schema arbitrary: make appName at least 1 char long * Fix: add a minimum length on appName in the context schema * Fix: fix tests that fail due to new requirements * Fix: update a test: remove variant mapping testing * Fix: fix remaining tests * Feat: rename response.toggles -> response.features * Refactor: avoid single-letter predicate variables * Refactor: extract offlineclient into its own file * Refactor: move arbitraries into separate file * Refactor: move playground requests into util function * Fix: remove duplicate declaration of urlFriendlyString * Chore: update comment * Refactor: align on arbitrary generator naming * Feat: Export single strategy arbitrary
2022-07-12 13:01:10 +02:00
playgroundFeatureSchema,
playgroundRequestSchema,
playgroundResponseSchema,
projectEnvironmentSchema,
projectSchema,
projectsSchema,
resetPasswordSchema,
roleSchema,
feat: add playground API post endpoint (#1791) * Chore: add unleash-client dependency * Feat: add openapi specs for basic sdk contexts and playground reqs * Feat: add openapi spec for response * Feat: add openAPI entry for playground endpoint * Fix: remove required 'projects' property that doesn't exist * Refactor: add test placeholders for playground api * Chore: improve openAPI description for playground request * Refactor: align example project names * Fix: update openapi snapshot * Fix: summary -> description; example -> examples * Feat: add fast-check and stub out one test. The test doesn't work yet. * Feat: add test and generator for sdk context schema * Feat: add generators and tests for all new schemas * Feat: test that the same input is returned exactly * Feat: add more tests and more schemas * Refactor: clean up tests some * Refactor: simplify url friendliness check * Refactor: fix types for playground request schema generator * Feat: add bad request test * Fix: make parameters the correct shape in generator * Feat: scaffold out tests for service and endpoint Liberal use of @ts-expect-error * Fix: update snapshot with new model * Add missing appName * wip: stub out some extra tests * Feat: model strategies for testing * Feat: model variant payloads better * Refactor: input params for function * Refactor: use email address for user id generation * Chore: update comment * Wip: start stubbing out e2e tests * Refactor: move tests requiring db to e2e file * Fix: make e2e tests run as expected * Fix: make toggle generator test work as expected * Fix: increase timeout for long-running e2e test * Wip: map toggles test * Wip: test movement and cleanup * Refactor: remove `AllowedStrings` in favor of typeof X[number] * Wip: add e2e tests for the service * Wip: tests in progress * Feat: return fuller variant value * Wip: delete redundant test. Both those tests were testing versions of the same thing, so let's delete one of them * Feat: update openAPI snapshot * Feat: hook up the playground service * Feat: fix test cases for e2e api * Refactor: get rid of _one_ 'as unknown as x' cast * Fix: wait for the client to be ready before we pass it back * Fix: weights go to 1000! * Fix: fix some test assertions, add one more test to be sure * Wip: add some test parameters to hopefully avoid timeouts * Fix: don't init the client if there are no toggles If you don't provide it with any toggles to bootstrap, then the client will never be ready. This avoids that. This adds two ways around it because we'll probably get away with a bit less computation if we don't even try to initialize it. However, we also don't want anyone else to make this mistake. * Chore: modify test params * Feat: use the type system to avoid empty lists for initialization * Refactor: make tests simpler * Feat: test basic context values * Feat: test dynamic context values * Fix: make custom context field test more reliable * Feat: use unique arrays for toggles * Feat: make `appName` required in context * Fix: sdk context schema arbitrary: make appName at least 1 char long * Fix: add a minimum length on appName in the context schema * Fix: fix tests that fail due to new requirements * Fix: update a test: remove variant mapping testing * Fix: fix remaining tests * Feat: rename response.toggles -> response.features * Refactor: avoid single-letter predicate variables * Refactor: extract offlineclient into its own file * Refactor: move arbitraries into separate file * Refactor: move playground requests into util function * Fix: remove duplicate declaration of urlFriendlyString * Chore: update comment * Refactor: align on arbitrary generator naming * Feat: Export single strategy arbitrary
2022-07-12 13:01:10 +02:00
sdkContextSchema,
segmentSchema,
setStrategySortOrderSchema,
sortOrderSchema,
splashSchema,
stateSchema,
strategiesSchema,
strategySchema,
tagSchema,
tagsSchema,
tagTypeSchema,
tagTypesSchema,
tagWithVersionSchema,
tokenUserSchema,
uiConfigSchema,
updateApiTokenSchema,
updateFeatureSchema,
updateFeatureStrategySchema,
updateTagTypeSchema,
updateUserSchema,
upsertContextFieldSchema,
upsertStrategySchema,
usersGroupsBaseSchema,
userSchema,
usersSchema,
usersSearchSchema,
validatePasswordSchema,
validateTagTypeSchema,
variantSchema,
variantsSchema,
versionSchema,
};
// Schemas must have an $id property on the form "#/components/schemas/mySchema".
export type SchemaId = typeof schemas[keyof typeof schemas]['$id'];
// Schemas must list all their $refs in `components`, including nested schemas.
export type SchemaRef = typeof schemas[keyof typeof schemas]['components'];
// JSON schema properties that should not be included in the OpenAPI spec.
export interface JsonSchemaProps {
$id: string;
components: object;
}
// Remove JSONSchema keys that would result in an invalid OpenAPI spec.
export const removeJsonSchemaProps = <T extends JsonSchemaProps>(
schema: T,
): OpenAPIV3.SchemaObject => {
return omitKeys(schema, '$id', 'components');
};
const findRootUrl: (unleashUrl: string, baseUriPath: string) => string = (
unleashUrl: string,
baseUriPath?: string,
) => {
if (!baseUriPath) {
return unleashUrl;
}
const baseUrl = new URL(unleashUrl);
if (baseUrl.pathname.indexOf(baseUriPath) >= 0) {
return `${baseUrl.protocol}//${baseUrl.host}`;
}
return baseUrl.toString();
};
export const createOpenApiSchema = ({
unleashUrl,
baseUriPath,
}: Pick<IServerOption, 'unleashUrl' | 'baseUriPath'>): Omit<
OpenAPIV3.Document,
'paths'
> => {
const url = findRootUrl(unleashUrl, baseUriPath);
return {
openapi: '3.0.3',
servers: url ? [{ url }] : [],
info: {
title: 'Unleash API',
version: process.env.npm_package_version!,
},
security: [{ apiKey: [] }],
components: {
securitySchemes: {
apiKey: {
type: 'apiKey',
in: 'header',
name: 'Authorization',
},
},
schemas: mapValues(schemas, removeJsonSchemaProps),
},
};
};