Skip to content

Commit a82becf

Browse files
authored
Merge of #9988
2 parents 355dba1 + 8941d00 commit a82becf

File tree

126 files changed

+2734
-1377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+2734
-1377
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @type {import('eslint').Linter.Config}
3+
*/
14
module.exports = {
25
root: true, // https://eslint.org/docs/user-guide/configuring/configuration-files#cascading-and-hierarchy
36
extends: [
@@ -7,6 +10,9 @@ module.exports = {
710
plugins: [
811
'regex',
912
],
13+
ignorePatterns: [
14+
'node_modules/**',
15+
],
1016
rules: {
1117
'import/prefer-default-export': 'off',
1218
'import/order': [
@@ -73,7 +79,7 @@ module.exports = {
7379
overrides: [
7480
{
7581
// enable the rule specifically for TypeScript files
76-
files: ['*.ts', '*.tsx'],
82+
files: ['*.ts', '*.mts', '*.tsx'],
7783
rules: {
7884
'@typescript-eslint/explicit-module-boundary-types': ['error'],
7985
},

apps/app/.eslintignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

apps/app/.eslintrc.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
/**
2+
* @type {import('eslint').Linter.Config}
3+
*/
14
module.exports = {
25
extends: [
36
'next/core-web-vitals',
47
'weseek/react',
58
],
69
plugins: [
710
],
11+
ignorePatterns: [
12+
'dist/**',
13+
'**/dist/**',
14+
'transpiled/**',
15+
'public/**',
16+
'src/linter-checker/**',
17+
'tmp/**',
18+
'next-env.d.ts',
19+
],
820
settings: {
921
// resolve path aliases by eslint-import-resolver-typescript
1022
'import/resolver': {
@@ -25,7 +37,7 @@ module.exports = {
2537
overrides: [
2638
{
2739
// enable the rule specifically for JavaScript files
28-
files: ['*.js', '*.jsx'],
40+
files: ['*.js', '*.mjs', '*.jsx'],
2941
rules: {
3042
// set 'warn' temporarily -- 2023.08.14 Yuki Takei
3143
'react/prop-types': 'warn',
@@ -35,7 +47,7 @@ module.exports = {
3547
},
3648
{
3749
// enable the rule specifically for TypeScript files
38-
files: ['*.ts', '*.tsx'],
50+
files: ['*.ts', '*.mts', '*.tsx'],
3951
rules: {
4052
'no-unused-vars': 'off',
4153
// set 'warn' temporarily -- 2023.08.14 Yuki Takei

apps/app/bin/swagger-jsdoc/definition-apiv1.js renamed to apps/app/bin/openapi/definition-apiv1.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ module.exports = {
77
version: pkg.version,
88
},
99
servers: [
10+
{
11+
url: '{server}/_api',
12+
variables: {
13+
server: {
14+
default: 'https://demo.growi.org',
15+
description: 'The base URL for the GROWI API except for the version path (/_api). This can be set to your GROWI instance URL.',
16+
},
17+
},
18+
},
1019
{
1120
url: 'https://demo.growi.org/_api',
1221
},

apps/app/bin/swagger-jsdoc/definition-apiv3.js renamed to apps/app/bin/openapi/definition-apiv3.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ module.exports = {
77
version: pkg.version,
88
},
99
servers: [
10+
{
11+
url: '{server}/_api/v3',
12+
variables: {
13+
server: {
14+
default: 'https://demo.growi.org',
15+
description: 'The base URL for the GROWI API except for the version path (/_api/v3). This can be set to your GROWI instance URL.',
16+
},
17+
},
18+
},
1019
{
1120
url: 'https://demo.growi.org/_api/v3',
1221
},
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { writeFileSync } from 'fs';
2+
3+
import {
4+
beforeEach, describe, expect, it, vi,
5+
} from 'vitest';
6+
7+
import { generateOperationIds } from './generate-operation-ids';
8+
9+
// Mock the modules
10+
vi.mock('fs');
11+
vi.mock('./generate-operation-ids');
12+
13+
const originalArgv = process.argv;
14+
15+
describe('cli', () => {
16+
const mockJsonStrings = '{"test": "data"}';
17+
18+
beforeEach(() => {
19+
vi.resetModules();
20+
vi.resetAllMocks();
21+
process.argv = [...originalArgv]; // Reset process.argv
22+
// Mock console.error to avoid actual console output during tests
23+
vi.spyOn(console, 'error').mockImplementation(() => {});
24+
});
25+
26+
it('processes input file and writes output to specified file', async() => {
27+
// Mock generateOperationIds to return success
28+
vi.mocked(generateOperationIds).mockResolvedValue(mockJsonStrings);
29+
30+
// Mock process.argv
31+
process.argv = ['node', 'cli.js', 'input.json', '-o', 'output.json'];
32+
33+
// Import the module that contains the main function
34+
const cliModule = await import('./cli');
35+
await cliModule.main();
36+
37+
// Verify generateOperationIds was called with correct arguments
38+
expect(generateOperationIds).toHaveBeenCalledWith('input.json', { overwriteExisting: undefined });
39+
40+
// Verify writeFileSync was called with correct arguments
41+
expect(writeFileSync).toHaveBeenCalledWith('output.json', mockJsonStrings);
42+
});
43+
44+
it('uses input file as output when no output file is specified', async() => {
45+
// Mock generateOperationIds to return success
46+
vi.mocked(generateOperationIds).mockResolvedValue(mockJsonStrings);
47+
48+
// Mock process.argv
49+
process.argv = ['node', 'cli.js', 'input.json'];
50+
51+
// Import the module that contains the main function
52+
const cliModule = await import('./cli');
53+
await cliModule.main();
54+
55+
// Verify generateOperationIds was called with correct arguments
56+
expect(generateOperationIds).toHaveBeenCalledWith('input.json', { overwriteExisting: undefined });
57+
58+
// Verify writeFileSync was called with input file as output
59+
expect(writeFileSync).toHaveBeenCalledWith('input.json', mockJsonStrings);
60+
});
61+
62+
it('handles overwrite-existing option correctly', async() => {
63+
// Mock generateOperationIds to return success
64+
vi.mocked(generateOperationIds).mockResolvedValue(mockJsonStrings);
65+
66+
// Mock process.argv
67+
process.argv = ['node', 'cli.js', 'input.json', '--overwrite-existing'];
68+
69+
// Import the module that contains the main function
70+
const cliModule = await import('./cli');
71+
await cliModule.main();
72+
73+
// Verify generateOperationIds was called with overwriteExisting option
74+
expect(generateOperationIds).toHaveBeenCalledWith('input.json', { overwriteExisting: true });
75+
});
76+
77+
it('handles generateOperationIds error correctly', async() => {
78+
// Mock generateOperationIds to throw error
79+
const error = new Error('Test error');
80+
vi.mocked(generateOperationIds).mockRejectedValue(error);
81+
82+
// Mock process.argv
83+
process.argv = ['node', 'cli.js', 'input.json'];
84+
85+
// Import the module that contains the main function
86+
const cliModule = await import('./cli');
87+
await cliModule.main();
88+
89+
// Verify error was logged
90+
// eslint-disable-next-line no-console
91+
expect(console.error).toHaveBeenCalledWith(error);
92+
93+
// Verify writeFileSync was not called
94+
expect(writeFileSync).not.toHaveBeenCalled();
95+
});
96+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { writeFileSync } from 'fs';
2+
3+
import { Command } from 'commander';
4+
5+
import { generateOperationIds } from './generate-operation-ids';
6+
7+
export const main = async(): Promise<void> => {
8+
// parse command line arguments
9+
const program = new Command();
10+
program
11+
.name('generate-operation-ids')
12+
.description('Generate operationId for OpenAPI specification')
13+
.argument('<input-file>', 'OpenAPI specification file')
14+
.option('-o, --out <output-file>', 'Output file (defaults to input file)')
15+
.option('--overwrite-existing', 'Overwrite existing operationId values')
16+
.parse();
17+
const { out: outputFile, overwriteExisting } = program.opts();
18+
const [inputFile] = program.args;
19+
20+
// eslint-disable-next-line no-console
21+
const jsonStrings = await generateOperationIds(inputFile, { overwriteExisting }).catch(console.error);
22+
if (jsonStrings != null) {
23+
writeFileSync(outputFile ?? inputFile, jsonStrings);
24+
}
25+
};
26+
27+
if (import.meta.url === `file://${process.argv[1]}`) {
28+
main();
29+
}

0 commit comments

Comments
 (0)