|
1 | 1 | # next release
|
2 | 2 |
|
| 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 | + |
3 | 202 | # 10.0.3
|
4 | 203 | fix: CRLF -> LF (#423)
|
5 | 204 | docs: add docs for addReadonly nodeJS api flag (#425)
|
|
0 commit comments