Skip to content

Commit 3417bf3

Browse files
authored
Merge pull request #435 from acacode/next
Next release
2 parents ec91cc5 + 3bb7441 commit 3417bf3

Some content is hidden

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

62 files changed

+4843
-179
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# next release
22

3+
# 11.1.2
4+
5+
fix: problems with missing type imports in `.d.ts` files with using option `--js`
6+
internal: add extra spec tests
7+
fix: additionalProperties management problem in Swagger 2 (#343)
8+
fix: hanging cli after execution finished (#436, thanks @Soarc)
9+
310
# 11.1.1
411
fix: `--api-class-name` option has no default value (#433)
512

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ const main = async () => {
308308
} catch (e) {
309309
console.error(e);
310310
process.exit(1);
311+
return;
311312
}
313+
process.exit(0);
312314
};
313315

314316
main();

package-lock.json

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

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "11.1.1",
3+
"version": "11.1.2",
44
"description": "Generate typescript/javascript api from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
@@ -39,6 +39,7 @@
3939
"test:--enum-names-as-values": "node tests/spec/enumNamesAsValues/test.js",
4040
"test:--default-response": "node tests/spec/defaultResponse/test.js",
4141
"test:--js": "node tests/spec/js/test.js",
42+
"test:jsSingleHttpClientModular": "node tests/spec/jsSingleHttpClientModular/test.js",
4243
"test:--js--axios": "node tests/spec/jsAxios/test.js",
4344
"test:--axios": "node tests/spec/axios/test.js",
4445
"test:--another-array-type": "node tests/spec/another-array-type/test.js",
@@ -47,11 +48,15 @@
4748
"test:--type-suffix--type-prefix": "node tests/spec/typeSuffixPrefix/test.js",
4849
"test:--dot-path-params": "node tests/spec/dot-path-params/test.js",
4950
"test:--primitive-type-constructs": "node tests/spec/primitive-type-constructs/test.js",
50-
"test:--cli": "node index.js -p tests/spec/cli/schema.json -o tests/spec/cli -n schema.ts --extract-response-body --extract-response-error --api-class-name MySuperApi --type-prefix Prefix",
51+
"test:--cli": "node index.js -p tests/spec/cli/schema.json -o tests/spec/cli -n schema.ts --extract-response-body --extract-response-error --api-class-name MySuperApi --type-prefix Prefix && node tests/spec/cli/test.js",
5152
"test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
5253
"test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
5354
"test:--patch": "node tests/spec/patch/test.js",
54-
"test:deprecated": "node tests/spec/deprecated/test.js"
55+
"test:deprecated": "node tests/spec/deprecated/test.js",
56+
"test:nullableRefTest3.0": "node tests/spec/nullable-3.0/test.js",
57+
"test:nullableRefTest2.0": "node tests/spec/nullable-2.0/test.js",
58+
"test:additionalProperties2.0": "node tests/spec/additional-properties-2.0/test.js",
59+
"test:enums2.0": "node tests/spec/enums-2.0/test.js"
5560
},
5661
"author": "acacode",
5762
"license": "MIT",
@@ -62,6 +67,7 @@
6267
"@types/node": "^18.11.7",
6368
"@types/prettier": "^2.7.1",
6469
"all-contributors-cli": "^6.20.0",
70+
"axios": "^1.1.3",
6571
"cross-env": "^7.0.3",
6672
"git-diff": "^2.0.6",
6773
"husky": "^4.3.6",

src/schema-parser/schema-parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class SchemaParser {
149149
});
150150
},
151151
[SCHEMA_TYPES.OBJECT]: (schema, typeName) => {
152-
const content = this.getObjectSchemaContent(schema);
152+
const contentProperties = this.getObjectSchemaContent(schema);
153153

154154
return this.attachParsedRef(schema, {
155155
...(_.isObject(schema) ? schema : {}),
@@ -159,8 +159,8 @@ class SchemaParser {
159159
typeIdentifier: this.config.Ts.Keyword.Interface,
160160
name: typeName,
161161
description: this.schemaFormatters.formatDescription(schema.description),
162-
allFieldsAreOptional: !_.some(_.values(content), (part) => part.isRequired),
163-
content: content,
162+
allFieldsAreOptional: !_.some(_.values(contentProperties), (part) => part.isRequired),
163+
content: contentProperties,
164164
});
165165
},
166166
[SCHEMA_TYPES.COMPLEX]: (schema, typeName) => {
@@ -424,7 +424,7 @@ class SchemaParser {
424424
};
425425
});
426426

427-
if (additionalProperties === true) {
427+
if (additionalProperties) {
428428
propertiesContent.push({
429429
$$raw: { additionalProperties },
430430
description: "",

src/translators/JavaScript.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,21 @@ module.exports = {
4040

4141
const sourceFileName = fileName.replace(ts.Extension.Ts, ts.Extension.Js);
4242
const declarationFileName = fileName.replace(ts.Extension.Ts, ts.Extension.Dts);
43+
const sourceContent = translated[sourceFileName];
44+
const tsImportRows = sourceTypeScript.split("\n").filter((line) => line.startsWith("import "));
45+
const declarationContent = translated[declarationFileName]
46+
.split("\n")
47+
.map((line) => {
48+
if (line.startsWith("import ")) {
49+
return tsImportRows.shift();
50+
}
51+
return line;
52+
})
53+
.join("\n");
4354

4455
return {
45-
sourceContent: translated[sourceFileName],
46-
declarationContent: translated[declarationFileName],
56+
sourceContent: sourceContent,
57+
declarationContent: declarationContent,
4758
};
4859
},
4960
};

0 commit comments

Comments
 (0)