fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #101 from nicolas-chaulet/refactor/types-dir

refactor(types): move types from client folder to types

authored by

Lubos and committed by
GitHub
df992785 1c1a86ac

+247 -353
-9
src/client/interfaces/Client.ts
··· 1 - import type { Model } from './Model'; 2 - import type { Service } from './Service'; 3 - 4 - export interface Client { 5 - models: Model[]; 6 - server: string; 7 - services: Service[]; 8 - version: string; 9 - }
-6
src/client/interfaces/Enum.ts
··· 1 - export interface Enum { 2 - 'x-enum-description'?: string; 3 - 'x-enum-varname'?: string; 4 - description?: string; 5 - value: string | number; 6 - }
-34
src/client/interfaces/Model.ts
··· 1 - import type { Enum } from './Enum'; 2 - import type { Schema } from './Schema'; 3 - 4 - export interface Model extends Schema { 5 - /** 6 - * **Experimental.** Contains list of original refs so they can be used 7 - * to access the schema from anywhere instead of relying on string name. 8 - * This allows us to do things like detect type of ref. 9 - */ 10 - $refs: string[]; 11 - base: string; 12 - default?: string; 13 - deprecated?: boolean; 14 - description: string | null; 15 - enum: Enum[]; 16 - enums: Model[]; 17 - export: 18 - | 'all-of' 19 - | 'any-of' 20 - | 'array' 21 - | 'const' 22 - | 'dictionary' 23 - | 'enum' 24 - | 'generic' 25 - | 'interface' 26 - | 'one-of' 27 - | 'reference'; 28 - imports: string[]; 29 - link: Model | null; 30 - name: string; 31 - properties: Model[]; 32 - template: string | null; 33 - type: string; 34 - }
-5
src/client/interfaces/ModelComposition.ts
··· 1 - import type { Model } from './Model'; 2 - 3 - export interface ModelComposition extends Pick<Model, '$refs' | 'enums' | 'imports' | 'properties'> { 4 - export: Extract<Model['export'], 'all-of' | 'any-of' | 'one-of'>; 5 - }
-23
src/client/interfaces/Operation.ts
··· 1 - import type { OperationError } from './OperationError'; 2 - import type { OperationParameters } from './OperationParameters'; 3 - import type { OperationResponse } from './OperationResponse'; 4 - 5 - export interface Operation extends OperationParameters { 6 - deprecated: boolean; 7 - description: string | null; 8 - errors: OperationError[]; 9 - method: 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT'; 10 - /** 11 - * Method name. Methods contain the request logic. 12 - */ 13 - name: string; 14 - path: string; 15 - responseHeader: string | null; 16 - results: OperationResponse[]; 17 - /** 18 - * Service name, might be without postfix. This will be used to name the 19 - * exported class. 20 - */ 21 - service: string; 22 - summary: string | null; 23 - }
-4
src/client/interfaces/OperationError.ts
··· 1 - export interface OperationError { 2 - code: number; 3 - description: string; 4 - }
-7
src/client/interfaces/OperationParameter.ts
··· 1 - import type { Model } from './Model'; 2 - 3 - export interface OperationParameter extends Model { 4 - in: 'path' | 'query' | 'header' | 'formData' | 'body' | 'cookie'; 5 - prop: string; 6 - mediaType: string | null; 7 - }
-12
src/client/interfaces/OperationParameters.ts
··· 1 - import type { Model } from './Model'; 2 - import type { OperationParameter } from './OperationParameter'; 3 - 4 - export interface OperationParameters extends Pick<Model, '$refs' | 'imports'> { 5 - parameters: OperationParameter[]; 6 - parametersBody: OperationParameter | null; 7 - parametersCookie: OperationParameter[]; 8 - parametersForm: OperationParameter[]; 9 - parametersHeader: OperationParameter[]; 10 - parametersPath: OperationParameter[]; 11 - parametersQuery: OperationParameter[]; 12 - }
-6
src/client/interfaces/OperationResponse.ts
··· 1 - import type { Model } from './Model'; 2 - 3 - export interface OperationResponse extends Model { 4 - in: 'response' | 'header'; 5 - code: number; 6 - }
-31
src/client/interfaces/Schema.ts
··· 1 - export interface Schema { 2 - exclusiveMaximum?: boolean; 3 - exclusiveMinimum?: boolean; 4 - format?: 5 - | 'binary' 6 - | 'boolean' 7 - | 'byte' 8 - | 'date-time' 9 - | 'date' 10 - | 'double' 11 - | 'float' 12 - | 'int32' 13 - | 'int64' 14 - | 'password' 15 - | 'string'; 16 - isDefinition: boolean; 17 - isNullable: boolean; 18 - isReadOnly: boolean; 19 - isRequired: boolean; 20 - maximum?: number; 21 - maxItems?: number; 22 - maxLength?: number; 23 - maxProperties?: number; 24 - minimum?: number; 25 - minItems?: number; 26 - minLength?: number; 27 - minProperties?: number; 28 - multipleOf?: number; 29 - pattern?: string; 30 - uniqueItems?: boolean; 31 - }
-6
src/client/interfaces/Service.ts
··· 1 - import type { Model } from './Model'; 2 - import type { Operation } from './Operation'; 3 - 4 - export interface Service extends Pick<Model, '$refs' | 'imports' | 'name'> { 5 - operations: Operation[]; 6 - }
-8
src/client/interfaces/Type.ts
··· 1 - export interface Type { 2 - $refs: string[]; 3 - base: string; 4 - imports: string[]; 5 - isNullable: boolean; 6 - template: string | null; 7 - type: string; 8 - }
-4
src/client/interfaces/WithEnumExtension.ts
··· 1 - export interface WithEnumExtension { 2 - 'x-enum-descriptions'?: ReadonlyArray<string>; 3 - 'x-enum-varnames'?: ReadonlyArray<string>; 4 - }
+1 -1
src/index.ts
··· 4 4 5 5 import { sync } from 'cross-spawn'; 6 6 7 - import type { Client } from './client/interfaces/Client'; 8 7 import { parse as parseV2 } from './openApi/v2'; 9 8 import { parse as parseV3 } from './openApi/v3'; 9 + import type { Client } from './types/client'; 10 10 import type { Config, UserConfig } from './types/config'; 11 11 import { getOpenApiSpec } from './utils/getOpenApiSpec'; 12 12 import { registerHandlebarTemplates } from './utils/handlebars';
+1 -1
src/openApi/v2/index.ts
··· 1 - import type { Client } from '../../client/interfaces/Client'; 1 + import type { Client } from '../../types/client'; 2 2 import type { Config } from '../../types/config'; 3 3 import type { OpenApi } from './interfaces/OpenApi'; 4 4 import { getModels } from './parser/getModels';
+1 -1
src/openApi/v2/interfaces/OpenApiItems.ts
··· 1 - import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension'; 1 + import type { WithEnumExtension } from '../../../types/client'; 2 2 3 3 /** 4 4 * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#itemsObject
+1 -1
src/openApi/v2/interfaces/OpenApiParameter.ts
··· 1 - import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension'; 1 + import type { WithEnumExtension } from '../../../types/client'; 2 2 import type { WithNullableExtension } from './Extensions/WithNullableExtension'; 3 3 import type { OpenApiItems } from './OpenApiItems'; 4 4 import type { OpenApiReference } from './OpenApiReference';
+1 -1
src/openApi/v2/interfaces/OpenApiSchema.ts
··· 1 - import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension'; 1 + import type { WithEnumExtension } from '../../../types/client'; 2 2 import type { Dictionary } from '../../../utils/types'; 3 3 import type { WithNullableExtension } from './Extensions/WithNullableExtension'; 4 4 import type { OpenApiExternalDocs } from './OpenApiExternalDocs';
+1 -1
src/openApi/v2/parser/getModel.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import { getEnums } from '../../../utils/getEnums'; 3 3 import { getPattern } from '../../../utils/getPattern'; 4 4 import { getType } from '../../../utils/type';
+1 -2
src/openApi/v2/parser/getModelComposition.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 2 - import type { ModelComposition } from '../../../client/interfaces/ModelComposition'; 1 + import type { Model, ModelComposition } from '../../../types/client'; 3 2 import type { OpenApi } from '../interfaces/OpenApi'; 4 3 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 5 4 import type { getModel } from './getModel';
+1 -1
src/openApi/v2/parser/getModelProperties.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import { escapeName } from '../../../utils/escapeName'; 3 3 import { getPattern } from '../../../utils/getPattern'; 4 4 import { getType } from '../../../utils/type';
-29
src/openApi/v2/parser/getModelTemplate.spec.ts
··· 1 - import { describe, expect, it } from 'vitest'; 2 - 3 - import { getModelTemplate } from './getModelTemplate'; 4 - 5 - describe('getModelTemplate', () => { 6 - it('should return generic for template type', () => { 7 - const template = getModelTemplate({ 8 - $refs: [], 9 - base: 'Link', 10 - imports: ['Model'], 11 - isNullable: false, 12 - template: 'Model', 13 - type: 'Link<Model>', 14 - }); 15 - expect(template).toEqual('<T>'); 16 - }); 17 - 18 - it('should return empty for primary type', () => { 19 - const template = getModelTemplate({ 20 - $refs: [], 21 - base: 'string', 22 - imports: [], 23 - isNullable: false, 24 - template: null, 25 - type: 'string', 26 - }); 27 - expect(template).toEqual(''); 28 - }); 29 - });
-9
src/openApi/v2/parser/getModelTemplate.ts
··· 1 - import type { Type } from '../../../client/interfaces/Type'; 2 - 3 - /** 4 - * If our model has a template type, then we want to generalize that! 5 - * In that case we should return "<T>" as our template type. 6 - * @param modelClass The parsed model class type. 7 - * @returns The model template type (<T> or empty). 8 - */ 9 - export const getModelTemplate = (modelClass: Type): string => (modelClass.template ? '<T>' : '');
+1 -1
src/openApi/v2/parser/getModels.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import { reservedWords } from '../../../utils/reservedWords'; 3 3 import { getType } from '../../../utils/type'; 4 4 import type { OpenApi } from '../interfaces/OpenApi';
+9 -3
src/openApi/v2/parser/getOperation.ts
··· 1 - import type { Operation } from '../../../client/interfaces/Operation'; 2 - import type { OperationParameters } from '../../../client/interfaces/OperationParameters'; 1 + import type { Operation, OperationParameter, OperationParameters } from '../../../types/client'; 3 2 import type { Config } from '../../../types/config'; 4 3 import { getOperationName } from '../../../utils/operation'; 5 4 import type { OpenApi } from '../interfaces/OpenApi'; ··· 10 9 import { getOperationResponses } from './getOperationResponses'; 11 10 import { getOperationResults } from './getOperationResults'; 12 11 import { getServiceName } from './getServiceName'; 13 - import { sortByRequired } from './sortByRequired'; 12 + 13 + const sortByRequired = (a: OperationParameter, b: OperationParameter): number => { 14 + const aNeedsValue = a.isRequired && a.default === undefined; 15 + const bNeedsValue = b.isRequired && b.default === undefined; 16 + if (aNeedsValue && !bNeedsValue) return -1; 17 + if (bNeedsValue && !aNeedsValue) return 1; 18 + return 0; 19 + }; 14 20 15 21 export const getOperation = ( 16 22 openApi: OpenApi,
+1 -2
src/openApi/v2/parser/getOperationErrors.ts
··· 1 - import type { OperationError } from '../../../client/interfaces/OperationError'; 2 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { OperationError, OperationResponse } from '../../../types/client'; 3 2 4 3 /** 5 4 *
+1 -1
src/openApi/v2/parser/getOperationParameter.ts
··· 1 - import type { OperationParameter } from '../../../client/interfaces/OperationParameter'; 1 + import type { OperationParameter } from '../../../types/client'; 2 2 import { getEnums } from '../../../utils/getEnums'; 3 3 import { getPattern } from '../../../utils/getPattern'; 4 4 import { getType } from '../../../utils/type';
+1 -1
src/openApi/v2/parser/getOperationParameterDefault.ts
··· 1 - import type { OperationParameter } from '../../../client/interfaces/OperationParameter'; 1 + import type { OperationParameter } from '../../../types/client'; 2 2 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 3 3 4 4 export const getOperationParameterDefault = (
+1 -1
src/openApi/v2/parser/getOperationParameters.ts
··· 1 - import type { OperationParameters } from '../../../client/interfaces/OperationParameters'; 1 + import type { OperationParameters } from '../../../types/client'; 2 2 import type { OpenApi } from '../interfaces/OpenApi'; 3 3 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 4 4 import { getOperationParameter } from './getOperationParameter';
+1 -1
src/openApi/v2/parser/getOperationResponse.ts
··· 1 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { OperationResponse } from '../../../types/client'; 2 2 import { getPattern } from '../../../utils/getPattern'; 3 3 import { getType } from '../../../utils/type'; 4 4 import type { OpenApi } from '../interfaces/OpenApi';
+1 -1
src/openApi/v2/parser/getOperationResponseHeader.ts
··· 1 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { OperationResponse } from '../../../types/client'; 2 2 3 3 export const getOperationResponseHeader = (operationResponses: OperationResponse[]): string | null => { 4 4 const header = operationResponses.find(operationResponses => operationResponses.in === 'header');
+1 -1
src/openApi/v2/parser/getOperationResponses.ts
··· 1 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { OperationResponse } from '../../../types/client'; 2 2 import type { OpenApi } from '../interfaces/OpenApi'; 3 3 import type { OpenApiResponse } from '../interfaces/OpenApiResponse'; 4 4 import type { OpenApiResponses } from '../interfaces/OpenApiResponses';
+1 -2
src/openApi/v2/parser/getOperationResults.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 2 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { Model, OperationResponse } from '../../../types/client'; 3 2 4 3 const areEqual = (a: Model, b: Model): boolean => { 5 4 const equal = a.type === b.type && a.base === b.base && a.template === b.template;
+1 -1
src/openApi/v2/parser/getRequiredPropertiesFromComposition.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import type { OpenApi } from '../interfaces/OpenApi'; 3 3 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 4 4 import type { getModel } from './getModel';
+1 -1
src/openApi/v2/parser/getServices.ts
··· 1 - import type { Service } from '../../../client/interfaces/Service'; 1 + import type { Service } from '../../../types/client'; 2 2 import type { Config } from '../../../types/config'; 3 3 import { unique } from '../../../utils/unique'; 4 4 import type { OpenApi } from '../interfaces/OpenApi';
-9
src/openApi/v2/parser/sortByRequired.ts
··· 1 - import type { OperationParameter } from '../../../client/interfaces/OperationParameter'; 2 - 3 - export const sortByRequired = (a: OperationParameter, b: OperationParameter): number => { 4 - const aNeedsValue = a.isRequired && a.default === undefined; 5 - const bNeedsValue = b.isRequired && b.default === undefined; 6 - if (aNeedsValue && !bNeedsValue) return -1; 7 - if (bNeedsValue && !aNeedsValue) return 1; 8 - return 0; 9 - };
+1 -1
src/openApi/v3/index.ts
··· 1 - import type { Client } from '../../client/interfaces/Client'; 1 + import type { Client } from '../../types/client'; 2 2 import type { Config } from '../../types/config'; 3 3 import type { OpenApi } from './interfaces/OpenApi'; 4 4 import { getModels } from './parser/getModels';
+1 -1
src/openApi/v3/interfaces/OpenApiSchema.ts
··· 1 - import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension'; 1 + import type { WithEnumExtension } from '../../../types/client'; 2 2 import type { Dictionary } from '../../../utils/types'; 3 3 import type { OpenApiDiscriminator } from './OpenApiDiscriminator'; 4 4 import type { OpenApiExternalDocs } from './OpenApiExternalDocs';
+1 -1
src/openApi/v3/interfaces/OpenApiServerVariable.ts
··· 1 - import type { WithEnumExtension } from '../../../client/interfaces/WithEnumExtension'; 1 + import type { WithEnumExtension } from '../../../types/client'; 2 2 3 3 /** 4 4 * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#serverVariableObject
+1 -1
src/openApi/v3/parser/getModel.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import { getEnums } from '../../../utils/getEnums'; 3 3 import { getPattern } from '../../../utils/getPattern'; 4 4 import { getType } from '../../../utils/type';
+1 -2
src/openApi/v3/parser/getModelComposition.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 2 - import type { ModelComposition } from '../../../client/interfaces/ModelComposition'; 1 + import type { Model, ModelComposition } from '../../../types/client'; 3 2 import type { OpenApi } from '../interfaces/OpenApi'; 4 3 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 5 4 import type { getModel } from './getModel';
+1 -1
src/openApi/v3/parser/getModelDefault.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 3 3 4 4 export const getModelDefault = (definition: OpenApiSchema, model?: Model): string | undefined => {
+1 -1
src/openApi/v3/parser/getModelProperties.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import { findOneOfParentDiscriminator, mapPropertyValue } from '../../../utils/discriminator'; 3 3 import { escapeName } from '../../../utils/escapeName'; 4 4 import { getPattern } from '../../../utils/getPattern';
-29
src/openApi/v3/parser/getModelTemplate.spec.ts
··· 1 - import { describe, expect, it } from 'vitest'; 2 - 3 - import { getModelTemplate } from './getModelTemplate'; 4 - 5 - describe('getModelTemplate', () => { 6 - it('should return generic for template type', () => { 7 - const template = getModelTemplate({ 8 - $refs: [], 9 - base: 'Link', 10 - imports: ['Model'], 11 - isNullable: false, 12 - template: 'Model', 13 - type: 'Link<Model>', 14 - }); 15 - expect(template).toEqual('<T>'); 16 - }); 17 - 18 - it('should return empty for primary type', () => { 19 - const template = getModelTemplate({ 20 - $refs: [], 21 - base: 'string', 22 - imports: [], 23 - isNullable: false, 24 - template: null, 25 - type: 'string', 26 - }); 27 - expect(template).toEqual(''); 28 - }); 29 - });
-9
src/openApi/v3/parser/getModelTemplate.ts
··· 1 - import type { Type } from '../../../client/interfaces/Type'; 2 - 3 - /** 4 - * If our model has a template type, then we want to generalize that! 5 - * In that case we should return "<T>" as our template type. 6 - * @param modelClass The parsed model class type. 7 - * @returns The model template type (<T> or empty). 8 - */ 9 - export const getModelTemplate = (modelClass: Type): string => (modelClass.template ? '<T>' : '');
+1 -1
src/openApi/v3/parser/getModels.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import { reservedWords } from '../../../utils/reservedWords'; 3 3 import { getType } from '../../../utils/type'; 4 4 import type { OpenApi } from '../interfaces/OpenApi';
+1 -2
src/openApi/v3/parser/getOperationErrors.ts
··· 1 - import type { OperationError } from '../../../client/interfaces/OperationError'; 2 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { OperationError, OperationResponse } from '../../../types/client'; 3 2 4 3 export const getOperationErrors = (operationResponses: OperationResponse[]): OperationError[] => 5 4 operationResponses
+1 -1
src/openApi/v3/parser/getOperationParameter.ts
··· 1 - import type { OperationParameter } from '../../../client/interfaces/OperationParameter'; 1 + import type { OperationParameter } from '../../../types/client'; 2 2 import { getPattern } from '../../../utils/getPattern'; 3 3 import { getType } from '../../../utils/type'; 4 4 import type { OpenApi } from '../interfaces/OpenApi';
+1 -1
src/openApi/v3/parser/getOperationParameters.ts
··· 1 - import type { OperationParameters } from '../../../client/interfaces/OperationParameters'; 1 + import type { OperationParameters } from '../../../types/client'; 2 2 import type { OpenApi } from '../interfaces/OpenApi'; 3 3 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 4 4 import { getOperationParameter } from './getOperationParameter';
+1 -1
src/openApi/v3/parser/getOperationRequestBody.ts
··· 1 - import type { OperationParameter } from '../../../client/interfaces/OperationParameter'; 1 + import type { OperationParameter } from '../../../types/client'; 2 2 import { getPattern } from '../../../utils/getPattern'; 3 3 import { getType } from '../../../utils/type'; 4 4 import type { OpenApi } from '../interfaces/OpenApi';
+1 -1
src/openApi/v3/parser/getOperationResponse.ts
··· 1 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { OperationResponse } from '../../../types/client'; 2 2 import { getPattern } from '../../../utils/getPattern'; 3 3 import { getType } from '../../../utils/type'; 4 4 import type { OpenApi } from '../interfaces/OpenApi';
+1 -1
src/openApi/v3/parser/getOperationResponseHeader.ts
··· 1 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { OperationResponse } from '../../../types/client'; 2 2 3 3 export const getOperationResponseHeader = (operationResponses: OperationResponse[]): string | null => { 4 4 const header = operationResponses.find(operationResponses => operationResponses.in === 'header');
+1 -1
src/openApi/v3/parser/getOperationResponses.ts
··· 1 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { OperationResponse } from '../../../types/client'; 2 2 import type { OpenApi } from '../interfaces/OpenApi'; 3 3 import type { OpenApiResponse } from '../interfaces/OpenApiResponse'; 4 4 import type { OpenApiResponses } from '../interfaces/OpenApiResponses';
+1 -2
src/openApi/v3/parser/getOperationResults.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 2 - import type { OperationResponse } from '../../../client/interfaces/OperationResponse'; 1 + import type { Model, OperationResponse } from '../../../types/client'; 3 2 4 3 const areEqual = (a: Model, b: Model): boolean => { 5 4 const equal = a.type === b.type && a.base === b.base && a.template === b.template;
+1 -1
src/openApi/v3/parser/getRequiredPropertiesFromComposition.ts
··· 1 - import type { Model } from '../../../client/interfaces/Model'; 1 + import type { Model } from '../../../types/client'; 2 2 import type { OpenApi } from '../interfaces/OpenApi'; 3 3 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 4 4 import type { getModel } from './getModel';
+1 -2
src/openApi/v3/parser/getServices.ts
··· 1 - import type { Operation } from '../../../client/interfaces/Operation'; 2 - import type { Service } from '../../../client/interfaces/Service'; 1 + import type { Operation, Service } from '../../../types/client'; 3 2 import type { Config } from '../../../types/config'; 4 3 import { unique } from '../../../utils/unique'; 5 4 import type { OpenApi } from '../interfaces/OpenApi';
+1 -3
src/openApi/v3/parser/operation.ts
··· 1 - import type { Operation } from '../../../client/interfaces/Operation'; 2 - import type { OperationParameter } from '../../../client/interfaces/OperationParameter'; 3 - import type { OperationParameters } from '../../../client/interfaces/OperationParameters'; 1 + import type { Operation, OperationParameter, OperationParameters } from '../../../types/client'; 4 2 import type { Config } from '../../../types/config'; 5 3 import { getOperationName } from '../../../utils/operation'; 6 4 import type { OpenApi } from '../interfaces/OpenApi';
+145
src/types/client.ts
··· 1 + export interface Type { 2 + $refs: string[]; 3 + base: string; 4 + imports: string[]; 5 + isNullable: boolean; 6 + template: string | null; 7 + type: string; 8 + } 9 + 10 + export interface ModelComposition extends Pick<Model, '$refs' | 'enums' | 'imports' | 'properties'> { 11 + export: Extract<Model['export'], 'all-of' | 'any-of' | 'one-of'>; 12 + } 13 + 14 + export interface WithEnumExtension { 15 + 'x-enum-descriptions'?: ReadonlyArray<string>; 16 + 'x-enum-varnames'?: ReadonlyArray<string>; 17 + } 18 + 19 + export interface Enum { 20 + 'x-enum-description'?: string; 21 + 'x-enum-varname'?: string; 22 + description?: string; 23 + value: string | number; 24 + } 25 + 26 + export interface OperationError { 27 + code: number; 28 + description: string; 29 + } 30 + 31 + export interface OperationParameter extends Model { 32 + in: 'path' | 'query' | 'header' | 'formData' | 'body' | 'cookie'; 33 + prop: string; 34 + mediaType: string | null; 35 + } 36 + 37 + export interface OperationParameters extends Pick<Model, '$refs' | 'imports'> { 38 + parameters: OperationParameter[]; 39 + parametersBody: OperationParameter | null; 40 + parametersCookie: OperationParameter[]; 41 + parametersForm: OperationParameter[]; 42 + parametersHeader: OperationParameter[]; 43 + parametersPath: OperationParameter[]; 44 + parametersQuery: OperationParameter[]; 45 + } 46 + 47 + export interface OperationResponse extends Model { 48 + in: 'response' | 'header'; 49 + code: number; 50 + } 51 + 52 + export interface Operation extends OperationParameters { 53 + deprecated: boolean; 54 + description: string | null; 55 + errors: OperationError[]; 56 + method: 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT'; 57 + /** 58 + * Method name. Methods contain the request logic. 59 + */ 60 + name: string; 61 + path: string; 62 + responseHeader: string | null; 63 + results: OperationResponse[]; 64 + /** 65 + * Service name, might be without postfix. This will be used to name the 66 + * exported class. 67 + */ 68 + service: string; 69 + summary: string | null; 70 + } 71 + 72 + export interface Schema { 73 + exclusiveMaximum?: boolean; 74 + exclusiveMinimum?: boolean; 75 + format?: 76 + | 'binary' 77 + | 'boolean' 78 + | 'byte' 79 + | 'date-time' 80 + | 'date' 81 + | 'double' 82 + | 'float' 83 + | 'int32' 84 + | 'int64' 85 + | 'password' 86 + | 'string'; 87 + isDefinition: boolean; 88 + isNullable: boolean; 89 + isReadOnly: boolean; 90 + isRequired: boolean; 91 + maximum?: number; 92 + maxItems?: number; 93 + maxLength?: number; 94 + maxProperties?: number; 95 + minimum?: number; 96 + minItems?: number; 97 + minLength?: number; 98 + minProperties?: number; 99 + multipleOf?: number; 100 + pattern?: string; 101 + uniqueItems?: boolean; 102 + } 103 + 104 + export interface Model extends Schema { 105 + /** 106 + * **Experimental.** Contains list of original refs so they can be used 107 + * to access the schema from anywhere instead of relying on string name. 108 + * This allows us to do things like detect type of ref. 109 + */ 110 + $refs: string[]; 111 + base: string; 112 + default?: string; 113 + deprecated?: boolean; 114 + description: string | null; 115 + enum: Enum[]; 116 + enums: Model[]; 117 + export: 118 + | 'all-of' 119 + | 'any-of' 120 + | 'array' 121 + | 'const' 122 + | 'dictionary' 123 + | 'enum' 124 + | 'generic' 125 + | 'interface' 126 + | 'one-of' 127 + | 'reference'; 128 + imports: string[]; 129 + link: Model | null; 130 + name: string; 131 + properties: Model[]; 132 + template: string | null; 133 + type: string; 134 + } 135 + 136 + export interface Service extends Pick<Model, '$refs' | 'imports' | 'name'> { 137 + operations: Operation[]; 138 + } 139 + 140 + export interface Client { 141 + models: Model[]; 142 + server: string; 143 + services: Service[]; 144 + version: string; 145 + }
+11 -3
src/utils/__tests__/sortByName.spec.ts src/utils/__tests__/sort.spec.ts
··· 1 1 import { describe, expect, it } from 'vitest'; 2 2 3 - import type { Model } from '../../client/interfaces/Model'; 4 - import type { Service } from '../../client/interfaces/Service'; 5 - import { sortByName } from '../sortByName'; 3 + import type { Model, Service } from '../../types/client'; 4 + import { sort, sortByName } from '../sort'; 5 + 6 + describe('sort', () => { 7 + it('should return correct index', () => { 8 + expect(sort('a', 'b')).toEqual(-1); 9 + expect(sort('b', 'a')).toEqual(1); 10 + expect(sort('a', 'a')).toEqual(0); 11 + expect(sort('', '')).toEqual(0); 12 + }); 13 + }); 6 14 7 15 describe('sortByName', () => { 8 16 it('should handle empty lists', () => {
+1 -1
src/utils/discriminator.ts
··· 1 - import type { Model } from '../client/interfaces/Model'; 2 1 import type { OpenApi } from '../openApi/v3/interfaces/OpenApi'; 3 2 import type { OpenApiDiscriminator } from '../openApi/v3/interfaces/OpenApiDiscriminator'; 3 + import type { Model } from '../types/client'; 4 4 import { stripNamespace } from './stripNamespace'; 5 5 import type { Dictionary } from './types'; 6 6
+1 -1
src/utils/enum.ts
··· 1 - import type { Enum } from '../client/interfaces/Enum'; 1 + import type { Enum } from '../types/client'; 2 2 import { unescapeName } from './escapeName'; 3 3 import { unique } from './unique'; 4 4
+1 -2
src/utils/getEnums.ts
··· 1 - import type { Enum } from '../client/interfaces/Enum'; 2 - import type { WithEnumExtension } from '../client/interfaces/WithEnumExtension'; 1 + import type { Enum, WithEnumExtension } from '../types/client'; 3 2 import { unique } from './unique'; 4 3 5 4 export const getEnums = (definition: WithEnumExtension, values?: ReadonlyArray<string | number>): Enum[] => {
+1 -1
src/utils/getHttpRequestName.ts
··· 1 - import type { UserConfig } from '../node'; 1 + import type { UserConfig } from '../types/config'; 2 2 3 3 /** 4 4 * Generate the HttpRequest filename based on the selected client
+1 -1
src/utils/getPattern.spec.ts src/utils/__tests__/getPattern.spec.ts
··· 1 1 import { describe, expect, it } from 'vitest'; 2 2 3 - import { getPattern } from './getPattern'; 3 + import { getPattern } from '../getPattern'; 4 4 5 5 describe('getPattern', () => { 6 6 it('should produce correct result', () => {
+2 -5
src/utils/handlebars.ts
··· 2 2 import Handlebars from 'handlebars/runtime'; 3 3 import { EOL } from 'os'; 4 4 5 - import type { Client } from '../client/interfaces/Client'; 6 - import type { Model } from '../client/interfaces/Model'; 7 - import type { OperationParameter } from '../client/interfaces/OperationParameter'; 8 - import type { Service } from '../client/interfaces/Service'; 9 5 import templateClient from '../templates/client.hbs'; 10 6 import angularGetHeaders from '../templates/core/angular/getHeaders.hbs'; 11 7 import angularGetRequestBody from '../templates/core/angular/getRequestBody.hbs'; ··· 90 86 import partialTypeIntersection from '../templates/partials/typeIntersection.hbs'; 91 87 import partialTypeReference from '../templates/partials/typeReference.hbs'; 92 88 import partialTypeUnion from '../templates/partials/typeUnion.hbs'; 89 + import type { Client, Model, OperationParameter, Service } from '../types/client'; 93 90 import type { Config, UserConfig } from '../types/config'; 94 91 import { enumKey, enumName, enumUnionType, enumValue } from './enum'; 95 92 import { escapeName } from './escapeName'; 96 - import { sortByName } from './sortByName'; 93 + import { sortByName } from './sort'; 97 94 import { unique } from './unique'; 98 95 99 96 const escapeComment = (value: string) =>
+1 -1
src/utils/isSubdirectory.spec.ts src/utils/__tests__/isSubdirectory.spec.ts
··· 2 2 3 3 import { describe, expect, it } from 'vitest'; 4 4 5 - import { isSubDirectory } from './isSubdirectory'; 5 + import { isSubDirectory } from '../isSubdirectory'; 6 6 7 7 describe('isSubDirectory', () => { 8 8 it('should return correct result', () => {
+1 -1
src/utils/operation.ts
··· 1 1 import camelCase from 'camelcase'; 2 2 3 - import type { UserConfig } from '../node'; 3 + import type { UserConfig } from '../types/config'; 4 4 import sanitizeOperationName from './sanitizeOperationName'; 5 5 6 6 /**
+1 -1
src/utils/postProcessClient.ts
··· 1 - import type { Client } from '../client/interfaces/Client'; 1 + import type { Client } from '../types/client'; 2 2 import { postProcessModel } from './postProcessModel'; 3 3 import { postProcessService } from './postProcessService'; 4 4
+1 -1
src/utils/postProcessModel.ts
··· 1 - import type { Model } from '../client/interfaces/Model'; 1 + import type { Model } from '../types/client'; 2 2 import { postProcessModelEnum } from './postProcessModelEnum'; 3 3 import { postProcessModelEnums } from './postProcessModelEnums'; 4 4 import { postProcessModelImports } from './postProcessModelImports';
+1 -1
src/utils/postProcessModelEnum.ts
··· 1 - import type { Model } from '../client/interfaces/Model'; 1 + import type { Model } from '../types/client'; 2 2 3 3 /** 4 4 * Set unique enum values for the model
+1 -1
src/utils/postProcessModelEnums.ts
··· 1 - import type { Model } from '../client/interfaces/Model'; 1 + import type { Model } from '../types/client'; 2 2 3 3 /** 4 4 * Set unique enum values for the model
+1 -1
src/utils/postProcessModelImports.ts
··· 1 - import type { Model } from '../client/interfaces/Model'; 1 + import type { Model } from '../types/client'; 2 2 import { sort } from './sort'; 3 3 import { unique } from './unique'; 4 4
+1 -1
src/utils/postProcessService.ts
··· 1 - import type { Service } from '../client/interfaces/Service'; 1 + import type { Service } from '../types/client'; 2 2 import { postProcessServiceImports } from './postProcessServiceImports'; 3 3 import { postProcessServiceOperations } from './postProcessServiceOperations'; 4 4
+1 -1
src/utils/postProcessServiceImports.ts
··· 1 - import type { Service } from '../client/interfaces/Service'; 1 + import type { Service } from '../types/client'; 2 2 import { sort } from './sort'; 3 3 import { unique } from './unique'; 4 4
+1 -2
src/utils/postProcessServiceOperations.ts
··· 1 - import type { Operation } from '../client/interfaces/Operation'; 2 - import type { Service } from '../client/interfaces/Service'; 1 + import type { Operation, Service } from '../types/client'; 3 2 4 3 export const postProcessServiceOperations = (service: Service): Operation[] => { 5 4 const names = new Map<string, number>();
+1 -1
src/utils/sanitizeTypeName.spec.ts src/utils/__tests__/sanitizeTypeName.spec.ts
··· 1 1 import { describe, expect, it } from 'vitest'; 2 2 3 - import sanitizeTypeName from './sanitizeTypeName'; 3 + import sanitizeTypeName from '../sanitizeTypeName'; 4 4 5 5 describe('sanitizeTypeName', () => { 6 6 it('should remove/replace illegal characters', () => {
-12
src/utils/sort.spec.ts
··· 1 - import { describe, expect, it } from 'vitest'; 2 - 3 - import { sort } from './sort'; 4 - 5 - describe('sort', () => { 6 - it('should return correct index', () => { 7 - expect(sort('a', 'b')).toEqual(-1); 8 - expect(sort('b', 'a')).toEqual(1); 9 - expect(sort('a', 'a')).toEqual(0); 10 - expect(sort('', '')).toEqual(0); 11 - }); 12 - });
+8
src/utils/sort.ts
··· 3 3 const nameB = b.toLowerCase(); 4 4 return nameA.localeCompare(nameB, 'en'); 5 5 }; 6 + 7 + export function sortByName<T extends { name: string }>(items: T[]): T[] { 8 + return items.sort((a, b) => { 9 + const nameA = a.name.toLocaleLowerCase(); 10 + const nameB = b.name.toLocaleLowerCase(); 11 + return nameA.localeCompare(nameB, 'en'); 12 + }); 13 + }
-7
src/utils/sortByName.ts
··· 1 - export function sortByName<T extends { name: string }>(items: T[]): T[] { 2 - return items.sort((a, b) => { 3 - const nameA = a.name.toLocaleLowerCase(); 4 - const nameB = b.name.toLocaleLowerCase(); 5 - return nameA.localeCompare(nameB, 'en'); 6 - }); 7 - }
+1 -1
src/utils/type.ts
··· 1 - import type { Type } from '../client/interfaces/Type'; 1 + import type { Type } from '../types/client'; 2 2 import sanitizeTypeName from './sanitizeTypeName'; 3 3 import { stripNamespace } from './stripNamespace'; 4 4
+1 -1
src/utils/unique.spec.ts src/utils/__tests__/unique.spec.ts
··· 1 1 import { describe, expect, it } from 'vitest'; 2 2 3 - import { unique } from './unique'; 3 + import { unique } from '../unique'; 4 4 5 5 describe('unique', () => { 6 6 it('should return correct index', () => {
+3 -3
src/utils/write/class.ts
··· 1 1 import { writeFileSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 - import type { Client } from '../../client/interfaces/Client'; 5 - import type { UserConfig } from '../../node'; 4 + import type { Client } from '../../types/client'; 5 + import type { UserConfig } from '../../types/config'; 6 6 import { getHttpRequestName } from '../getHttpRequestName'; 7 7 import type { Templates } from '../handlebars'; 8 - import { sortByName } from '../sortByName'; 8 + import { sortByName } from '../sort'; 9 9 10 10 /** 11 11 * Generate the OpenAPI client index file using the Handlebar template and write it to disk.
+1 -1
src/utils/write/client.ts
··· 1 1 import { mkdirSync, rmSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 - import type { Client } from '../../client/interfaces/Client'; 4 + import type { Client } from '../../types/client'; 5 5 import type { Config } from '../../types/config'; 6 6 import type { Templates } from '../handlebars'; 7 7 import { isSubDirectory } from '../isSubdirectory';
+2 -2
src/utils/write/core.ts
··· 1 1 import { copyFileSync, existsSync, writeFileSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 - import type { Client } from '../../client/interfaces/Client'; 5 - import type { UserConfig } from '../../node'; 4 + import type { Client } from '../../types/client'; 5 + import type { UserConfig } from '../../types/config'; 6 6 import { getHttpRequestName } from '../getHttpRequestName'; 7 7 import type { Templates } from '../handlebars'; 8 8
+3 -3
src/utils/write/index.ts
··· 1 1 import { writeFileSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 - import type { Client } from '../../client/interfaces/Client'; 5 - import type { UserConfig } from '../../node'; 4 + import type { Client } from '../../types/client'; 5 + import type { UserConfig } from '../../types/config'; 6 6 import { Templates } from '../handlebars'; 7 - import { sortByName } from '../sortByName'; 7 + import { sortByName } from '../sort'; 8 8 9 9 /** 10 10 * Generate the OpenAPI client index file using the Handlebar template and write it to disk.
+2 -2
src/utils/write/models.ts
··· 1 1 import { writeFileSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 - import type { Client } from '../../client/interfaces/Client'; 5 - import type { UserConfig } from '../../node'; 4 + import type { Client } from '../../types/client'; 5 + import type { UserConfig } from '../../types/config'; 6 6 import type { Templates } from '../handlebars'; 7 7 8 8 /**
+2 -2
src/utils/write/schemas.ts
··· 1 1 import { writeFileSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 - import type { Client } from '../../client/interfaces/Client'; 5 - import type { UserConfig } from '../../node'; 4 + import type { Client } from '../../types/client'; 5 + import type { UserConfig } from '../../types/config'; 6 6 import type { Templates } from '../handlebars'; 7 7 8 8 /**
+1 -1
src/utils/write/services.ts
··· 1 1 import { writeFileSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 - import type { Client } from '../../client/interfaces/Client'; 4 + import type { Client } from '../../types/client'; 5 5 import type { Config } from '../../types/config'; 6 6 import type { Templates } from '../handlebars'; 7 7
+2 -2
tsconfig.check.json
··· 1 1 { 2 2 "compilerOptions": { 3 3 "exactOptionalPropertyTypes": true, 4 - "module": "node16", 5 - "moduleResolution": "node16", 4 + "module": "NodeNext", 5 + "moduleResolution": "NodeNext", 6 6 "noEmit": true, 7 7 "strict": true, 8 8 "target": "ES2020"