Skip to content

Commit

Permalink
refactor: remove v3 directory (#29)
Browse files Browse the repository at this point in the history
* refactor: remove v3 directory
* fix: package json path
  • Loading branch information
Himenon authored Apr 4, 2021
1 parent 72abfaa commit 4d1eee4
Show file tree
Hide file tree
Showing 60 changed files with 231 additions and 233 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Converter/v3/Comment.ts → src/Converter/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EOL } from "os";
import { OpenApi } from "./types";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require("../../../package.json");
const pkg = require("../../package.json");

export const generateLeading = (schema: OpenApi.Document): string => {
const messages: string[] = [];
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as Path from "path";

import ts from "typescript";

import * as TypeScriptCodeGenerator from "../../CodeGenerator";
import { DevelopmentError } from "../../Exception";
import * as TypeScriptCodeGenerator from "../CodeGenerator";
import { DevelopmentError } from "../Exception";
import * as ConverterContext from "./ConverterContext";
import { Store } from "./store";
import * as ToTypeNode from "./toTypeNode";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as ToTypeNode from "../toTypeNode";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Factory } from "../../../CodeGenerator";
import { UndefinedComponent } from "../../../Exception";
import { Factory } from "../../CodeGenerator";
import { UndefinedComponent } from "../../Exception";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as ConverterContext from "../ConverterContext";
import * as ToTypeNode from "../toTypeNode";
import { OpenApi } from "../types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path";

import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import { Store } from "../store";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Factory } from "../../../CodeGenerator";
import { UnSupportError } from "../../../Exception";
import { Factory } from "../../CodeGenerator";
import { UnSupportError } from "../../Exception";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as ConverterContext from "../ConverterContext";
import { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Factory } from "../../../CodeGenerator";
import { FeatureDevelopmentError, UnSupportError } from "../../../Exception";
import { Factory } from "../../CodeGenerator";
import { FeatureDevelopmentError, UnSupportError } from "../../Exception";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as path from "path";

import { DevelopmentError, FeatureDevelopmentError, NotFoundFileError } from "../../../Exception";
import { fileSystem } from "../../../FileSystem";
import * as Logger from "../../../Logger";
import { DevelopmentError, FeatureDevelopmentError, NotFoundFileError } from "../../Exception";
import { fileSystem } from "../../FileSystem";
import * as Logger from "../../Logger";
import * as Guard from "../Guard";
import { Def } from "../store";
import { OpenApi } from "../types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "path";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as ConverterContext from "../ConverterContext";
import { Store } from "../store";
import * as ToTypeNode from "../toTypeNode";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "path";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as ConverterContext from "../ConverterContext";
import * as Name from "../Name";
import { Store } from "../store";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as path from "path";

import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { UndefinedComponent } from "../../../Exception";
import { Factory } from "../../CodeGenerator";
import { UndefinedComponent } from "../../Exception";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as Name from "../Name";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { FeatureDevelopmentError } from "../../../Exception";
import { Factory } from "../../CodeGenerator";
import { FeatureDevelopmentError } from "../../Exception";
import * as ConvertContext from "../ConverterContext";
import * as Guard from "../Guard";
import { Store } from "../store";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Factory } from "../../../CodeGenerator";
import { UnSupportError } from "../../../Exception";
import { Factory } from "../../CodeGenerator";
import { UnSupportError } from "../../Exception";
import * as ConverterContext from "../ConverterContext";
import * as Guard from "../Guard";
import * as InferredType from "../InferredType";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import { OpenApi } from "../types";

export const generatePropertySignatures = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Factory } from "../../../CodeGenerator";
import { UndefinedComponent } from "../../../Exception";
import { Factory } from "../../CodeGenerator";
import { UndefinedComponent } from "../../Exception";
import * as Guard from "../Guard";
import * as Name from "../Name";
import { Store } from "../store";
Expand Down
File renamed without changes.
File renamed without changes.
127 changes: 126 additions & 1 deletion src/Converter/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,126 @@
export * as v3 from "./v3";
import ts from "typescript";

import * as TypeScriptCodeGenerator from "../CodeGenerator";
import * as CodeGenerator from "./CodeGenerator";
import * as Comment from "./Comment";
import * as Headers from "./components/Headers";
import * as Parameters from "./components/Parameters";
// import * as PathItems from "./components/PathItems";
import * as RequestBodies from "./components/RequestBodies";
import * as Responses from "./components/Responses";
import * as Schemas from "./components/Schemas";
import * as ConvertContext from "./ConverterContext";
import * as Name from "./Name";
import * as Paths from "./paths";
import { Store } from "./store";
import * as TypeNodeContext from "./TypeNodeContext";
import { CodeGeneratorParams, OpenApi, PickedParameter } from "./types";

export { OpenApi, CodeGenerator, CodeGeneratorParams, PickedParameter, Name };

