Skip to content

Commit 31ce4a2

Browse files
authored
Merge branch 'master' into keywords
2 parents 5d140cb + 2a26cb7 commit 31ce4a2

23 files changed

+908
-540
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ $ openapi --help
4848
--exportModels <value> Write models to disk (default: true)
4949
--exportSchemas <value> Write schemas to disk (default: false)
5050
--indent <value> Indentation options [4, 2, tab] (default: "4")
51-
--postfix <value> Service name postfix (default: "Service")
51+
--postfixServices Service name postfix (default: "Service")
52+
--postfixModels Model name postfix
5253
--request <value> Path to custom request file
5354
-h, --help display help for command
5455

bin/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const params = program
2121
.option('--exportModels <value>', 'Write models to disk', true)
2222
.option('--exportSchemas <value>', 'Write schemas to disk', false)
2323
.option('--indent <value>', 'Indentation options [4, 2, tabs]', '4')
24-
.option('--postfix <value>', 'Service name postfix', 'Service')
24+
.option('--postfix <value>', 'Deprecated: Use --postfixServices instead. Service name postfix', 'Service')
25+
.option('--postfixServices <value>', 'Service name postfix', 'Service')
26+
.option('--postfixModels <value>', 'Model name postfix')
2527
.option('--request <value>', 'Path to custom request file')
2628
.parse(process.argv)
2729
.opts();
@@ -41,7 +43,8 @@ if (OpenAPI) {
4143
exportModels: JSON.parse(params.exportModels) === true,
4244
exportSchemas: JSON.parse(params.exportSchemas) === true,
4345
indent: params.indent,
44-
postfix: params.postfix,
46+
postfixServices: params.postfixServices ?? params.postfix,
47+
postfixModels: params.postfixModels,
4548
request: params.request,
4649
})
4750
.then(() => {

bin/index.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ describe('bin', () => {
3434
'true',
3535
'--indent',
3636
'4',
37-
'--postfix',
37+
'--postfixServices',
3838
'Service',
39+
'--postfixModels',
40+
'Dto',
3941
]);
4042
expect(result.stdout.toString()).toBe('');
4143
expect(result.stderr.toString()).toBe('');
@@ -67,4 +69,18 @@ describe('bin', () => {
6769
expect(result.stdout.toString()).toContain(`-o, --output <value>`);
6870
expect(result.stderr.toString()).toBe('');
6971
});
72+
73+
it('should still support the deprecated --postfix parameter', () => {
74+
const result = crossSpawn.sync('node', [
75+
'./bin/index.js',
76+
'--input',
77+
'./test/spec/v3.json',
78+
'--output',
79+
'./test/generated/bin',
80+
'--postfix',
81+
'Service',
82+
]);
83+
expect(result.stdout.toString()).toBe('');
84+
expect(result.stderr.toString()).toBe('');
85+
});
7086
});

docs/basic-usage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ $ openapi --help
1818
--exportModels <value> Write models to disk (default: true)
1919
--exportSchemas <value> Write schemas to disk (default: false)
2020
--indent <value> Indentation options [4, 2, tab] (default: "4")
21-
--postfix <value> Service name postfix (default: "Service")
21+
--postfixServices Service name postfix (default: "Service")
22+
--postfixModels Model name postfix
2223
--request <value> Path to custom request file
2324
-h, --help display help for command
2425

package-lock.json

