Skip to content

Commit

Permalink
refactor: organize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Aug 4, 2023
1 parent ef1d89d commit 1a8a32b
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 42 deletions.
4 changes: 2 additions & 2 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import { ConfigFile } from '../src/getConfig';
import build from '../src';
import path from 'path';
import build from '../src';
import type { ConfigFile } from '../src/getConfig';

function readDirRecursive(dirPath: string): string[] {
return fs
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"root": true,
"rules": {
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/ban-ts-comment": "off",
Expand Down Expand Up @@ -105,6 +106,7 @@
"jest": "^29.6.2",
"minimist": "^1.2.8",
"prettier": "^2.8.8",
"prettier-plugin-organize-imports": "^3.2.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
Expand Down
4 changes: 2 additions & 2 deletions src/buildTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import SwaggerParser from '@apidevtools/swagger-parser';
import { OpenAPI, OpenAPIV3 } from 'openapi-types';
import type { OpenAPI, OpenAPIV3 } from 'openapi-types';
import buildV3 from './buildV3';
import type { Config } from './getConfig';
import resolveExternalRefs from './resolveExternalRefs';
import { Config } from './getConfig';

const isV3 = (openapi: OpenAPI.Document): openapi is OpenAPIV3.Document => 'openapi' in openapi;

Expand Down
19 changes: 7 additions & 12 deletions src/buildV3.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { OpenAPIV3 } from 'openapi-types';
import type { OpenAPIV3 } from 'openapi-types';
import {
isRefObject,
$ref2Type,
BINARY_TYPE,
getPropertyName,
isRefObject,
schema2value,
BINARY_TYPE,
} from './builderUtils/converters';
import {
props2String,
Prop,
PropValue,
value2String,
description2Doc,
} from './builderUtils/props2String';
import { resolveParamsRef, resolveResRef, resolveReqRef } from './builderUtils/resolvers';
import getDirName from './builderUtils/getDirName';
import schemas2Props from './builderUtils/schemas2Props';
import parameters2Props from './builderUtils/parameters2Props';
import type { Prop, PropValue } from './builderUtils/props2String';
import { description2Doc, props2String, value2String } from './builderUtils/props2String';
import requestBodies2Props from './builderUtils/requestBodies2Props';
import { resolveParamsRef, resolveReqRef, resolveResRef } from './builderUtils/resolvers';
import responses2Props from './builderUtils/responses2Props';
import schemas2Props from './builderUtils/schemas2Props';

const methodNames = ['get', 'post', 'put', 'delete', 'head', 'options', 'patch'] as const;

Expand Down
4 changes: 2 additions & 2 deletions src/builderUtils/converters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OpenAPIV3 } from 'openapi-types';
import { Prop, PropValue } from './props2String';
import type { OpenAPIV3 } from 'openapi-types';
import type { Prop, PropValue } from './props2String';

export const defKey2defName = (key: string) =>
`${key[0].replace(/^([^a-zA-Z$_])$/, '$$$1').toUpperCase()}${key
Expand Down
8 changes: 4 additions & 4 deletions src/builderUtils/parameters2Props.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { OpenAPIV3 } from 'openapi-types';
import type { OpenAPIV3 } from 'openapi-types';
import {
isRefObject,
defKey2defName,
$ref2Type,
defKey2defName,
getPropertyName,
isRefObject,
schema2value,
} from './converters';
import { Prop } from './props2String';
import type { Prop } from './props2String';
import { resolveParamsRef } from './resolvers';

export type Parameter = { name: string; prop: string | Prop };
Expand Down
6 changes: 3 additions & 3 deletions src/builderUtils/requestBodies2Props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenAPIV3 } from 'openapi-types';
import { isRefObject, defKey2defName, $ref2Type, schema2value } from './converters';
import { PropValue } from './props2String';
import type { OpenAPIV3 } from 'openapi-types';
import { $ref2Type, defKey2defName, isRefObject, schema2value } from './converters';
import type { PropValue } from './props2String';

export type RequestBody = { name: string; value: string | PropValue };

Expand Down
4 changes: 2 additions & 2 deletions src/builderUtils/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OpenAPIV3 } from 'openapi-types';
import { isRefObject, $ref2TypeName } from './converters';
import type { OpenAPIV3 } from 'openapi-types';
import { $ref2TypeName, isRefObject } from './converters';

export const resolveParamsRef = (
openapi: OpenAPIV3.Document,
Expand Down
6 changes: 3 additions & 3 deletions src/builderUtils/responses2Props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenAPIV3 } from 'openapi-types';
import { isRefObject, defKey2defName, $ref2Type, schema2value } from './converters';
import { PropValue } from './props2String';
import type { OpenAPIV3 } from 'openapi-types';
import { $ref2Type, defKey2defName, isRefObject, schema2value } from './converters';
import type { PropValue } from './props2String';

export type Response = { name: string; value: string | PropValue };

Expand Down
6 changes: 3 additions & 3 deletions src/builderUtils/schemas2Props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenAPIV3 } from 'openapi-types';
import { isRefObject, defKey2defName, schema2value } from './converters';
import { PropValue } from './props2String';
import type { OpenAPIV3 } from 'openapi-types';
import { defKey2defName, isRefObject, schema2value } from './converters';
import type { PropValue } from './props2String';
import { resolveSchemasRef } from './resolvers';

export type Schema = { name: string; value: PropValue };
Expand Down
5 changes: 3 additions & 2 deletions src/getConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpenAPI } from 'openapi-types';
import { AspidaConfig, getConfigs } from 'aspida/dist/cjs/commands';
import type { AspidaConfig } from 'aspida/dist/cjs/commands';
import { getConfigs } from 'aspida/dist/cjs/commands';
import type { OpenAPI } from 'openapi-types';

export type Config = Pick<AspidaConfig, 'outputEachDir' | 'outputMode' | 'trailingSlash'> & {
input: string | OpenAPI.Document;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs';
import fse from 'fs-extra';
import getConfig from './getConfig';
import buildTemplate from './buildTemplate';
import writeRouteFile from './writeRouteFile';
import getConfig from './getConfig';
import outputFilePath from './outputFilePath';
import writeRouteFile from './writeRouteFile';

/**
* @param {string} outputdir 出力するディレクトリー
Expand Down
8 changes: 4 additions & 4 deletions src/resolveExternalRefs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import https from 'https';
import http from 'http';
import fs from 'fs';
import path from 'path';
import http from 'http';
import https from 'https';
import yaml from 'js-yaml';
import { OpenAPIV3 } from 'openapi-types';
import type { OpenAPIV3 } from 'openapi-types';
import path from 'path';

const getText = (url: string) =>
new Promise<string>(resolve => {
Expand Down
3 changes: 2 additions & 1 deletion src/writeRouteFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { AspidaConfig } from 'aspida/dist/cjs/commands';
import { build } from 'aspida/dist/cjs/commands';
import fs from 'fs';
import { build, AspidaConfig } from 'aspida/dist/cjs/commands';

export default ({
config,
Expand Down

0 comments on commit 1a8a32b

Please sign in to comment.