export interface Type {
generateLeadingComment: () => string;
createFunction: TypeScriptCodeGenerator.CreateFunction;
codeGeneratorOption: CodeGenerator.Option;
}

export interface Option {
/**
* It is possible to rewrite the implementation after the type declaration.
*/
rewriteCodeAfterTypeDeclaration: CodeGenerator.RewriteCodeAfterTypeDeclaration;
/**
*
*/
codeGeneratorOption: CodeGenerator.Option;
/**
* List of operationId to be used
*/
allowOperationIds?: string[];
}

export const create = (entryPoint: string, rootSchema: OpenApi.Document, noReferenceOpenApiSchema: OpenApi.Document, option: Option): Type => {
const currentPoint = entryPoint;
const converterContext = ConvertContext.create();

const createFunction = (context: ts.TransformationContext): ts.Statement[] => {
const factory = TypeScriptCodeGenerator.Factory.create(context);
const store = Store.create(factory, noReferenceOpenApiSchema);
const toTypeNodeContext = TypeNodeContext.create(entryPoint, store, factory, converterContext);

if (rootSchema.components) {
if (rootSchema.components.schemas) {
Schemas.generateNamespace(entryPoint, currentPoint, store, factory, rootSchema.components.schemas, toTypeNodeContext, converterContext);
}
if (rootSchema.components.headers) {
Headers.generateNamespace(entryPoint, currentPoint, store, factory, rootSchema.components.headers, toTypeNodeContext, converterContext);
}
if (rootSchema.components.responses) {
Responses.generateNamespace(
entryPoint,
currentPoint,
store,
factory,
rootSchema.components.responses,
toTypeNodeContext,
converterContext,
);
}
if (rootSchema.components.parameters) {
Parameters.generateNamespace(
entryPoint,
currentPoint,
store,
factory,
rootSchema.components.parameters,
toTypeNodeContext,
converterContext,
);
}
if (rootSchema.components.requestBodies) {
RequestBodies.generateNamespace(
entryPoint,
currentPoint,
store,
factory,
rootSchema.components.requestBodies,
toTypeNodeContext,
converterContext,
);
}
// if (rootSchema.components.securitySchemes) {
// SecuritySchemas.generateNamespace(entryPoint, currentPoint, store, factory, rootSchema.components.securitySchemes);
// }
// if (rootSchema.components.pathItems) {
// PathItems.generateNamespace(entryPoint, currentPoint, store, factory, rootSchema.components.pathItems, toTypeNodeContext);
// }
// TODO Feature Development
// if (rootSchema.components.links) {
// statements.push(Links.generateNamespace(entryPoint, currentPoint, factory, rootSchema.components.links));
// }

// TODO Feature Development
// if (rootSchema.components.callbacks) {
// statements.push(Callbacks.generateNamespace(entryPoint, currentPoint, factory, rootSchema.components.callbacks));
// }
}
if (rootSchema.paths) {
Paths.generateStatements(entryPoint, currentPoint, store, factory, rootSchema.paths, toTypeNodeContext, converterContext);
CodeGenerator.generateApiClientCode(
store,
context,
converterContext,
option.rewriteCodeAfterTypeDeclaration,
option.allowOperationIds,
option.codeGeneratorOption,
);
}
return store.getRootStatements();
};

return {
createFunction,
generateLeadingComment: () => Comment.generateLeading(rootSchema),
codeGeneratorOption: option.codeGeneratorOption,
};
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { Factory } from "../../CodeGenerator";
import * as PathItem from "../components/PathItem";
import * as Reference from "../components/Reference";
import * as ConverterContext from "../ConverterContext";
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EOL } from "os";

import { DevelopmentError } from "../../../Exception";
import { DevelopmentError } from "../../Exception";
import { OpenApi } from "../types";

const httpMethodList = ["get", "put", "post", "delete", "options", "head", "patch", "trace"] as const;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Tree } from "@himenon/path-oriented-data-structure";
import Dot from "dot-prop";
import ts from "typescript";

import { Factory } from "../../../CodeGenerator";
import { UnSupportError } from "../../../Exception";
import { Factory } from "../../CodeGenerator";
import { UnSupportError } from "../../Exception";
import { OpenApi } from "../types";
import * as Def from "./Definition";
import * as Operation from "./Operation";
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ts from "typescript";

import { Factory } from "../../CodeGenerator";
import { UnsetTypeError } from "../../Exception";
import { UnSupportError } from "../../Exception";
import * as Logger from "../../Logger";
import { Factory } from "../CodeGenerator";
import { UnsetTypeError } from "../Exception";
import { UnSupportError } from "../Exception";
import * as Logger from "../Logger";
import * as Reference from "./components/Reference";
import * as ConverterContext from "./ConverterContext";
import * as Guard from "./Guard";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4d1eee4

Please sign in to comment.