Skip to content

Commit

Permalink
fix(writers): line return
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed Mar 31, 2020
1 parent 3ffa282 commit 17c38c0
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 65 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -113,14 +113,14 @@ module.exports = inputSchema => ({
(pathItemMem, [verb, operation]) => ({
...pathItemMem,
[verb]: {
...fixOperationId(path, verb, operation)
}
...fixOperationId(path, verb, operation),
},
}),
{}
)
{},
),
}),
{}
)
{},
),
});
```

Expand Down Expand Up @@ -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
Expand All @@ -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',
},
},
},
},
};
```

Expand Down
34 changes: 17 additions & 17 deletions examples/orval.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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',
},
},
},
};
2 changes: 1 addition & 1 deletion examples/transformer-add-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => ({
Expand Down
2 changes: 1 addition & 1 deletion examples/transformer-response-type.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = (url, {params}) => [url, {params, responseType: 'json'}];
module.exports = (url, { params }) => [url, { params, responseType: 'json' }];
12 changes: 6 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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',
},
}));
4 changes: 1 addition & 3 deletions src/core/generators/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 4 additions & 6 deletions src/core/writers/singleMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,18 @@ 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);
} else {
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';
Expand Down
12 changes: 6 additions & 6 deletions src/core/writers/splitMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/core/writers/tagsMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 17c38c0

Please sign in to comment.