Skip to content

Commit a60014c

Browse files
committed
- Added tests for compare
1 parent 8ce9e97 commit a60014c

File tree

8 files changed

+2456
-24
lines changed

8 files changed

+2456
-24
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
## Known issues:
2121
- If you use enums inside your models / definitions then those enums are now
2222
inside a namespace with the same name as your model. This is called declaration
23-
merging. However Babel 7 now support compiling of Typescript and right now they
23+
merging. However, Babel 7 now support compiling of Typescript and right now they
2424
do not support namespaces.
2525

2626

@@ -111,7 +111,7 @@ createUser({
111111

112112
### Runtime schemas
113113
By default the OpenAPI generator only exports interfaces for your models. These interfaces will help you during
114-
development, but will not be available in javascript during runtime. However Swagger allows you to define properties
114+
development, but will not be available in javascript during runtime. However, Swagger allows you to define properties
115115
that can be useful during runtime, for instance: `maxLength` of a string or a `pattern` to match, etc. Let's say
116116
we have the following model:
117117

@@ -158,7 +158,7 @@ export interface MyModel {
158158
}
159159
```
160160

161-
The interface does not contain any properties like `maxLength` or `pattern`. However they could be useful
161+
The interface does not contain any properties like `maxLength` or `pattern`. However, they could be useful
162162
if we wanted to create some form where a user could create such a model. In that form you would iterate
163163
over the properties to render form fields based on their type and validate the input based on the `maxLength`
164164
or `pattern` property. This requires us to have this information somewhere... For this we can use the
@@ -222,7 +222,7 @@ const MyForm = () => (
222222

223223
### Enum with custom names and descriptions
224224
You can use `x-enum-varnames` and `x-enum-descriptions` in your spec to generate enum with custom names and descriptions.
225-
It's not in official [spec](https://github.com/OAI/OpenAPI-Specification/issues/681) yet. But its a supported extension
225+
It's not in official [spec](https://github.com/OAI/OpenAPI-Specification/issues/681) yet. But it's a supported extension
226226
that can help developers use more meaningful enumerators.
227227
```json
228228
{
@@ -274,3 +274,7 @@ import { OpenAPI } from './generated';
274274

275275
OpenAPI.TOKEN = 'some-bearer-token';
276276
```
277+
278+
279+
### Compare to other libraries
280+
LINK

samples/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
swagger-codegen-cli-v2.jar
2+
swagger-codegen-cli-v3.jar
3+
examples

samples/README.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Compare to other libraries
2+
3+
Depending on which generator you use, you will see different output. For instance:
4+
Different ways of generating models, services, level of quality, HTTP client, etc.
5+
I've compiled a list below with the results per area and how they compare
6+
against the openapi-typescript-codegen.
7+
8+
I've used the standard petshop examples from OpenAPI:
9+
- https://petstore3.swagger.io/api/v3/openapi.json
10+
- https://petstore.swagger.io/v2/swagger.json
11+
12+
And used the following generators with their default options:
13+
14+
- typescript-aurelia
15+
- typescript-angular
16+
- typescript-inversify
17+
- typescript-angular
18+
- typescript-fetch
19+
- typescript-jquery
20+
- typescript-node
21+
22+
#Results
23+
24+
<table>
25+
<thead>
26+
<tr>
27+
<th></th>
28+
<th>openapi-typscript-codegen</th>
29+
<th>aurelia</th>
30+
<th>inversify</th>
31+
<th>angular</th>
32+
<th>fetch</th>
33+
<th>jquery</th>
34+
<th>node</th>
35+
</tr>
36+
</thead>
37+
<tbody>
38+
<tr>
39+
<th>Supports OpenApi v2 specification</th>
40+
<td>✅</td>
41+
<td>✅</td>
42+
<td>✅</td>
43+
<td>✅</td>
44+
<td>✅</td>
45+
<td>✅</td>
46+
<td>✅</td>
47+
</tr>
48+
<tr>
49+
<th>Supports OpenApi v3 specification</th>
50+
<td>✅</td>
51+
<td>❌</td>
52+
<td>❌</td>
53+
<td>✅</td>
54+
<td>✅</td>
55+
<td>❌</td>
56+
<td>❌</td>
57+
</tr>
58+
<tr>
59+
<th>Supports authentication</th>
60+
<td>✅ Bearer token</td>
61+
<td>❌</td>
62+
<td>✅ Bearer token</td>
63+
<td>✅ Bearer token</td>
64+
<td>✅ Bearer token</td>
65+
<td>✅ Bearer token</td>
66+
<td>✅ Bearer token</td>
67+
</tr>
68+
<tr>
69+
<th>Strongly typed models</th>
70+
<td>✅</td>
71+
<td>✅</td>
72+
<td>✅</td>
73+
<td>✅</td>
74+
<td>✅</td>
75+
<td>✅</td>
76+
<td>✅ Using classes instead of simple interfaces</td>
77+
</tr>
78+
<tr>
79+
<th>Strongly typed enums</th>
80+
<td>✅</td>
81+
<td>✅ No enum is exported</td>
82+
<td>✅</td>
83+
<td>✅ Odd cast to <code>&lt;any&gt</code></td>
84+
<td>✅ Odd cast to <code>&lt;any&gt</code></td>
85+
<td>✅ Odd cast to <code>&lt;any&gt</code></td>
86+
<td>✅ Odd cast to <code>&lt;any&gt</code></td>
87+
</tr>
88+
<tr>
89+
<th>Models and services exported as individual files</th>
90+
<td>✅</td>
91+
<td>❌ All models inside one file</td>
92+
<td>✅</td>
93+
<td>✅</td>
94+
<td>❌ All models and services inside one file</td>
95+
<td>✅</td>
96+
<td>❌ All models and services inside one file</td>
97+
</tr>
98+
<tr>
99+
<th>Index file that exports all services and models</th>
100+
<td>✅</td>
101+
<td>✅</td>
102+
<td>❌</td>
103+
<td>✅</td>
104+
<td>✅</td>
105+
<td>✅</td>
106+
<td>❌</td>
107+
</tr>
108+
<tr>
109+
<th>Service returns typed result</th>
110+
<td>✅</td>
111+
<td>✅</td>
112+
<td>✅</td>
113+
<td>✅</td>
114+
<td>❌</td>
115+
<td>✅</td>
116+
<td>✅</td>
117+
</tr>
118+
<tr>
119+
<th>Service supports sending and receiving binary content</th>
120+
<td>✅</td>
121+
<td>✅</td>
122+
<td>✅</td>
123+
<td>❌ Passing file as application/octet-stream</td>
124+
<td>❌ Passing file as application/octet-stream</td>
125+
<td>✅</td>
126+
<td>✅</td>
127+
</tr>
128+
<tr>
129+
<th>Models and services contain inline documentation</th>
130+
<td>✅</td>
131+
<td>❌</td>
132+
<td>❌</td>
133+
<td>❌</td>
134+
<td>❌</td>
135+
<td>❌</td>
136+
<td>❌</td>
137+
</tr>
138+
<tr>
139+
<th>Framework agnostic</th>
140+
<td>✅</td>
141+
<td>❌ No, using <code>aurelia</code></td>
142+
<td>❌ No, using <code>inversify</code> and <code>rxjs</code></td>
143+
<td>❌ No, using <code>angular</code></td>
144+
<td>✅ But depends on <code>portable-fetch</code></td>
145+
<td>❌ No, using <code>jquery</code></td>
146+
<td>❌ No, can only be used with NodeJS <code>http</code></td>
147+
</tr>
148+
</tbody>
149+
</table>

samples/codegen.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
curl https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.14/swagger-codegen-cli-2.4.14.jar -o swagger-codegen-cli-v2.jar
4+
curl https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.20/swagger-codegen-cli-3.0.20.jar -o swagger-codegen-cli-v3.jar
5+
6+
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-aurelia -o examples/v2/typescript-aurelia/
7+
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-angular -o examples/v2/typescript-angular/
8+
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-inversify -o examples/v2/typescript-inversify/
9+
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-fetch -o examples/v2/typescript-fetch/
10+
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-jquery -o examples/v2/typescript-jquery/
11+
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-node -o examples/v2/typescript-node/
12+
13+
java -jar ./swagger-codegen-cli-v3.jar generate -i v3/spec.json -l typescript-angular -o examples/v3/typescript-angular/
14+
java -jar ./swagger-codegen-cli-v3.jar generate -i v3/spec.json -l typescript-fetch -o examples/v3/typescript-fetch/
15+
16+
node ../bin/index.js --input v2/spec.json --output examples/v2/openapi-typescript-codegen/
17+
node ../bin/index.js --input v3/spec.json --output examples/v3/openapi-typescript-codegen/

0 commit comments

Comments
 (0)