Lines changed: 678 additions & 370 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,27 @@
7878
"@angular/platform-browser-dynamic": "14.0.1",
7979
"@angular/router": "14.0.1",
8080
"@babel/cli": "7.18.10",
81-
"@babel/core": "7.18.10",
82-
"@babel/preset-env": "7.18.10",
81+
"@babel/core": "7.18.13",
82+
"@babel/preset-env": "7.19.0",
8383
"@babel/preset-typescript": "7.18.6",
8484
"@rollup/plugin-commonjs": "22.0.2",
8585
"@rollup/plugin-node-resolve": "13.3.0",
86-
"@rollup/plugin-typescript": "8.3.4",
86+
"@rollup/plugin-typescript": "8.5.0",
8787
"@types/cross-spawn": "6.0.2",
8888
"@types/express": "4.17.13",
8989
"@types/fs-extra": "^9.0.13",
9090
"@types/glob": "7.2.0",
91-
"@types/jest": "28.1.6",
92-
"@types/node": "18.6.5",
91+
"@types/jest": "28.1.8",
92+
"@types/node": "18.7.17",
9393
"@types/node-fetch": "2.6.1",
9494
"@types/qs": "6.9.7",
95-
"@typescript-eslint/eslint-plugin": "5.33.0",
96-
"@typescript-eslint/parser": "5.33.0",
95+
"@typescript-eslint/eslint-plugin": "5.36.2",
96+
"@typescript-eslint/parser": "5.37.0",
9797
"abort-controller": "3.0.0",
9898
"axios": "0.27.2",
9999
"codecov": "3.8.3",
100100
"cross-spawn": "7.0.3",
101-
"eslint": "8.21.0",
101+
"eslint": "8.23.1",
102102
"eslint-config-prettier": "8.5.0",
103103
"eslint-plugin-prettier": "4.2.1",
104104
"eslint-plugin-simple-import-sort": "7.0.0",
@@ -111,13 +111,13 @@
111111
"puppeteer": "15.5.0",
112112
"qs": "6.11.0",
113113
"rimraf": "3.0.2",
114-
"rollup": "2.77.2",
114+
"rollup": "2.79.0",
115115
"rollup-plugin-terser": "7.0.2",
116116
"rxjs": "7.5.6",
117117
"ts-node": "10.9.1",
118118
"tslib": "2.4.0",
119119
"typescript": "4.7.3",
120-
"zone.js": "0.11.7"
120+
"zone.js": "0.11.8"
121121
},
122122
"resolutions": {
123123
"node-fetch": "2.6.7"

src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export type Options = {
2424
exportModels?: boolean;
2525
exportSchemas?: boolean;
2626
indent?: Indent;
27-
postfix?: string;
27+
postfixServices?: string;
28+
postfixModels?: string;
2829
request?: string;
2930
write?: boolean;
3031
};
@@ -44,7 +45,8 @@ export type Options = {
4445
* @param exportModels Generate models
4546
* @param exportSchemas Generate schemas
4647
* @param indent Indentation options (4, 2 or tab)
47-
* @param postfix Service name postfix
48+
* @param postfixServices Service name postfix
49+
* @param postfixModels Model name postfix
4850
* @param request Path to custom request file
4951
* @param write Write the files to disk (true or false)
5052
*/
@@ -60,7 +62,8 @@ export const generate = async ({
6062
exportModels = true,
6163
exportSchemas = false,
6264
indent = Indent.SPACE_4,
63-
postfix = 'Service',
65+
postfixServices = 'Service',
66+
postfixModels = '',
6467
request,
6568
write = true,
6669
}: Options): Promise<void> => {
@@ -89,7 +92,8 @@ export const generate = async ({
8992
exportModels,
9093
exportSchemas,
9194
indent,
92-
postfix,
95+
postfixServices,
96+
postfixModels,
9397
clientName,
9498
request
9599
);
@@ -112,7 +116,8 @@ export const generate = async ({
112116
exportModels,
113117
exportSchemas,
114118
indent,
115-
postfix,
119+
postfixServices,
120+
postfixModels,
116121
clientName,
117122
request
118123
);

src/openApi/v3/parser/getModel.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ export const getModel = (
9595
}
9696
}
9797

98-
if (definition.type === 'object' && typeof definition.additionalProperties === 'object') {
99-
if (definition.additionalProperties.$ref) {
100-
const additionalProperties = getType(definition.additionalProperties.$ref);
98+
if (
99+
definition.type === 'object' &&
100+
(typeof definition.additionalProperties === 'object' || definition.additionalProperties === true)
101+
) {
102+
const ap = typeof definition.additionalProperties === 'object' ? definition.additionalProperties : {};
103+
if (ap.$ref) {
104+
const additionalProperties = getType(ap.$ref);
101105
model.export = 'dictionary';
102106
model.type = additionalProperties.type;
103107
model.base = additionalProperties.base;
@@ -106,7 +110,7 @@ export const getModel = (
106110
model.default = getModelDefault(definition, model);
107111
return model;
108112
} else {
109-
const additionalProperties = getModel(openApi, definition.additionalProperties);
113+
const additionalProperties = getModel(openApi, ap);
110114
model.export = 'dictionary';
111115
model.type = additionalProperties.type;
112116
model.base = additionalProperties.base;
@@ -146,12 +150,12 @@ export const getModel = (
146150
}
147151

148152
if (definition.type === 'object') {
149-
model.export = 'interface';
150-
model.type = 'any';
151-
model.base = 'any';
152-
model.default = getModelDefault(definition, model);
153-
154153
if (definition.properties) {
154+
model.export = 'interface';
155+
model.type = 'any';
156+
model.base = 'any';
157+
model.default = getModelDefault(definition, model);
158+
155159
const modelProperties = getModelProperties(openApi, definition, getModel, model);
156160
modelProperties.forEach(modelProperty => {
157161
model.imports.push(...modelProperty.imports);
@@ -161,8 +165,18 @@ export const getModel = (
161165
model.enums.push(modelProperty);
162166
}
163167
});
168+
return model;
169+
} else {
170+
const additionalProperties = getModel(openApi, {});
171+
model.export = 'dictionary';
172+
model.type = additionalProperties.type;
173+
model.base = additionalProperties.base;
174+
model.template = additionalProperties.template;
175+
model.link = additionalProperties;
176+
model.imports.push(...additionalProperties.imports);
177+
model.default = getModelDefault(definition, model);
178+
return model;
164179
}
165-
return model;
166180
}
167181

168182
// If the schema has a type than it can be a basic or generic type.

src/templates/core/fetch/getResponseBody.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const getResponseBody = async (response: Response): Promise<any> => {
33
try {
44
const contentType = response.headers.get('Content-Type');
55
if (contentType) {
6-
const isJSON = contentType.toLowerCase().startsWith('application/json');
6+
const jsonTypes = ['application/json', 'application/problem+json']
7+
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
78
if (isJSON) {
89
return await response.json();
910
} else {

src/templates/core/node/getResponseBody.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const getResponseBody = async (response: Response): Promise<any> => {
33
try {
44
const contentType = response.headers.get('Content-Type');
55
if (contentType) {
6-
const isJSON = contentType.toLowerCase().startsWith('application/json');
6+
const jsonTypes = ['application/json', 'application/problem+json']
7+
const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
78
if (isJSON) {
89
return await response.json();
910
} else {

0 commit comments

Comments
 (0)