diff --git a/src/lib/openapi/index.test.ts b/src/lib/openapi/index.test.ts index 125f0853f8..7084cc2082 100644 --- a/src/lib/openapi/index.test.ts +++ b/src/lib/openapi/index.test.ts @@ -1,10 +1,4 @@ -import { - createOpenApiSchema, - createRequestSchema, - createResponseSchema, - removeJsonSchemaProps, - schemas, -} from './index'; +import { createOpenApiSchema, removeJsonSchemaProps, schemas } from './index'; import fs from 'fs'; import path from 'path'; @@ -32,37 +26,6 @@ test('all schema $id attributes should have the expected format', () => { }); }); -test('createRequestSchema', () => { - expect(createRequestSchema('schemaName')).toMatchInlineSnapshot(` - Object { - "content": Object { - "application/json": Object { - "schema": Object { - "$ref": "#/components/schemas/schemaName", - }, - }, - }, - "description": "schemaName", - "required": true, - } - `); -}); - -test('createResponseSchema', () => { - expect(createResponseSchema('schemaName')).toMatchInlineSnapshot(` - Object { - "content": Object { - "application/json": Object { - "schema": Object { - "$ref": "#/components/schemas/schemaName", - }, - }, - }, - "description": "schemaName", - } - `); -}); - test('removeJsonSchemaProps', () => { expect(removeJsonSchemaProps({ a: 'b', $id: 'c', components: {} })) .toMatchInlineSnapshot(` diff --git a/src/lib/openapi/index.ts b/src/lib/openapi/index.ts index f31284fdc3..d7c5a79c3d 100644 --- a/src/lib/openapi/index.ts +++ b/src/lib/openapi/index.ts @@ -204,43 +204,6 @@ export interface JsonSchemaProps { components: object; } -export interface ApiOperation - extends Omit { - operationId: string; - tags: [Tag]; -} - -export const createRequestSchema = ( - schemaName: string, -): OpenAPIV3.RequestBodyObject => { - return { - description: schemaName, - required: true, - content: { - 'application/json': { - schema: { - $ref: `#/components/schemas/${schemaName}`, - }, - }, - }, - }; -}; - -export const createResponseSchema = ( - schemaName: string, -): OpenAPIV3.ResponseObject => { - return { - description: schemaName, - content: { - 'application/json': { - schema: { - $ref: `#/components/schemas/${schemaName}`, - }, - }, - }, - }; -}; - // Remove JSONSchema keys that would result in an invalid OpenAPI spec. export const removeJsonSchemaProps = ( schema: T, diff --git a/src/lib/openapi/spec/empty-response.ts b/src/lib/openapi/spec/empty-response.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/lib/openapi/util/api-operation.ts b/src/lib/openapi/util/api-operation.ts new file mode 100644 index 0000000000..1a6bcb7174 --- /dev/null +++ b/src/lib/openapi/util/api-operation.ts @@ -0,0 +1,7 @@ +import { OpenAPIV3 } from 'openapi-types'; + +export interface ApiOperation + extends Omit { + operationId: string; + tags: [Tag]; +} diff --git a/src/lib/openapi/util/create-request-schema.test.ts b/src/lib/openapi/util/create-request-schema.test.ts new file mode 100644 index 0000000000..f8fa20974d --- /dev/null +++ b/src/lib/openapi/util/create-request-schema.test.ts @@ -0,0 +1,17 @@ +import { createRequestSchema } from './create-request-schema'; + +test('createRequestSchema', () => { + expect(createRequestSchema('schemaName')).toMatchInlineSnapshot(` + Object { + "content": Object { + "application/json": Object { + "schema": Object { + "$ref": "#/components/schemas/schemaName", + }, + }, + }, + "description": "schemaName", + "required": true, + } + `); +}); diff --git a/src/lib/openapi/util/create-request-schema.ts b/src/lib/openapi/util/create-request-schema.ts new file mode 100644 index 0000000000..19d45e532a --- /dev/null +++ b/src/lib/openapi/util/create-request-schema.ts @@ -0,0 +1,17 @@ +import { OpenAPIV3 } from 'openapi-types'; + +export const createRequestSchema = ( + schemaName: string, +): OpenAPIV3.RequestBodyObject => { + return { + description: schemaName, + required: true, + content: { + 'application/json': { + schema: { + $ref: `#/components/schemas/${schemaName}`, + }, + }, + }, + }; +}; diff --git a/src/lib/openapi/util/create-response-schema.test.ts b/src/lib/openapi/util/create-response-schema.test.ts new file mode 100644 index 0000000000..a069083e74 --- /dev/null +++ b/src/lib/openapi/util/create-response-schema.test.ts @@ -0,0 +1,16 @@ +import { createResponseSchema } from './create-response-schema'; + +test('createResponseSchema', () => { + expect(createResponseSchema('schemaName')).toMatchInlineSnapshot(` + Object { + "content": Object { + "application/json": Object { + "schema": Object { + "$ref": "#/components/schemas/schemaName", + }, + }, + }, + "description": "schemaName", + } + `); +}); diff --git a/src/lib/openapi/util/create-response-schema.ts b/src/lib/openapi/util/create-response-schema.ts new file mode 100644 index 0000000000..f8886fbacb --- /dev/null +++ b/src/lib/openapi/util/create-response-schema.ts @@ -0,0 +1,16 @@ +import { OpenAPIV3 } from 'openapi-types'; + +export const createResponseSchema = ( + schemaName: string, +): OpenAPIV3.ResponseObject => { + return { + description: schemaName, + content: { + 'application/json': { + schema: { + $ref: `#/components/schemas/${schemaName}`, + }, + }, + }, + }; +}; diff --git a/src/lib/openapi/util/standard-responses.ts b/src/lib/openapi/util/standard-responses.ts index e1fe52c666..c206249215 100644 --- a/src/lib/openapi/util/standard-responses.ts +++ b/src/lib/openapi/util/standard-responses.ts @@ -1,14 +1,14 @@ export const emptyResponse = { - description: 'emptyResponse', -}; + description: 'This response has no body.', +} as const; -export const unauthorizedResponse = { +const unauthorizedResponse = { description: 'Authorization information is missing or invalid. Provide a valid API token as the `authorization` header, e.g. `authorization:*.*.my-admin-token`.', } as const; -export const badRequestResponse = { - description: 'The request data do not match what we expect.', +const badRequestResponse = { + description: 'The request data does not match what we expect.', } as const; const standardResponses = { diff --git a/src/lib/routes/admin-api/addon.ts b/src/lib/routes/admin-api/addon.ts index 946c4bb0eb..c1afed996d 100644 --- a/src/lib/routes/admin-api/addon.ts +++ b/src/lib/routes/admin-api/addon.ts @@ -12,7 +12,8 @@ import { UPDATE_ADDON, } from '../../types/permissions'; import { IAuthRequest } from '../unleash-types'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { OpenApiService } from '../../services/openapi-service'; import { AddonSchema, addonSchema } from '../../openapi/spec/addon-schema'; import { serializeDates } from '../../types/serialize-dates'; diff --git a/src/lib/routes/admin-api/api-token.ts b/src/lib/routes/admin-api/api-token.ts index db35039e03..49392e315c 100644 --- a/src/lib/routes/admin-api/api-token.ts +++ b/src/lib/routes/admin-api/api-token.ts @@ -18,7 +18,8 @@ import { ApiTokenType, IApiToken } from '../../types/models/api-token'; import { createApiToken } from '../../schema/api-token-schema'; import { OpenApiService } from '../../services/openapi-service'; import { IUnleashServices } from '../../types'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { apiTokensSchema, ApiTokensSchema, diff --git a/src/lib/routes/admin-api/archive.ts b/src/lib/routes/admin-api/archive.ts index c717b490c7..86767e9d89 100644 --- a/src/lib/routes/admin-api/archive.ts +++ b/src/lib/routes/admin-api/archive.ts @@ -13,7 +13,7 @@ import { } from '../../openapi/spec/features-schema'; import { serializeDates } from '../../types/serialize-dates'; import { OpenApiService } from '../../services/openapi-service'; -import { createResponseSchema } from '../../openapi'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { emptyResponse } from '../../openapi/util/standard-responses'; export default class ArchiveController extends Controller { diff --git a/src/lib/routes/admin-api/bootstrap-ui.ts b/src/lib/routes/admin-api/bootstrap-ui.ts index 486e805467..8bd11285dc 100644 --- a/src/lib/routes/admin-api/bootstrap-ui.ts +++ b/src/lib/routes/admin-api/bootstrap-ui.ts @@ -21,7 +21,7 @@ import { IProject } from '../../types/model'; import { IUserPermission } from '../../types/stores/access-store'; import { OpenApiService } from '../../services/openapi-service'; import { NONE } from '../../types/permissions'; -import { createResponseSchema } from '../../openapi'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { BootstrapUiSchema, bootstrapUiSchema, diff --git a/src/lib/routes/admin-api/client-metrics.ts b/src/lib/routes/admin-api/client-metrics.ts index 7255491861..5447abf7d1 100644 --- a/src/lib/routes/admin-api/client-metrics.ts +++ b/src/lib/routes/admin-api/client-metrics.ts @@ -5,7 +5,7 @@ import { IUnleashServices } from '../../types'; import { Logger } from '../../logger'; import ClientMetricsServiceV2 from '../../services/client-metrics/metrics-service-v2'; import { NONE } from '../../types/permissions'; -import { createResponseSchema } from '../../openapi'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { OpenApiService } from '../../services/openapi-service'; import { serializeDates } from '../../types/serialize-dates'; import { diff --git a/src/lib/routes/admin-api/config.ts b/src/lib/routes/admin-api/config.ts index 48d9ce820b..db3d6c56a0 100644 --- a/src/lib/routes/admin-api/config.ts +++ b/src/lib/routes/admin-api/config.ts @@ -10,7 +10,7 @@ import { SimpleAuthSettings, } from '../../types/settings/simple-auth-settings'; import { NONE } from '../../types/permissions'; -import { createResponseSchema } from '../../openapi'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { uiConfigSchema, UiConfigSchema, diff --git a/src/lib/routes/admin-api/constraints.ts b/src/lib/routes/admin-api/constraints.ts index 9c6d18ec8a..215a05510f 100644 --- a/src/lib/routes/admin-api/constraints.ts +++ b/src/lib/routes/admin-api/constraints.ts @@ -7,7 +7,7 @@ import { NONE } from '../../types/permissions'; import Controller from '../controller'; import { Logger } from '../../logger'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; export default class ConstraintController extends Controller { private featureService: FeatureToggleService; diff --git a/src/lib/routes/admin-api/context.ts b/src/lib/routes/admin-api/context.ts index 1dbf694f8a..d6e8cfee06 100644 --- a/src/lib/routes/admin-api/context.ts +++ b/src/lib/routes/admin-api/context.ts @@ -23,7 +23,8 @@ import { } from '../../openapi/spec/context-field-schema'; import { ContextFieldsSchema } from '../../openapi/spec/context-fields-schema'; import { UpsertContextFieldSchema } from '../../openapi/spec/upsert-context-field-schema'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { serializeDates } from '../../types/serialize-dates'; import NotFoundError from '../../error/notfound-error'; import { NameSchema } from '../../openapi/spec/name-schema'; diff --git a/src/lib/routes/admin-api/environments.ts b/src/lib/routes/admin-api/environments.ts index 66a8887b64..a0e49ef6d1 100644 --- a/src/lib/routes/admin-api/environments.ts +++ b/src/lib/routes/admin-api/environments.ts @@ -6,7 +6,8 @@ import EnvironmentService from '../../services/environment-service'; import { Logger } from '../../logger'; import { ADMIN, NONE } from '../../types/permissions'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { environmentsSchema, EnvironmentsSchema, diff --git a/src/lib/routes/admin-api/event.ts b/src/lib/routes/admin-api/event.ts index 2a751ff051..4537145fe8 100644 --- a/src/lib/routes/admin-api/event.ts +++ b/src/lib/routes/admin-api/event.ts @@ -7,8 +7,8 @@ import { IEvent } from '../../types/events'; import Controller from '../controller'; import { anonymise } from '../../util/anonymise'; import { OpenApiService } from '../../services/openapi-service'; -import { createResponseSchema } from '../../../lib/openapi'; -import { endpointDescriptions } from '../../../lib/openapi/endpoint-descriptions'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; +import { endpointDescriptions } from '../../openapi/endpoint-descriptions'; import { eventsSchema, EventsSchema, diff --git a/src/lib/routes/admin-api/feature-type.ts b/src/lib/routes/admin-api/feature-type.ts index 4aa847b336..416e8120d9 100644 --- a/src/lib/routes/admin-api/feature-type.ts +++ b/src/lib/routes/admin-api/feature-type.ts @@ -6,7 +6,7 @@ import { IUnleashConfig } from '../../types/option'; import { OpenApiService } from '../../services/openapi-service'; import { NONE } from '../../types/permissions'; import { FeatureTypesSchema } from '../../openapi/spec/feature-types-schema'; -import { createResponseSchema } from '../../openapi'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import Controller from '../controller'; const version = 1; diff --git a/src/lib/routes/admin-api/feature.ts b/src/lib/routes/admin-api/feature.ts index 6abbd97129..9a17b3645c 100644 --- a/src/lib/routes/admin-api/feature.ts +++ b/src/lib/routes/admin-api/feature.ts @@ -24,7 +24,8 @@ import { TagSchema } from '../../openapi/spec/tag-schema'; import { TagsSchema } from '../../openapi/spec/tags-schema'; import { serializeDates } from '../../types/serialize-dates'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { emptyResponse } from '../../openapi/util/standard-responses'; const version = 1; diff --git a/src/lib/routes/admin-api/metrics.ts b/src/lib/routes/admin-api/metrics.ts index cd9db42b04..957f0179ce 100644 --- a/src/lib/routes/admin-api/metrics.ts +++ b/src/lib/routes/admin-api/metrics.ts @@ -5,7 +5,8 @@ import { IUnleashConfig } from '../../types/option'; import { IUnleashServices } from '../../types/services'; import { Logger } from '../../logger'; import ClientInstanceService from '../../services/client-metrics/instance-service'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { ApplicationSchema } from '../../openapi/spec/application-schema'; import { ApplicationsSchema } from '../../openapi/spec/applications-schema'; import { emptyResponse } from '../../openapi/util/standard-responses'; diff --git a/src/lib/routes/admin-api/project/environments.ts b/src/lib/routes/admin-api/project/environments.ts index a135a7450a..30eb6b5747 100644 --- a/src/lib/routes/admin-api/project/environments.ts +++ b/src/lib/routes/admin-api/project/environments.ts @@ -5,7 +5,7 @@ import { IUnleashServices } from '../../../types/services'; import { Logger } from '../../../logger'; import EnvironmentService from '../../../services/environment-service'; import { UPDATE_PROJECT } from '../../../types/permissions'; -import { createRequestSchema } from '../../../openapi'; +import { createRequestSchema } from '../../../openapi/util/create-request-schema'; import { ProjectEnvironmentSchema } from '../../../openapi/spec/project-environment-schema'; import { emptyResponse } from '../../../openapi/util/standard-responses'; diff --git a/src/lib/routes/admin-api/project/features.ts b/src/lib/routes/admin-api/project/features.ts index d4ad3b3f3b..5f7cc388ea 100644 --- a/src/lib/routes/admin-api/project/features.ts +++ b/src/lib/routes/admin-api/project/features.ts @@ -33,7 +33,8 @@ import { UpdateFeatureStrategySchema } from '../../../openapi/spec/update-featur import { CreateFeatureStrategySchema } from '../../../openapi/spec/create-feature-strategy-schema'; import { serializeDates } from '../../../types/serialize-dates'; import { OpenApiService } from '../../../services/openapi-service'; -import { createRequestSchema, createResponseSchema } from '../../../openapi'; +import { createRequestSchema } from '../../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../../openapi/util/create-response-schema'; import { FeatureEnvironmentSchema } from '../../../openapi/spec/feature-environment-schema'; import { emptyResponse } from '../../../openapi/util/standard-responses'; diff --git a/src/lib/routes/admin-api/project/health-report.ts b/src/lib/routes/admin-api/project/health-report.ts index a64e7a8c65..8c5a70a268 100644 --- a/src/lib/routes/admin-api/project/health-report.ts +++ b/src/lib/routes/admin-api/project/health-report.ts @@ -7,7 +7,7 @@ import { Logger } from '../../../logger'; import { IArchivedQuery, IProjectParam } from '../../../types/model'; import { NONE } from '../../../types/permissions'; import { OpenApiService } from '../../../services/openapi-service'; -import { createResponseSchema } from '../../../openapi'; +import { createResponseSchema } from '../../../openapi/util/create-response-schema'; import { healthOverviewSchema, HealthOverviewSchema, diff --git a/src/lib/routes/admin-api/project/index.ts b/src/lib/routes/admin-api/project/index.ts index 4e97d5f3c3..374d70c4ca 100644 --- a/src/lib/routes/admin-api/project/index.ts +++ b/src/lib/routes/admin-api/project/index.ts @@ -14,7 +14,7 @@ import { } from '../../../openapi/spec/projects-schema'; import { OpenApiService } from '../../../services/openapi-service'; import { serializeDates } from '../../../types/serialize-dates'; -import { createResponseSchema } from '../../../openapi'; +import { createResponseSchema } from '../../../openapi/util/create-response-schema'; export default class ProjectApi extends Controller { private projectService: ProjectService; diff --git a/src/lib/routes/admin-api/project/variants.ts b/src/lib/routes/admin-api/project/variants.ts index 48e9d9cf70..ebfb7072df 100644 --- a/src/lib/routes/admin-api/project/variants.ts +++ b/src/lib/routes/admin-api/project/variants.ts @@ -10,7 +10,8 @@ import { IVariant } from '../../../types/model'; import { extractUsername } from '../../../util/extract-user'; import { IAuthRequest } from '../../unleash-types'; import { FeatureVariantsSchema } from '../../../openapi/spec/feature-variants-schema'; -import { createRequestSchema, createResponseSchema } from '../../../openapi'; +import { createRequestSchema } from '../../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../../openapi/util/create-response-schema'; const PREFIX = '/:projectId/features/:featureName/variants'; diff --git a/src/lib/routes/admin-api/state.ts b/src/lib/routes/admin-api/state.ts index 6895678c18..1e22ebbeea 100644 --- a/src/lib/routes/admin-api/state.ts +++ b/src/lib/routes/admin-api/state.ts @@ -12,7 +12,8 @@ import { Logger } from '../../logger'; import StateService from '../../services/state-service'; import { IAuthRequest } from '../unleash-types'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { ExportParametersSchema } from '../../openapi/spec/export-parameters-schema'; import { emptyResponse } from '../../openapi/util/standard-responses'; diff --git a/src/lib/routes/admin-api/strategy.ts b/src/lib/routes/admin-api/strategy.ts index 2443b3e6de..23f76c46ec 100644 --- a/src/lib/routes/admin-api/strategy.ts +++ b/src/lib/routes/admin-api/strategy.ts @@ -13,7 +13,9 @@ import { import { Request, Response } from 'express'; import { IAuthRequest } from '../unleash-types'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { emptyResponse } from '../../openapi/util/standard-responses'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { strategySchema, StrategySchema, @@ -23,7 +25,6 @@ import { StrategiesSchema, } from '../../openapi/spec/strategies-schema'; import { UpsertStrategySchema } from '../../openapi/spec/upsert-strategy-schema'; -import { emptyResponse } from '../../openapi/util/standard-responses'; const version = 1; diff --git a/src/lib/routes/admin-api/tag-type.ts b/src/lib/routes/admin-api/tag-type.ts index 4b481f9470..f67ca866fe 100644 --- a/src/lib/routes/admin-api/tag-type.ts +++ b/src/lib/routes/admin-api/tag-type.ts @@ -12,7 +12,8 @@ import { IUnleashServices } from '../../types/services'; import TagTypeService from '../../services/tag-type-service'; import { Logger } from '../../logger'; import { IAuthRequest } from '../unleash-types'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { TagTypesSchema } from '../../openapi/spec/tag-types-schema'; import { ValidateTagTypeSchema } from '../../openapi/spec/validate-tag-type-schema'; import { diff --git a/src/lib/routes/admin-api/tag.ts b/src/lib/routes/admin-api/tag.ts index 86a40403e9..7b1309314d 100644 --- a/src/lib/routes/admin-api/tag.ts +++ b/src/lib/routes/admin-api/tag.ts @@ -9,7 +9,8 @@ import Controller from '../controller'; import { NONE, UPDATE_FEATURE } from '../../types/permissions'; import { extractUsername } from '../../util/extract-user'; import { IAuthRequest } from '../unleash-types'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { tagsSchema, TagsSchema } from '../../openapi/spec/tags-schema'; import { TagSchema } from '../../openapi/spec/tag-schema'; import { OpenApiService } from '../../services/openapi-service'; diff --git a/src/lib/routes/admin-api/user-admin.ts b/src/lib/routes/admin-api/user-admin.ts index ca9a556c0f..8283c29552 100644 --- a/src/lib/routes/admin-api/user-admin.ts +++ b/src/lib/routes/admin-api/user-admin.ts @@ -14,7 +14,8 @@ import { IUser, SimpleAuthSettings } from '../../server-impl'; import { simpleAuthKey } from '../../types/settings/simple-auth-settings'; import { anonymise } from '../../util/anonymise'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { userSchema, UserSchema } from '../../openapi/spec/user-schema'; import { serializeDates } from '../../types/serialize-dates'; import { usersSchema, UsersSchema } from '../../openapi/spec/users-schema'; diff --git a/src/lib/routes/admin-api/user-feedback.ts b/src/lib/routes/admin-api/user-feedback.ts index 00ff7bf9f3..9de59ed557 100644 --- a/src/lib/routes/admin-api/user-feedback.ts +++ b/src/lib/routes/admin-api/user-feedback.ts @@ -13,7 +13,8 @@ import { } from '../../openapi/spec/feedback-schema'; import { serializeDates } from '../../types/serialize-dates'; import { parseISO } from 'date-fns'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import BadDataError from '../../error/bad-data-error'; class UserFeedbackController extends Controller { diff --git a/src/lib/routes/admin-api/user-splash.ts b/src/lib/routes/admin-api/user-splash.ts index a0d2c7f083..a18fa550c5 100644 --- a/src/lib/routes/admin-api/user-splash.ts +++ b/src/lib/routes/admin-api/user-splash.ts @@ -7,7 +7,7 @@ import UserSplashService from '../../services/user-splash-service'; import { IAuthRequest } from '../unleash-types'; import { NONE } from '../../types/permissions'; import { OpenApiService } from '../../services/openapi-service'; -import { createResponseSchema } from '../../openapi'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { splashSchema, SplashSchema } from '../../openapi/spec/splash-schema'; class UserSplashController extends Controller { diff --git a/src/lib/routes/admin-api/user.ts b/src/lib/routes/admin-api/user.ts index c995611ace..cdfc63153d 100644 --- a/src/lib/routes/admin-api/user.ts +++ b/src/lib/routes/admin-api/user.ts @@ -9,7 +9,8 @@ import UserFeedbackService from '../../services/user-feedback-service'; import UserSplashService from '../../services/user-splash-service'; import { ADMIN, NONE } from '../../types/permissions'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { meSchema, MeSchema } from '../../openapi/spec/me-schema'; import { serializeDates } from '../../types/serialize-dates'; import { IUserPermission } from '../../types/stores/access-store'; diff --git a/src/lib/routes/auth/reset-password-controller.ts b/src/lib/routes/auth/reset-password-controller.ts index d870044ca8..f8fab80a08 100644 --- a/src/lib/routes/auth/reset-password-controller.ts +++ b/src/lib/routes/auth/reset-password-controller.ts @@ -5,7 +5,8 @@ import { Logger } from '../../logger'; import { IUnleashConfig } from '../../types/option'; import { IUnleashServices } from '../../types'; import { NONE } from '../../types/permissions'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { OpenApiService } from '../../services/openapi-service'; import { tokenUserSchema, diff --git a/src/lib/routes/auth/simple-password-provider.ts b/src/lib/routes/auth/simple-password-provider.ts index ee77553ec4..94f11b5642 100644 --- a/src/lib/routes/auth/simple-password-provider.ts +++ b/src/lib/routes/auth/simple-password-provider.ts @@ -7,7 +7,8 @@ import { IUnleashServices } from '../../types'; import { NONE } from '../../types/permissions'; import Controller from '../controller'; import { IAuthRequest } from '../unleash-types'; -import { createRequestSchema, createResponseSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { userSchema, UserSchema } from '../../openapi/spec/user-schema'; import { LoginSchema } from '../../openapi/spec/login-schema'; import { serializeDates } from '../../types/serialize-dates'; diff --git a/src/lib/routes/client-api/feature.ts b/src/lib/routes/client-api/feature.ts index a354c7a4e2..b3fe436349 100644 --- a/src/lib/routes/client-api/feature.ts +++ b/src/lib/routes/client-api/feature.ts @@ -15,7 +15,7 @@ import { FeatureConfigurationClient } from '../../types/stores/feature-strategie import { ClientSpecService } from '../../services/client-spec-service'; import { OpenApiService } from '../../services/openapi-service'; import { NONE } from '../../types/permissions'; -import { createResponseSchema } from '../../openapi'; +import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { ClientFeaturesQuerySchema } from '../../openapi/spec/client-features-query-schema'; import { clientFeatureSchema, diff --git a/src/lib/routes/client-api/metrics.ts b/src/lib/routes/client-api/metrics.ts index 03b7333a74..6f6f58e97f 100644 --- a/src/lib/routes/client-api/metrics.ts +++ b/src/lib/routes/client-api/metrics.ts @@ -11,7 +11,7 @@ import { User } from '../../server-impl'; import { IClientApp } from '../../types/model'; import { NONE } from '../../types/permissions'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema } from '../../openapi'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; import { emptyResponse, getStandardResponses, diff --git a/src/lib/routes/client-api/register.ts b/src/lib/routes/client-api/register.ts index 79fb619675..3da2efb3dd 100644 --- a/src/lib/routes/client-api/register.ts +++ b/src/lib/routes/client-api/register.ts @@ -10,9 +10,9 @@ import ApiUser from '../../types/api-user'; import { ALL } from '../../types/models/api-token'; import { NONE } from '../../types/permissions'; import { OpenApiService } from '../../services/openapi-service'; -import { createRequestSchema } from '../../openapi'; -import { ClientApplicationSchema } from '../../openapi/spec/client-application-schema'; import { emptyResponse } from '../../openapi/util/standard-responses'; +import { createRequestSchema } from '../../openapi/util/create-request-schema'; +import { ClientApplicationSchema } from '../../openapi/spec/client-application-schema'; export default class RegisterController extends Controller { logger: Logger; diff --git a/src/lib/routes/health-check.ts b/src/lib/routes/health-check.ts index b1afa6ce11..b6be7da184 100644 --- a/src/lib/routes/health-check.ts +++ b/src/lib/routes/health-check.ts @@ -7,7 +7,7 @@ import { OpenApiService } from '../services/openapi-service'; import Controller from './controller'; import { NONE } from '../types/permissions'; -import { createResponseSchema } from '../openapi'; +import { createResponseSchema } from '../openapi/util/create-response-schema'; import { HealthCheckSchema } from '../openapi/spec/health-check-schema'; export class HealthCheckController extends Controller { diff --git a/src/lib/services/openapi-service.ts b/src/lib/services/openapi-service.ts index 5d64be44b6..97c5d125a2 100644 --- a/src/lib/services/openapi-service.ts +++ b/src/lib/services/openapi-service.ts @@ -2,12 +2,12 @@ import openapi, { IExpressOpenApi } from '@unleash/express-openapi'; import { Express, RequestHandler, Response } from 'express'; import { IUnleashConfig } from '../types/option'; import { - ApiOperation, createOpenApiSchema, JsonSchemaProps, removeJsonSchemaProps, SchemaId, } from '../openapi'; +import { ApiOperation } from '../openapi/util/api-operation'; import { Logger } from '../logger'; import { validateSchema } from '../openapi/validate'; diff --git a/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap b/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap index 116a216944..b8fa58b98a 100644 --- a/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap +++ b/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap @@ -2661,7 +2661,7 @@ Object { ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -2800,7 +2800,7 @@ Object { ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -2832,7 +2832,7 @@ Object { }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -2907,7 +2907,7 @@ Object { ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -2930,7 +2930,7 @@ Object { ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3059,7 +3059,7 @@ Object { }, "responses": Object { "201": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3083,7 +3083,7 @@ Object { }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3106,7 +3106,7 @@ Object { ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3166,7 +3166,7 @@ Object { }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3179,7 +3179,7 @@ Object { "operationId": "getAllEnvironments", "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3203,7 +3203,7 @@ Object { }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3256,7 +3256,7 @@ Object { ], "responses": Object { "204": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3279,7 +3279,7 @@ Object { ], "responses": Object { "204": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3405,7 +3405,7 @@ If the provided project does not exist, the list of events will be empty.", "operationId": "validateFeature", "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3513,7 +3513,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3628,7 +3628,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3688,7 +3688,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "202": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3772,7 +3772,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3803,7 +3803,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -3903,7 +3903,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -4368,7 +4368,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -4787,7 +4787,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "202": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -4829,7 +4829,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "201": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -4852,7 +4852,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -4914,7 +4914,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -4937,7 +4937,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -4960,7 +4960,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5063,7 +5063,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5123,7 +5123,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5165,7 +5165,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "201": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5226,7 +5226,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5446,7 +5446,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5469,7 +5469,7 @@ If the provided project does not exist, the list of events will be empty.", ], "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5570,7 +5570,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5594,7 +5594,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, "400": Object { "description": "passwordMismatch", @@ -5671,10 +5671,10 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "202": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, "400": Object { - "description": "The request data do not match what we expect.", + "description": "The request data does not match what we expect.", }, }, "tags": Array [ @@ -5698,7 +5698,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "202": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5722,7 +5722,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5746,7 +5746,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [ @@ -5790,7 +5790,7 @@ If the provided project does not exist, the list of events will be empty.", }, "responses": Object { "200": Object { - "description": "emptyResponse", + "description": "This response has no body.", }, }, "tags": Array [