Skip to content

Commit

Permalink
refactor(types): move types from client folder to types
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Mar 20, 2024
1 parent 1c1a86a commit e669195
Show file tree
Hide file tree
Showing 89 changed files with 247 additions and 353 deletions.
9 changes: 0 additions & 9 deletions src/client/interfaces/Client.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/client/interfaces/Enum.ts

This file was deleted.

34 changes: 0 additions & 34 deletions src/client/interfaces/Model.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/client/interfaces/ModelComposition.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/client/interfaces/Operation.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/client/interfaces/OperationError.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/client/interfaces/OperationParameter.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/client/interfaces/OperationParameters.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/client/interfaces/OperationResponse.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/client/interfaces/Schema.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/client/interfaces/Service.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/client/interfaces/Type.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/client/interfaces/WithEnumExtension.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { pathToFileURL } from 'node:url';

import { sync } from 'cross-spawn';

import type { Client } from './client/interfaces/Client';
import { parse as parseV2 } from './openApi/v2';
import { parse as parseV3 } from './openApi/v3';
import type { Client } from './types/client';
import type { Config, UserConfig } from './types/config';
import { getOpenApiSpec } from './utils/getOpenApiSpec';
import { registerHandlebarTemplates } from './utils/handlebars';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client } from '../../client/interfaces/Client';
import type { Client } from '../../types/client';
import type { Config } from '../../types/config';
import type { OpenApi } from './interfaces/OpenApi';
import { getModels } from './parser/getModels';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/interfaces/OpenApiItems.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension';
import type { WithEnumExtension } from '../../../types/client';

