Skip to content

Commit 9781aff

Browse files
authored
Release 3.1.1
fix: problem of name.includes is not a function (acacode#98) ; bump: up version to 3.1.1 (acacode#100)
1 parent 14f59aa commit 9781aff

File tree

7 files changed

+39
-4
lines changed

7 files changed

+39
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# next release
22

3+
# 3.1.1
4+
5+
Fixes:
6+
- `name.includes is not a function` (issue #98)
37

48
# 3.1.0
59

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Create typescript api module from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",

src/modelNames.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ const isValidName = (name) => /^([A-Za-z$_]{1,})$/g.test(name);
55
const formattedModelNamesMap = new Map();
66

77
const checkAndRenameModelName = (name) => {
8+
if (typeof name !== "string") {
9+
console.warn("🔨 wrong name of the model name", name);
10+
11+
return name;
12+
}
13+
814
if (formattedModelNamesMap.has(name)) {
915
return formattedModelNamesMap.get(name);
1016
}

src/schema.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,29 @@ const jsPrimitiveTypes = _.uniq(["number", "string", "boolean"]);
3232
const jsEmptyTypes = _.uniq(["null", "undefined"]);
3333
const formDataTypes = _.uniq([types.file, types.string.binary]);
3434

35+
const stealTypeFromSchema = (rawSchema) => {
36+
const schema = rawSchema || {};
37+
38+
if (schema.type) {
39+
return schema.type;
40+
}
41+
if (schema.enum) {
42+
const enumFieldType = typeof schema.enum[0];
43+
if (enumFieldType === "undefined") return;
44+
45+
return enumFieldType;
46+
}
47+
if (_.keys(schema.properties).length) {
48+
return "object";
49+
}
50+
if (!!schema.items) {
51+
return "array";
52+
}
53+
};
54+
3555
const getTypeAlias = (rawSchema) => {
3656
const schema = rawSchema || {};
37-
const type = toInternalCase(schema.type);
57+
const type = toInternalCase(stealTypeFromSchema(schema));
3858
const format = toInternalCase(schema.format);
3959
const typeAlias = _.get(types, [type, format]) || _.get(types, [type, "$default"]) || types[type];
4060

tests/generated/v2.0/another-example.ts

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export enum PetNames {
6363

6464
export type PetIds = 10 | 20 | 30 | 40;
6565

66+
export type PetIdsWithWrongEnum = 10 | 20 | 30 | 40;
67+
6668
/**
6769
* A pet for sale in the pet store
6870
*/

tests/schemas/v2.0/another-example.json

+3
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,9 @@
887887
"type": "integer",
888888
"enum": [10, 20, 30, 40]
889889
},
890+
"PetIdsWithWrongEnum": {
891+
"enum": [10, 20, 30, 40]
892+
},
890893
"Pet": {
891894
"type": "object",
892895
"required": ["name", "photoUrls"],

0 commit comments

Comments
 (0)