Skip to content

Commit 20eb1ff

Browse files
committed
- Fixed issue with anyOf
1 parent 8a68605 commit 20eb1ff

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,4 @@ OpenAPI.TOKEN = 'some-bearer-token';
277277

278278

279279
### Compare to other libraries
280-
https://htmlpreview.github.io/?https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/samples/README.html
280+
[samples/README.html](https://htmlpreview.github.io/?https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/samples/README.html)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",
66
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",

samples/codegen.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,3 @@ echo v3/openapi-typescript-codegen && time node ../bin/index.js --input v3/spec.
2020

2121
yarn install
2222
yarn run build
23-
24-
cd examples
25-
find . -type f ! -iname "*.ts" -delete
26-
cd ../

samples/README.html renamed to samples/index.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" crossorigin="anonymous">
99
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" crossorigin="anonymous">
1010
<title>Compared to other generators</title>
11+
<style>
12+
details summary {
13+
outline: none;
14+
}
15+
</style>
1116
</head>
1217
<body>
1318
<div class="container">
@@ -137,14 +142,16 @@ <h5>And used the following generators with their default options:</h5>
137142
<td class="success" data-type="aurelia"></td>
138143
<td class="success" data-type="inversify"></td>
139144
<td class="warning" data-type="angular">
145+
<span>⚠️</span>
140146
<details>
141-
<summary>⚠️</summary>
147+
<summary>Details</summary>
142148
<p>V3 version sends data as <code>application/octet-stream</code> instead of <code>application/x-www-form-urlencoded</code></p>
143149
</details>
144150
</td>
145151
<td class="warning" data-type="fetch">
152+
<span>⚠️</span>
146153
<details>
147-
<summary>⚠️</summary>
154+
<summary>Details</summary>
148155
<p>V3 version sends data as <code>application/octet-stream</code> instead of <code>application/x-www-form-urlencoded</code></p>
149156
</details>
150157
</td>
@@ -168,15 +175,17 @@ <h5>And used the following generators with their default options:</h5>
168175
<td class="danger" data-type="inversify"></td>
169176
<td class="danger" data-type="angular"></td>
170177
<td class="warning" data-type="node">
178+
<span>⚠️</span>
171179
<details>
172-
<summary>⚠️</summary>
180+
<summary>Details</summary>
173181
<p>Requires portable-fetch</p>
174182
</details>
175183
</td>
176184
<td class="danger" data-type="jquery"></td>
177185
<td class="warning" data-type="node">
186+
<span>⚠️</span>
178187
<details>
179-
<summary>⚠️</summary>
188+
<summary>Details</summary>
180189
<p>Requires bluebird</p>
181190
</details>
182191
</td>
@@ -185,38 +194,44 @@ <h5>And used the following generators with their default options:</h5>
185194
<th>Compiles in strict mode without issues</th>
186195
<td class="success" data-type="openapi-typescript-codegen"></td>
187196
<td class="danger" data-type="aurelia">
197+
<span></span>
188198
<details>
189-
<summary></summary>
199+
<summary>Details</summary>
190200
<p>Errors when compiling: <code>PetApi.ts:147:30 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'</code></p>
191201
</details>
192202
</td>
193203
<td class="danger" data-type="inversify">
204+
<span></span>
194205
<details>
195-
<summary></summary>
206+
<summary>Details</summary>
196207
<p>Errors when compiling: <code>pet.service.ts:312:159 - error TS2304: Cannot find name 'body'</code></p>
197208
</details>
198209
</td>
199210
<td class="danger" data-type="angular">
211+
<span></span>
200212
<details>
201-
<summary></summary>
213+
<summary>Details</summary>
202214
<p>Errors when compiling: <code>pet.service.ts:528:26 - error TS1345: An expression of type 'void' cannot be tested for truthiness</code></p>
203215
</details>
204216
</td>
205217
<td class="danger" data-type="fetch">
218+
<span></span>
206219
<details>
207-
<summary></summary>
220+
<summary>Details</summary>
208221
<p>Errors when compiling: <code>api.ts:2276:67 - error TS2300: Duplicate identifier 'username'</code></p>
209222
</details>
210223
</td>
211224
<td class="danger" data-type="jquery">
225+
<span></span>
212226
<details>
213-
<summary></summary>
227+
<summary>Details</summary>
214228
<p>Errors when compiling: <code>PetApi.ts:25:12 - error TS2322: Type 'null' is not assignable to type 'JQueryAjaxSettings | undefined'</code></p>
215229
</details>
216230
</td>
217231
<td class="danger" data-type="node">
232+
<span></span>
218233
<details>
219-
<summary></summary>
234+
<summary>Details</summary>
220235
<p>Errors when compiling: <code>api.ts:1631:45 - error TS2694: Namespace '"http"' has no exported member 'ClientResponse'</code></p>
221236
</details>
222237
</td>

src/openApi/v3/parser/getModel.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
114114
}
115115
}
116116

117-
if (definition.anyOf && definition.anyOf.length) {
117+
// TODO: Add correct support for oneOf, anyOf, allOf
118+
// TODO: https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
119+
120+
if (definition.anyOf && definition.anyOf.length && !definition.properties) {
118121
model.export = 'generic';
119122
const compositionTypes = definition.anyOf.filter(type => type.$ref).map(type => getType(type.$ref));
120123
const composition = compositionTypes
@@ -127,7 +130,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti
127130
return model;
128131
}
129132

130-
if (definition.oneOf && definition.oneOf.length) {
133+
if (definition.oneOf && definition.oneOf.length && !definition.properties) {
131134
model.export = 'generic';
132135
const compositionTypes = definition.oneOf.filter(type => type.$ref).map(type => getType(type.$ref));
133136
const composition = compositionTypes

0 commit comments

Comments
 (0)