/**
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#itemsObject
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/interfaces/OpenApiParameter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension';
import type { WithEnumExtension } from '../../../types/client';
import type { WithNullableExtension } from './Extensions/WithNullableExtension';
import type { OpenApiItems } from './OpenApiItems';
import type { OpenApiReference } from './OpenApiReference';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/interfaces/OpenApiSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension';
import type { WithEnumExtension } from '../../../types/client';
import type { Dictionary } from '../../../utils/types';
import type { WithNullableExtension } from './Extensions/WithNullableExtension';
import type { OpenApiExternalDocs } from './OpenApiExternalDocs';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { Model } from '../../../types/client';
import { getEnums } from '../../../utils/getEnums';
import { getPattern } from '../../../utils/getPattern';
import { getType } from '../../../utils/type';
Expand Down
3 changes: 1 addition & 2 deletions src/openApi/v2/parser/getModelComposition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { ModelComposition } from '../../../client/interfaces/ModelComposition';
import type { Model, ModelComposition } from '../../../types/client';
import type { OpenApi } from '../interfaces/OpenApi';
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
import type { getModel } from './getModel';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getModelProperties.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { Model } from '../../../types/client';
import { escapeName } from '../../../utils/escapeName';
import { getPattern } from '../../../utils/getPattern';
import { getType } from '../../../utils/type';
Expand Down
29 changes: 0 additions & 29 deletions src/openApi/v2/parser/getModelTemplate.spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/openApi/v2/parser/getModelTemplate.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getModels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { Model } from '../../../types/client';
import { reservedWords } from '../../../utils/reservedWords';
import { getType } from '../../../utils/type';
import type { OpenApi } from '../interfaces/OpenApi';
Expand Down
12 changes: 9 additions & 3 deletions src/openApi/v2/parser/getOperation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Operation } from '../../../client/interfaces/Operation';
import type { OperationParameters } from '../../../client/interfaces/OperationParameters';
import type { Operation, OperationParameter, OperationParameters } from '../../../types/client';
import type { Config } from '../../../types/config';
import { getOperationName } from '../../../utils/operation';
import type { OpenApi } from '../interfaces/OpenApi';
Expand All @@ -10,7 +9,14 @@ import { getOperationResponseHeader } from './getOperationResponseHeader';
import { getOperationResponses } from './getOperationResponses';
import { getOperationResults } from './getOperationResults';
import { getServiceName } from './getServiceName';
import { sortByRequired } from './sortByRequired';

const sortByRequired = (a: OperationParameter, b: OperationParameter): number => {
const aNeedsValue = a.isRequired && a.default === undefined;
const bNeedsValue = b.isRequired && b.default === undefined;
if (aNeedsValue && !bNeedsValue) return -1;
if (bNeedsValue && !aNeedsValue) return 1;
return 0;
};

export const getOperation = (
openApi: OpenApi,
Expand Down
3 changes: 1 addition & 2 deletions src/openApi/v2/parser/getOperationErrors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { OperationError } from '../../../client/interfaces/OperationError';
import type { OperationResponse } from '../../../client/interfaces/OperationResponse';
import type { OperationError, OperationResponse } from '../../../types/client';

/**
*
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getOperationParameter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OperationParameter } from '../../../client/interfaces/OperationParameter';
import type { OperationParameter } from '../../../types/client';
import { getEnums } from '../../../utils/getEnums';
import { getPattern } from '../../../utils/getPattern';
import { getType } from '../../../utils/type';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getOperationParameterDefault.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OperationParameter } from '../../../client/interfaces/OperationParameter';
import type { OperationParameter } from '../../../types/client';
import type { OpenApiParameter } from '../interfaces/OpenApiParameter';

export const getOperationParameterDefault = (
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getOperationParameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OperationParameters } from '../../../client/interfaces/OperationParameters';
import type { OperationParameters } from '../../../types/client';
import type { OpenApi } from '../interfaces/OpenApi';
import type { OpenApiParameter } from '../interfaces/OpenApiParameter';
import { getOperationParameter } from './getOperationParameter';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getOperationResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OperationResponse } from '../../../client/interfaces/OperationResponse';
import type { OperationResponse } from '../../../types/client';
import { getPattern } from '../../../utils/getPattern';
import { getType } from '../../../utils/type';
import type { OpenApi } from '../interfaces/OpenApi';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getOperationResponseHeader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OperationResponse } from '../../../client/interfaces/OperationResponse';
import type { OperationResponse } from '../../../types/client';

export const getOperationResponseHeader = (operationResponses: OperationResponse[]): string | null => {
const header = operationResponses.find(operationResponses => operationResponses.in === 'header');
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getOperationResponses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OperationResponse } from '../../../client/interfaces/OperationResponse';
import type { OperationResponse } from '../../../types/client';
import type { OpenApi } from '../interfaces/OpenApi';
import type { OpenApiResponse } from '../interfaces/OpenApiResponse';
import type { OpenApiResponses } from '../interfaces/OpenApiResponses';
Expand Down
3 changes: 1 addition & 2 deletions src/openApi/v2/parser/getOperationResults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { OperationResponse } from '../../../client/interfaces/OperationResponse';
import type { Model, OperationResponse } from '../../../types/client';

const areEqual = (a: Model, b: Model): boolean => {
const equal = a.type === b.type && a.base === b.base && a.template === b.template;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { Model } from '../../../types/client';
import type { OpenApi } from '../interfaces/OpenApi';
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
import type { getModel } from './getModel';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v2/parser/getServices.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Service } from '../../../client/interfaces/Service';
import type { Service } from '../../../types/client';
import type { Config } from '../../../types/config';
import { unique } from '../../../utils/unique';
import type { OpenApi } from '../interfaces/OpenApi';
Expand Down
9 changes: 0 additions & 9 deletions src/openApi/v2/parser/sortByRequired.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/openApi/v3/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client } from '../../client/interfaces/Client';
import type { Client } from '../../types/client';
import type { Config } from '../../types/config';
import type { OpenApi } from './interfaces/OpenApi';
import { getModels } from './parser/getModels';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v3/interfaces/OpenApiSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension';
import type { WithEnumExtension } from '../../../types/client';
import type { Dictionary } from '../../../utils/types';
import type { OpenApiDiscriminator } from './OpenApiDiscriminator';
import type { OpenApiExternalDocs } from './OpenApiExternalDocs';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v3/interfaces/OpenApiServerVariable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension';
import type { WithEnumExtension } from '../../../types/client';

/**
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#serverVariableObject
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v3/parser/getModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { Model } from '../../../types/client';
import { getEnums } from '../../../utils/getEnums';
import { getPattern } from '../../../utils/getPattern';
import { getType } from '../../../utils/type';
Expand Down
3 changes: 1 addition & 2 deletions src/openApi/v3/parser/getModelComposition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { ModelComposition } from '../../../client/interfaces/ModelComposition';
import type { Model, ModelComposition } from '../../../types/client';
import type { OpenApi } from '../interfaces/OpenApi';
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';
import type { getModel } from './getModel';
Expand Down
2 changes: 1 addition & 1 deletion src/openApi/v3/parser/getModelDefault.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Model } from '../../../client/interfaces/Model';
import type { Model } from '../../../types/client';
import type { OpenApiSchema } from '../interfaces/OpenApiSchema';

export const getModelDefault = (definition: OpenApiSchema, model?: Model): string | undefined => {
Expand Down
Loading

0 comments on commit e669195

Please sign in to comment.