Skip to content

Commit

Permalink
refactor: classified the store
Browse files Browse the repository at this point in the history
  • Loading branch information
Himenon committed Apr 25, 2021
1 parent 0674443 commit e3475b6
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 143 deletions.
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/Extractor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CodeGenerator, OpenApi } from "../../types";
import * as ConverterContext from "./ConverterContext";
import { Store } from "./store";
import type { Store } from "./store";

const extractPickedParameter = (parameter: OpenApi.Parameter): CodeGenerator.PickedParameter => {
return {
Expand Down Expand Up @@ -56,7 +56,7 @@ const hasQueryParameters = (parameters?: OpenApi.Parameter[]): boolean => {
};

export const generateCodeGeneratorParamsArray = (
store: Store.Type,
store: Store,
converterContext: ConverterContext.Types,
allowOperationIds: string[] | undefined,
): CodeGenerator.Params[] => {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as TypeNodeContext from "./TypeNodeContext";
export class Parser {
private currentPoint: string;
private convertContext: ConvertContext.Types;
private store: Store.Type;
private store: Store;
private factory: TypeScriptCodeGenerator.Factory.Type;
constructor(
private entryPoint: string,
Expand All @@ -26,7 +26,7 @@ export class Parser {
this.currentPoint = entryPoint;
this.convertContext = ConvertContext.create();
this.factory = TypeScriptCodeGenerator.Factory.create();
this.store = Store.create(this.factory, noReferenceOpenApiSchema);
this.store = new Store(this.factory, noReferenceOpenApiSchema);
this.initialize();
}

Expand Down
6 changes: 3 additions & 3 deletions src/internal/OpenApiTools/TypeNodeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ts from "typescript";
import { DevelopmentError } from "../Exception";
import * as TypeScriptCodeGenerator from "../TsGenerator";
import * as ConverterContext from "./ConverterContext";
import { Store } from "./store";
import type { Store } from "./store";
import * as ToTypeNode from "./toTypeNode";

export interface ReferencePathSet {
Expand All @@ -25,7 +25,7 @@ const generatePath = (entryPoint: string, currentPoint: string, referencePath: s
};
};

const calculateReferencePath = (store: Store.Type, base: string, pathArray: string[]): ToTypeNode.ResolveReferencePath => {
const calculateReferencePath = (store: Store, base: string, pathArray: string[]): ToTypeNode.ResolveReferencePath => {
let names: string[] = [];
let unresolvedPaths: string[] = [];
pathArray.reduce((previous, lastPath, index) => {
Expand Down Expand Up @@ -75,7 +75,7 @@ const calculateReferencePath = (store: Store.Type, base: string, pathArray: stri

export const create = (
entryPoint: string,
store: Store.Type,
store: Store,
factory: TypeScriptCodeGenerator.Factory.Type,
converterContext: ConverterContext.Types,
): ToTypeNode.Context => {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/components/Headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as Header from "./Header";
import * as Reference from "./Reference";
Expand All @@ -13,7 +13,7 @@ import * as Schema from "./Schema";
export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
headers: Record<string, OpenApi.Header | OpenApi.Reference>,
context: ToTypeNode.Context,
Expand Down
6 changes: 3 additions & 3 deletions src/internal/OpenApiTools/components/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as ExternalDocumentation from "./ExternalDocumentation";
import * as Parameter from "./Parameter";
Expand All @@ -35,7 +35,7 @@ const generateComment = (operation: OpenApi.Operation): string => {
export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parentPath: string,
name: string,
Expand Down Expand Up @@ -131,7 +131,7 @@ export const generateNamespace = (
export const generateStatements = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
requestUri: string,
httpMethod: string, // PUT POST PATCH
Expand Down
10 changes: 5 additions & 5 deletions src/internal/OpenApiTools/components/Parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { OpenApi } from "../../../types";
import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as Reference from "./Reference";

Expand Down Expand Up @@ -39,7 +39,7 @@ export const generateTypeAlias = (
export const generatePropertySignature = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parameter: OpenApi.Parameter | OpenApi.Reference,
context: ToTypeNode.Context,
Expand Down Expand Up @@ -86,7 +86,7 @@ export const generatePropertySignature = (
export const generatePropertySignatures = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parameters: (OpenApi.Parameter | OpenApi.Reference)[],
context: ToTypeNode.Context,
Expand All @@ -100,7 +100,7 @@ export const generatePropertySignatures = (
export const generateInterface = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
name: string,
parameters: [OpenApi.Parameter | OpenApi.Reference],
Expand All @@ -120,7 +120,7 @@ export const generateInterface = (
export const generateAliasInterface = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
name: string,
parameters: (OpenApi.Parameter | OpenApi.Reference)[],
Expand Down
6 changes: 3 additions & 3 deletions src/internal/OpenApiTools/components/Parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as Paramter from "./Parameter";
import * as Reference from "./Reference";
Expand All @@ -13,7 +13,7 @@ import * as Schema from "./Schema";
export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parameters: Record<string, OpenApi.Parameter | OpenApi.Reference>,
context: ToTypeNode.Context,
Expand Down Expand Up @@ -71,7 +71,7 @@ export const generateNamespace = (
export const generateNamespaceWithList = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parameters: (OpenApi.Parameter | OpenApi.Reference)[],
context: ToTypeNode.Context,
Expand Down
6 changes: 3 additions & 3 deletions src/internal/OpenApiTools/components/PathItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ts from "typescript";
import type { OpenApi } from "../../../types";
import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as Operation from "./Operation";
import * as Parameters from "./Parameters";
Expand All @@ -12,7 +12,7 @@ import * as Servers from "./Servers";
export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parentPath: string,
name: string,
Expand Down Expand Up @@ -60,7 +60,7 @@ export const generateNamespace = (
export const generateStatements = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
requestUri: string,
pathItem: OpenApi.PathItem,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/components/PathItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as PathItem from "./PathItem";
import * as Reference from "./Reference";
Expand All @@ -13,7 +13,7 @@ import * as Reference from "./Reference";
export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
pathItems: Record<string, OpenApi.PathItem | OpenApi.Reference>,
context: ToTypeNode.Context,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/components/RequestBodies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as Reference from "./Reference";
import * as RequestBody from "./RequestBody";

export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
requestBodies: Record<string, OpenApi.RequestBody | OpenApi.Reference>,
context: ToTypeNode.Context,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/components/RequestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ts from "typescript";
import type { OpenApi } from "../../../types";
import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as MediaType from "./MediaType";

Expand Down Expand Up @@ -34,7 +34,7 @@ export const generateInterface = (
export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parentName: string,
name: string,
Expand Down
6 changes: 3 additions & 3 deletions src/internal/OpenApiTools/components/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { OpenApi } from "../../../types";
import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as Header from "./Header";
import * as MediaType from "./MediaType";

export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parentPath: string,
name: string,
Expand Down Expand Up @@ -63,7 +63,7 @@ export const generateNamespace = (
export const generateReferenceNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parentPath: string,
nameWithStatusCode: string,
Expand Down
8 changes: 4 additions & 4 deletions src/internal/OpenApiTools/components/Responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Factory } from "../../TsGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as MediaType from "./MediaType";
import * as Reference from "./Reference";
Expand All @@ -17,7 +17,7 @@ import * as Response from "./Response";
export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
responses: Record<string, OpenApi.Response | OpenApi.Reference>,
context: ToTypeNode.Context,
Expand Down Expand Up @@ -57,7 +57,7 @@ export const generateNamespace = (
export const generateNamespaceWithStatusCode = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
parentPath: string,
responses: OpenApi.Responses,
Expand Down Expand Up @@ -122,7 +122,7 @@ export const generateNamespaceWithStatusCode = (
export const generateInterfacesWithStatusCode = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
operationId: string,
responses: OpenApi.Responses,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/components/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FeatureDevelopmentError } from "../../Exception";
import { Factory } from "../../TsGenerator";
import * as ConvertContext from "../ConverterContext";
import * as Guard from "../Guard";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import type { ArraySchema, ObjectSchema, PrimitiveSchema } from "../types";
import * as ExternalDocumentation from "./ExternalDocumentation";
Expand Down Expand Up @@ -159,7 +159,7 @@ export const generateMultiTypeAlias = (
export const addSchema = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
targetPoint: string,
declarationName: string,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/components/Schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as InferredType from "../InferredType";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
import * as Reference from "./Reference";
import * as Schema from "./Schema";
Expand All @@ -29,7 +29,7 @@ const createNullableTypeNode = (factory: Factory.Type, schema: OpenApi.Schema) =
export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
schemas: Record<string, OpenApi.Schema | OpenApi.Reference>,
context: ToTypeNode.Context,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/components/SecuritySchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { UndefinedComponent } from "../../Exception";
import { Factory } from "../../TsGenerator";
import * as Guard from "../Guard";
import * as Name from "../Name";
import { Store } from "../store";
import type { Store } from "../store";
import * as Reference from "./Reference";
import * as SecuritySchema from "./SecuritySchema";

export const generateNamespace = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
requestBodies: Record<string, OpenApi.SecuritySchema | OpenApi.Reference>,
): void => {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/OpenApiTools/paths/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import * as PathItem from "../components/PathItem";
import * as Reference from "../components/Reference";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import { Store } from "../store";
import type { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";

export const generateStatements = (
entryPoint: string,
currentPoint: string,
store: Store.Type,
store: Store,
factory: Factory.Type,
paths: OpenApi.Paths,
context: ToTypeNode.Context,
Expand Down
Loading

0 comments on commit e3475b6

Please sign in to comment.