Skip to content

Commit

Permalink
refactor: fix empty response usage (#1783)
Browse files Browse the repository at this point in the history
* refactor: fix empty response usage

* refactor: move emptyResponse into standard-responses.ts
  • Loading branch information
olav committed Jun 30, 2022
1 parent 2729999 commit 98c7b91
Show file tree
Hide file tree
Showing 21 changed files with 27 additions and 30 deletions.
3 changes: 0 additions & 3 deletions src/lib/openapi/spec/empty-response.ts
@@ -1,3 +0,0 @@
export const emptyResponse = {
description: 'emptyResponse',
};
4 changes: 4 additions & 0 deletions src/lib/openapi/util/standard-responses.ts
@@ -1,3 +1,7 @@
export const emptyResponse = {
description: 'emptyResponse',
};

export const unauthorizedResponse = {
description:
'Authorization information is missing or invalid. Provide a valid API token as the `authorization` header, e.g. `authorization:*.*.my-admin-token`.',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/addon.ts
Expand Up @@ -14,10 +14,10 @@ import {
import { IAuthRequest } from '../unleash-types';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { OpenApiService } from '../../services/openapi-service';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { AddonSchema, addonSchema } from '../../openapi/spec/addon-schema';
import { serializeDates } from '../../types/serialize-dates';
import { AddonsSchema, addonsSchema } from '../../openapi/spec/addons-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

type AddonServices = Pick<IUnleashServices, 'addonService' | 'openApiService'>;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/api-token.ts
Expand Up @@ -28,8 +28,8 @@ import {
apiTokenSchema,
ApiTokenSchema,
} from '../../openapi/spec/api-token-schema';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { UpdateApiTokenSchema } from '../../openapi/spec/update-api-token-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

interface TokenParam {
token: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/archive.ts
Expand Up @@ -14,7 +14,7 @@ import {
import { serializeDates } from '../../types/serialize-dates';
import { OpenApiService } from '../../services/openapi-service';
import { createResponseSchema } from '../../openapi';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { emptyResponse } from '../../openapi/util/standard-responses';

export default class ArchiveController extends Controller {
private readonly logger: Logger;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/context.ts
Expand Up @@ -26,8 +26,8 @@ import { UpsertContextFieldSchema } from '../../openapi/spec/upsert-context-fiel
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { serializeDates } from '../../types/serialize-dates';
import NotFoundError from '../../error/notfound-error';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { NameSchema } from '../../openapi/spec/name-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

interface ContextParam {
contextField: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/environments.ts
Expand Up @@ -16,7 +16,7 @@ import {
EnvironmentSchema,
} from '../../openapi/spec/environment-schema';
import { SortOrderSchema } from '../../openapi/spec/sort-order-schema';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { emptyResponse } from '../../openapi/util/standard-responses';

interface EnvironmentParam {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/feature.ts
Expand Up @@ -25,7 +25,7 @@ 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 { emptyResponse } from '../../openapi/spec/empty-response';
import { emptyResponse } from '../../openapi/util/standard-responses';

const version = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/metrics.ts
Expand Up @@ -5,10 +5,10 @@ import { IUnleashConfig } from '../../types/option';
import { IUnleashServices } from '../../types/services';
import { Logger } from '../../logger';
import ClientInstanceService from '../../services/client-metrics/instance-service';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { ApplicationSchema } from '../../openapi/spec/application-schema';
import { ApplicationsSchema } from '../../openapi/spec/applications-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

class MetricsController extends Controller {
private logger: Logger;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/project/environments.ts
Expand Up @@ -7,7 +7,7 @@ import EnvironmentService from '../../../services/environment-service';
import { UPDATE_PROJECT } from '../../../types/permissions';
import { createRequestSchema } from '../../../openapi';
import { ProjectEnvironmentSchema } from '../../../openapi/spec/project-environment-schema';
import { emptyResponse } from '../../../openapi/spec/empty-response';
import { emptyResponse } from '../../../openapi/util/standard-responses';

const PREFIX = '/:projectId/environments';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/project/features.ts
Expand Up @@ -35,7 +35,7 @@ import { serializeDates } from '../../../types/serialize-dates';
import { OpenApiService } from '../../../services/openapi-service';
import { createRequestSchema, createResponseSchema } from '../../../openapi';
import { FeatureEnvironmentSchema } from '../../../openapi/spec/feature-environment-schema';
import { emptyResponse } from '../../../openapi/spec/empty-response';
import { emptyResponse } from '../../../openapi/util/standard-responses';

interface FeatureStrategyParams {
projectId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/state.ts
Expand Up @@ -13,8 +13,8 @@ import StateService from '../../services/state-service';
import { IAuthRequest } from '../unleash-types';
import { OpenApiService } from '../../services/openapi-service';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { ExportParametersSchema } from '../../openapi/spec/export-parameters-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

const upload = multer({ limits: { fileSize: 5242880 } });
const paramToBool = (param, def) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/strategy.ts
Expand Up @@ -13,7 +13,6 @@ import {
import { Request, Response } from 'express';
import { IAuthRequest } from '../unleash-types';
import { OpenApiService } from '../../services/openapi-service';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import {
strategySchema,
Expand All @@ -24,6 +23,7 @@ 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;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/tag-type.ts
Expand Up @@ -14,14 +14,14 @@ import { Logger } from '../../logger';
import { IAuthRequest } from '../unleash-types';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { TagTypesSchema } from '../../openapi/spec/tag-types-schema';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { ValidateTagTypeSchema } from '../../openapi/spec/validate-tag-type-schema';
import {
tagTypeSchema,
TagTypeSchema,
} from '../../openapi/spec/tag-type-schema';
import { UpdateTagTypeSchema } from '../../openapi/spec/update-tag-type-schema';
import { OpenApiService } from '../../services/openapi-service';
import { emptyResponse } from '../../openapi/util/standard-responses';

const version = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/tag.ts
Expand Up @@ -10,14 +10,14 @@ import { NONE, UPDATE_FEATURE } from '../../types/permissions';
import { extractUsername } from '../../util/extract-user';
import { IAuthRequest } from '../unleash-types';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { tagsSchema, TagsSchema } from '../../openapi/spec/tags-schema';
import { TagSchema } from '../../openapi/spec/tag-schema';
import { OpenApiService } from '../../services/openapi-service';
import {
tagWithVersionSchema,
TagWithVersionSchema,
} from '../../openapi/spec/tag-with-version-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

const version = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/user-admin.ts
Expand Up @@ -14,7 +14,6 @@ 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 { emptyResponse } from '../../openapi/spec/empty-response';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { userSchema, UserSchema } from '../../openapi/spec/user-schema';
import { serializeDates } from '../../types/serialize-dates';
Expand All @@ -31,6 +30,7 @@ import {
resetPasswordSchema,
ResetPasswordSchema,
} from '../../openapi/spec/reset-password-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

export default class UserAdminController extends Controller {
private anonymise: boolean = false;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/admin-api/user.ts
Expand Up @@ -10,11 +10,11 @@ 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 { emptyResponse } from '../../openapi/spec/empty-response';
import { meSchema, MeSchema } from '../../openapi/spec/me-schema';
import { serializeDates } from '../../types/serialize-dates';
import { IUserPermission } from '../../types/stores/access-store';
import { PasswordSchema } from '../../openapi/spec/password-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

class UserController extends Controller {
private accessService: AccessService;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/auth/reset-password-controller.ts
Expand Up @@ -6,13 +6,13 @@ import { IUnleashConfig } from '../../types/option';
import { IUnleashServices } from '../../types';
import { NONE } from '../../types/permissions';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { emptyResponse } from '../../openapi/spec/empty-response';
import { OpenApiService } from '../../services/openapi-service';
import {
tokenUserSchema,
TokenUserSchema,
} from '../../openapi/spec/token-user-schema';
import { EmailSchema } from '../../openapi/spec/email-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

interface IValidateQuery {
token: string;
Expand Down
9 changes: 6 additions & 3 deletions src/lib/routes/client-api/metrics.ts
Expand Up @@ -11,8 +11,11 @@ import { User } from '../../server-impl';
import { IClientApp } from '../../types/model';
import { NONE } from '../../types/permissions';
import { OpenApiService } from '../../services/openapi-service';
import { createRequestSchema, createResponseSchema } from '../../openapi';
import { getStandardResponses } from '../../openapi/util/standard-responses';
import { createRequestSchema } from '../../openapi';
import {
emptyResponse,
getStandardResponses,
} from '../../openapi/util/standard-responses';

export default class ClientMetricsController extends Controller {
logger: Logger;
Expand Down Expand Up @@ -56,7 +59,7 @@ export default class ClientMetricsController extends Controller {
requestBody: createRequestSchema('clientMetricsSchema'),
responses: {
...getStandardResponses(400),
202: createResponseSchema('emptyResponse'),
202: emptyResponse,
},
}),
],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/routes/client-api/register.ts
Expand Up @@ -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 { emptyResponse } from '../../openapi/spec/empty-response';
import { createRequestSchema } from '../../openapi';
import { ClientApplicationSchema } from '../../openapi/spec/client-application-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';

export default class RegisterController extends Controller {
logger: Logger;
Expand Down
Expand Up @@ -5671,13 +5671,6 @@ If the provided project does not exist, the list of events will be empty.",
},
"responses": Object {
"202": Object {
"content": Object {
"application/json": Object {
"schema": Object {
"$ref": "#/components/schemas/emptyResponse",
},
},
},
"description": "emptyResponse",
},
"400": Object {
Expand Down

0 comments on commit 98c7b91

Please sign in to comment.