From 17c38c0b1a3f47d4a638f1bbec33326b13dbbac7 Mon Sep 17 00:00:00 2001 From: Victor Bury Date: Tue, 31 Mar 2020 09:14:15 +0200 Subject: [PATCH] fix(writers): line return --- README.md | 46 +++++++++++++-------------- examples/orval.config.js | 34 ++++++++++---------- examples/transformer-add-version.js | 2 +- examples/transformer-response-type.js | 2 +- rollup.config.js | 12 +++---- src/core/generators/imports.ts | 4 +-- src/core/writers/singleMode.ts | 10 +++--- src/core/writers/splitMode.ts | 12 +++---- src/core/writers/tagsMode.ts | 4 +-- 9 files changed, 61 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 6eed5f315..a9fdd2e2a 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ The function specified in `--transformer` is pure: it imports your `--file`, tra * @param {OpenAPIObject} schema * @return {OpenAPIObject} */ -module.exports = inputSchema => ({ +module.exports = (inputSchema) => ({ ...inputSchema, // Place your augmentations here paths: Object.entries(schema.paths).reduce( @@ -113,14 +113,14 @@ module.exports = inputSchema => ({ (pathItemMem, [verb, operation]) => ({ ...pathItemMem, [verb]: { - ...fixOperationId(path, verb, operation) - } + ...fixOperationId(path, verb, operation), + }, }), - {} - ) + {}, + ), }), - {} - ) + {}, + ), }); ``` @@ -176,18 +176,18 @@ interface OutputOptions = { module.exports = { 'petstore-file': { input: 'examples/petstore.yaml', - output: 'examples/petstoreFromFileSpecWithConfig.ts' + output: 'examples/petstoreFromFileSpecWithConfig.ts', }, 'petstore-file-transfomer': { output: { target: 'examples/petstoreFromFileSpecWithTransformer.ts', schemas: 'examples/model', mode: 'split', - mock: true + mock: true, }, input: { target: 'examples/petstore.yaml', - transformer: 'examples/transformer-add-version.js' + transformer: 'examples/transformer-add-version.js', }, override: { // contains operationId of your spec with override options @@ -199,30 +199,30 @@ module.exports = { // override mock properties properties: () => { return { - id: faker.random.number({min: 1, max: 9}) + id: faker.random.number({ min: 1, max: 9 }), }; - } - } + }, + }, }, showPetById: { mock: { // override mock for this api call data: () => ({ - id: faker.random.number({min: 1, max: 99}), + id: faker.random.number({ min: 1, max: 99 }), name: faker.name.firstName(), - tag: faker.helpers.randomize([faker.random.word(), undefined]) - }) - } - } + tag: faker.helpers.randomize([faker.random.word(), undefined]), + }), + }, + }, }, mock: { // override mock properties for all api calls properties: { - '/tag|name/': 'jon' - } - } - } - } + '/tag|name/': 'jon', + }, + }, + }, + }, }; ``` diff --git a/examples/orval.config.js b/examples/orval.config.js index 94f3e8d29..f529e0c57 100644 --- a/examples/orval.config.js +++ b/examples/orval.config.js @@ -6,7 +6,7 @@ const faker = require('faker'); module.exports = { 'petstore-file': { input: 'examples/petstore.yaml', - output: 'examples/petstoreFromFileSpecWithConfig.ts' + output: 'examples/petstoreFromFileSpecWithConfig.ts', }, 'petstore-file-transfomer': { output: { @@ -21,33 +21,33 @@ module.exports = { mock: { properties: () => { return { - id: faker.random.number({min: 1, max: 9}) + id: faker.random.number({ min: 1, max: 9 }), }; - } - } + }, + }, }, showPetById: { mock: { data: () => ({ - id: faker.random.number({min: 1, max: 99}), + id: faker.random.number({ min: 1, max: 99 }), name: faker.name.firstName(), - tag: faker.helpers.randomize([faker.random.word(), undefined]) - }) - } - } + tag: faker.helpers.randomize([faker.random.word(), undefined]), + }), + }, + }, }, mock: { properties: { - '/tag|name/': 'jon' - } - } - } + '/tag|name/': 'jon', + }, + }, + }, }, input: { target: 'examples/petstore.yaml', override: { - transformer: 'examples/transformer-add-version.js' - } - } - } + transformer: 'examples/transformer-add-version.js', + }, + }, + }, }; diff --git a/examples/transformer-add-version.js b/examples/transformer-add-version.js index 2985eb6e9..d7c6c1692 100644 --- a/examples/transformer-add-version.js +++ b/examples/transformer-add-version.js @@ -4,7 +4,7 @@ * @param {OpenAPIObject} schema * @return {OpenAPIObject} */ -module.exports = inputSchema => ({ +module.exports = (inputSchema) => ({ ...inputSchema, paths: Object.entries(inputSchema.paths).reduce( (acc, [path, pathItem]) => ({ diff --git a/examples/transformer-response-type.js b/examples/transformer-response-type.js index e0fb673f3..3587870bf 100644 --- a/examples/transformer-response-type.js +++ b/examples/transformer-response-type.js @@ -1 +1 @@ -module.exports = (url, {params}) => [url, {params, responseType: 'json'}]; +module.exports = (url, { params }) => [url, { params, responseType: 'json' }]; diff --git a/rollup.config.js b/rollup.config.js index 8941f35e0..6e8a016eb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,15 +1,15 @@ -const { readdirSync } = require("fs"); +const { readdirSync } = require('fs'); /** * Rollup configuration to build correctly our scripts (nodejs scripts need to be cjs) */ -module.exports = readdirSync("lib/bin") - .filter(file => file.endsWith(".js")) - .map(file => ({ +module.exports = readdirSync('lib/bin') + .filter((file) => file.endsWith('.js')) + .map((file) => ({ input: `lib/bin/${file}`, output: { file: `lib/bin/${file}`, - format: "cjs", - banner: "#!/usr/bin/env node", + format: 'cjs', + banner: '#!/usr/bin/env node', }, })); diff --git a/src/core/generators/imports.ts b/src/core/generators/imports.ts index 3c279c3c7..92c23f8ff 100644 --- a/src/core/generators/imports.ts +++ b/src/core/generators/imports.ts @@ -6,9 +6,7 @@ export const generateImports = ( pathOnly: boolean = false, ) => { if (pathOnly) { - return `import {\n ${imports - .sort() - .join(',\n ')}\n} from \'${path}\';\n\n`; + return `import {\n ${imports.sort().join(',\n ')}\n} from \'${path}\';\n`; } return imports .sort() diff --git a/src/core/writers/singleMode.ts b/src/core/writers/singleMode.ts index 063c0f772..055b318bb 100644 --- a/src/core/writers/singleMode.ts +++ b/src/core/writers/singleMode.ts @@ -34,9 +34,9 @@ export const writeSingleMode = ({ let data = getFilesHeader(info); data += - "import { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'\n"; + "import { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';\n"; data += - isObject(output) && output.mock ? "import faker from 'faker'\n\n" : '\n'; + isObject(output) && output.mock ? "import faker from 'faker';\n" : '\n'; if (isObject(output) && output.schemas) { data += generateImports(imports, resolvePath(path, output.schemas), true); @@ -44,10 +44,8 @@ export const writeSingleMode = ({ data += generateModelsInline(schemas); } - data += '\n'; - data += definition; - data += '\n\n'; - data += implementation; + data += `\n${definition}`; + data += `\n\n${implementation}`; if (isObject(output) && output.mock) { data += '\n\n'; diff --git a/src/core/writers/splitMode.ts b/src/core/writers/splitMode.ts index b5e1edf7f..43cdb6828 100644 --- a/src/core/writers/splitMode.ts +++ b/src/core/writers/splitMode.ts @@ -38,7 +38,7 @@ export const writeSplitMode = ({ let implementationData = header; let mockData = header; - definitionData += "import { AxiosPromise } from 'axios'\n"; + definitionData += "import { AxiosPromise } from 'axios';\n"; const definitionPath = './' + filename + '.definition'; const definitionImport = generateImports( @@ -47,8 +47,8 @@ export const writeSplitMode = ({ true, ); - implementationData += `import { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'\n${definitionImport}`; - mockData += `import { AxiosPromise } from 'axios'\nimport faker from 'faker'\n${definitionImport}`; + implementationData += `import { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';\n${definitionImport}`; + mockData += `import { AxiosPromise } from 'axios';\nimport faker from 'faker';\n${definitionImport}`; if (output.schemas) { const schemasPath = resolvePath(path, output.schemas); @@ -67,9 +67,9 @@ export const writeSplitMode = ({ mockData += generateImports(imports, schemasPath, true); } - definitionData += definition; - implementationData += implementation; - mockData += implementationMocks; + definitionData += `\n${definition}`; + implementationData += `\n${implementation}`; + mockData += `\n${implementationMocks}`; if (path) { writeFileSync(join(dirname, definitionPath + extension), definitionData); diff --git a/src/core/writers/tagsMode.ts b/src/core/writers/tagsMode.ts index af36da1d1..9d9d1afbf 100644 --- a/src/core/writers/tagsMode.ts +++ b/src/core/writers/tagsMode.ts @@ -109,9 +109,9 @@ export const writeTagsMode = ({ const header = getFilesHeader(info); let data = header; data += - "import { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'\n"; + "import { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';\n"; data += - isObject(output) && output.mock ? "import faker from 'faker'\n\n" : '\n'; + isObject(output) && output.mock ? "import faker from 'faker';\n" : '\n'; if (isObject(output) && output.schemas) { data += generateImports(imports, resolvePath(path, output.schemas), true);