Skip to content

Commit e64d703

Browse files
js2meqbootBen WatkinsFeargaliciousFeargal Kavanagh
authored
Merge pull request #429 from acacode/next
* docs: add link to article about swagger typescript api lessons in README * fix: problems with path params with dots * internal: add gitattributes * feat: ability to modify code gen constructs; feat: --another-array-type cli option (Array<Type>); docs: update CHANGELOG, README * bump: 11.0.0; refactor: codebase of project, `data-contract-jsdoc.ejs` incompatible with prev version, see CHANGELOG * docs: typo fix * feat: improve jsdoc fields declaration * docs: update README * chore: add .nvmrc * fix: problems due to new version; feat: new cli utility * fix(deprecated): property with deprecated=false was shown as deprecated (#421) * document approach to disabling output (#325) * Added "generateClient", "typePrefix", "typeSuffix" options to readme for NodeJS usage (#335) Co-authored-by: Feargal Kavanagh <[email protected]> Co-authored-by: Sergey S. Volkov <[email protected]> * fix: ci\cd build; fix: try\catch for cli operation * refactor: templates * fix: replace Iterable<any> to any[] in axios-http-client to solve type bugs linked with Iterable * feat: add new command (generate-templates) * docs: update CHANGELOG * fix: tests, scriptsRunner Co-authored-by: Quentin Brunet <[email protected]> Co-authored-by: Ben Watkins <[email protected]> Co-authored-by: Feargal Kavanagh <[email protected]> Co-authored-by: Feargal Kavanagh <[email protected]>
2 parents 6f1abb6 + 276c52d commit e64d703

File tree

150 files changed

+40936
-40943
lines changed

Some content is hidden

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

150 files changed

+40936
-40943
lines changed

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
* text=auto
2+
*.js text eol=lf
3+
*.mjs text eol=lf
4+
*.jsx text eol=lf
5+
*.ts text eol=lf
6+
*.tsx text eol=lf
7+
*.json text eol=lf
8+
*.md text eol=lf

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.16.0

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/**/*.ts
22
tests/**/schema.js
3+
tests/**/schema.ts
34
tests/**/*.d.js
45
swagger-test-cli
56
swagger-test-cli.*

CHANGELOG.md

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

3+
# 11.0.0
4+
5+
## Breaking changes
6+
7+
- `data-contract-jsdoc.ejs` file uses new input structure. Please update your local copy.
8+
- new codebase (class way)
9+
- ability to change everything in codegen process configuration with using NodeJS Api
10+
- ability to call `generateApi` function 2 and more times per 1 NodeJS process.
11+
- new command `generate-templates` to create source templates
12+
13+
## [feature] Ability to generate source templates
14+
New command `generate-templates` which allow you to generate source templates which using with option `--templates`
15+
16+
## [feature] Ability to modify internal codegen typescript structs
17+
Everything which creates codegen about output typescript code now contains in `Ts` field in [`src/configuration`](src/configuration.js).
18+
And this thing is available for end user modifications with using NodeJS Cli option `codeGenConstructs`.
19+
It contains almost all which is not contains in `.eta`\ `.ejs` templates. For example: `Record<string, any>`, `readonly typeField?: value`, etc
20+
21+
Structure of `Ts` property
22+
```ts
23+
const Ts = {
24+
Keyword: {
25+
Number: "number",
26+
String: "string",
27+
Boolean: "boolean",
28+
Any: "any",
29+
Void: "void",
30+
Unknown: "unknown",
31+
Null: "null",
32+
Undefined: "undefined",
33+
Object: "object",
34+
File: "File",
35+
Date: "Date",
36+
Type: "type",
37+
Enum: "enum",
38+
Interface: "interface",
39+
Array: "Array",
40+
Record: "Record",
41+
Intersection: "&",
42+
Union: "|",
43+
},
44+
CodeGenKeyword: {
45+
UtilRequiredKeys: "UtilRequiredKeys",
46+
},
47+
/**
48+
* $A[] or Array<$A>
49+
*/
50+
ArrayType: (content) => {
51+
if (this.anotherArrayType) {
52+
return Ts.TypeWithGeneric(Ts.Keyword.Array, [content]);
53+
}
54+
55+
return `${Ts.ExpressionGroup(content)}[]`;
56+
},
57+
/**
58+
* "$A"
59+
*/
60+
StringValue: (content) => `"${content}"`,
61+
/**
62+
* $A
63+
*/
64+
BooleanValue: (content) => `${content}`,
65+
/**
66+
* $A
67+
*/
68+
NumberValue: (content) => `${content}`,
69+
/**
70+
* $A
71+
*/
72+
NullValue: (content) => content,
73+
/**
74+
* $A1 | $A2
75+
*/
76+
UnionType: (contents) => _.join(_.uniq(contents), ` ${Ts.Keyword.Union} `),
77+
/**
78+
* ($A1)
79+
*/
80+
ExpressionGroup: (content) => (content ? `(${content})` : ""),
81+
/**
82+
* $A1 & $A2
83+
*/
84+
IntersectionType: (contents) => _.join(_.uniq(contents), ` ${Ts.Keyword.Intersection} `),
85+
/**
86+
* Record<$A1, $A2>
87+
*/
88+
RecordType: (key, value) => Ts.TypeWithGeneric(Ts.Keyword.Record, [key, value]),
89+
/**
90+
* readonly $key?:$value
91+
*/
92+
TypeField: ({ readonly, key, optional, value }) =>
93+
_.compact([readonly && "readonly ", key, optional && "?", ": ", value]).join(""),
94+
/**
95+
* [key: $A1]: $A2
96+
*/
97+
InterfaceDynamicField: (key, value) => `[key: ${key}]: ${value}`,
98+
/**
99+
* $A1 = $A2
100+
*/
101+
EnumField: (key, value) => `${key} = ${value}`,
102+
/**
103+
* $A0.key = $A0.value,
104+
* $A1.key = $A1.value,
105+
* $AN.key = $AN.value,
106+
*/
107+
EnumFieldsWrapper: (contents) =>
108+
_.map(contents, ({ key, value }) => ` ${Ts.EnumField(key, value)}`).join(",\n"),
109+
/**
110+
* {\n $A \n}
111+
*/
112+
ObjectWrapper: (content) => `{\n${content}\n}`,
113+
/**
114+
* /** $A *\/
115+
*/
116+
MultilineComment: (contents, formatFn) =>
117+
[
118+
...(contents.length === 1
119+
? [`/** ${contents[0]} */`]
120+
: ["/**", ...contents.map((content) => ` * ${content}`), " */"]),
121+
].map((part) => `${formatFn ? formatFn(part) : part}\n`),
122+
/**
123+
* $A1<...$A2.join(,)>
124+
*/
125+
TypeWithGeneric: (typeName, genericArgs) => {
126+
return `${typeName}${genericArgs.length ? `<${genericArgs.join(",")}>` : ""}`;
127+
},
128+
}
129+
```
130+
131+
## [feature] Ability to modify swagger schema type/format to typescript construction translators
132+
Swagger schema has constructions like `{ "type": "string" | "integer" | etc, "format": "date-time" | "float" | "etc" }` where field `type` is not "readable" for TypeScript.
133+
And because of this `swagger-typescript-api` has key value group to translate swagger schema fields `type`/`format` to TypeScript constructions.
134+
See more about [swagger schema type/format data here](https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times)
135+
For example, current version of default configuration translates this schema
136+
```json
137+
{
138+
"type": "string",
139+
"format": "date-time"
140+
}
141+
```
142+
translates to
143+
```ts
144+
string
145+
```
146+
If you need to see `Date` instead of `string` you are able to change it with using `primitiveTypeConstructs`
147+
```ts
148+
generateApiForTest({
149+
// ...
150+
primitiveTypeConstructs: (construct) => ({
151+
string: {
152+
'date-time': 'Date'
153+
}
154+
})
155+
})
156+
```
157+
158+
Structure of `primitiveTypes` property
159+
```ts
160+
const primitiveTypes = {
161+
integer: () => Ts.Keyword.Number,
162+
number: () => Ts.Keyword.Number,
163+
boolean: () => Ts.Keyword.Boolean,
164+
object: () => Ts.Keyword.Object,
165+
file: () => Ts.Keyword.File,
166+
string: {
167+
$default: () => Ts.Keyword.String,
168+
169+
/** formats */
170+
binary: () => Ts.Keyword.File,
171+
file: () => Ts.Keyword.File,
172+
"date-time": () => Ts.Keyword.String,
173+
time: () => Ts.Keyword.String,
174+
date: () => Ts.Keyword.String,
175+
duration: () => Ts.Keyword.String,
176+
email: () => Ts.Keyword.String,
177+
"idn-email": () => Ts.Keyword.String,
178+
"idn-hostname": () => Ts.Keyword.String,
179+
ipv4: () => Ts.Keyword.String,
180+
ipv6: () => Ts.Keyword.String,
181+
uuid: () => Ts.Keyword.String,
182+
uri: () => Ts.Keyword.String,
183+
"uri-reference": () => Ts.Keyword.String,
184+
"uri-template": () => Ts.Keyword.String,
185+
"json-pointer": () => Ts.Keyword.String,
186+
"relative-json-pointer": () => Ts.Keyword.String,
187+
regex: () => Ts.Keyword.String,
188+
},
189+
array: ({ items, ...schemaPart }, parser) => {
190+
const content = parser.getInlineParseContent(items);
191+
return parser.checkAndAddNull(schemaPart, Ts.ArrayType(content));
192+
},
193+
}
194+
```
195+
196+
## Other
197+
feat: `--another-array-type` cli option (#414)
198+
fix: path params with dot style (truck.id) (#413)
199+
200+
201+
3202
# 10.0.3
4203
fix: CRLF -> LF (#423)
5204
docs: add docs for addReadonly nodeJS api flag (#425)

0 commit comments

Comments
 (0)