Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions apps/generator-cli/src/app/services/generator.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ describe('GeneratorService', () => {
ext: '#{ext}',
},
},
['ignore-list.json']: {
ignoreListArray: {
inputSpec: 'http://example.local/openapi.json',
output: 'ignore-list-array/#{name}',
openapiGeneratorIgnoreList: ['README.md', 'pom.xml', 'docs/*.md'],
},
ignoreListString: {
inputSpec: 'http://example.local/openapi.json',
output: 'ignore-list-string/#{name}',
openapiGeneratorIgnoreList: 'README.md,pom.xml',
},
},
};

const specFiles = {
Expand Down Expand Up @@ -229,6 +241,21 @@ describe('GeneratorService', () => {
],
['none.json', []],
['also-none.json', []],
[
'ignore-list.json',
[
cmd('[ignoreListArray] http://example.local/openapi.json', [
`--input-spec="http://example.local/openapi.json"`,
`--output="ignore-list-array/openapi"`,
`--openapi-generator-ignore-list="README.md,pom.xml,docs/*.md"`,
]),
cmd('[ignoreListString] http://example.local/openapi.json', [
`--input-spec="http://example.local/openapi.json"`,
`--output="ignore-list-string/openapi"`,
`--openapi-generator-ignore-list="README.md,pom.xml"`,
]),
],
],
[
'no-glob.json',
[
Expand Down
5 changes: 5 additions & 0 deletions apps/generator-cli/src/app/services/generator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ export class GeneratorService {
.toLowerCase();

const value = (() => {
// arrays are passed as comma separated lists, matching the csv
// semantics of CLI flags like --openapi-generator-ignore-list
if (Array.isArray(v)) {
return `"${v.join(',')}"`;
}
switch (typeof v) {
case 'object':
return `"${Object.entries(v)
Expand Down
14 changes: 14 additions & 0 deletions apps/generator-cli/src/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,20 @@
}
}
},
"openapiGeneratorIgnoreList": {
"description": "specifies a list of files or patterns to be ignored during generation, pre-populating the .openapi-generator-ignore file in the output folder. Can be provided as an array of strings or a comma separated list",
"anyOf": [
{
"type": "string"
},
{
"type": "array",
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
"items": {
"type": "string"
}
}
]
},
"packageName": {
"type": "string",
"description": "package for generated classes (where supported)"
Expand Down
72 changes: 72 additions & 0 deletions apps/generator-cli/src/config.schema.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Ajv from 'ajv';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const configSchema = require('./config.schema.json');

// strict mode is disabled because the `generator-cli.repository` block uses
// non-standard nesting (queryUrl/downloadUrl are not declared as properties),
// which ajv strict mode reports as unknown keywords
const validate = new Ajv({ strict: false }).compile(configSchema);

const baseConfig = {
$schema: './node_modules/@openapitools/openapi-generator-cli/config.schema.json',
spaces: 2,
'generator-cli': {
version: '7.12.0',
generators: {
kotlin: {
generatorName: 'kotlin',
inputSpec: './openapi/petstore.yaml',
output: './generated/kotlin',
},
},
},
};

function configWithIgnoreList(ignoreList: unknown) {
return {
...baseConfig,
'generator-cli': {
...baseConfig['generator-cli'],
generators: {
kotlin: {
...baseConfig['generator-cli'].generators.kotlin,
openapiGeneratorIgnoreList: ignoreList,
},
},
},
};
}

describe('config.schema', () => {
it('is a valid JSON schema', () => {
expect(new Ajv({ strict: false }).validateSchema(configSchema)).toBe(true);
});

it('validates a config without openapiGeneratorIgnoreList', () => {
expect(validate(baseConfig)).toBe(true);
expect(validate.errors).toBeNull();
});

describe('openapiGeneratorIgnoreList', () => {
it.each([[['README.md', 'pom.xml', 'docs/*.md']], [['single']], [[]]])(
'accepts the array of strings %j',
(ignoreList) => {
expect(validate(configWithIgnoreList(ignoreList))).toBe(true);
expect(validate.errors).toBeNull();
}
);

it('accepts a comma separated list', () => {
expect(validate(configWithIgnoreList('README.md,pom.xml'))).toBe(true);
expect(validate.errors).toBeNull();
});

it.each([[42], [true], [null], [[42]], [[{}]], [{}]])(
'rejects the invalid value %j',
(invalidValue) => {
expect(validate(configWithIgnoreList(invalidValue))).toBe(false);
}
);
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"@types/node": "^22.0.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"ajv": "^8.20.0",
"dotenv": "17.4.2",
"eslint": "9.39.5",
"eslint-config-prettier": "^10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4244,7 +4244,7 @@ ajv@^6.12.5, ajv@^6.14.0:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^8.0.0, ajv@^8.11.0, ajv@^8.12.0, ajv@^8.9.0:
ajv@^8.0.0, ajv@^8.11.0, ajv@^8.12.0, ajv@^8.20.0, ajv@^8.9.0:
version "8.20.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.20.0.tgz#304b3636add88ba7d936760dd50ece006dea95f9"
integrity sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==
Expand Down
Loading