mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Added tests for compare
This commit is contained in:
parent
8ce9e97f98
commit
a60014c2b1
12
README.md
12
README.md
@ -20,7 +20,7 @@
|
||||
## Known issues:
|
||||
- If you use enums inside your models / definitions then those enums are now
|
||||
inside a namespace with the same name as your model. This is called declaration
|
||||
merging. However Babel 7 now support compiling of Typescript and right now they
|
||||
merging. However, Babel 7 now support compiling of Typescript and right now they
|
||||
do not support namespaces.
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ createUser({
|
||||
|
||||
### Runtime schemas
|
||||
By default the OpenAPI generator only exports interfaces for your models. These interfaces will help you during
|
||||
development, but will not be available in javascript during runtime. However Swagger allows you to define properties
|
||||
development, but will not be available in javascript during runtime. However, Swagger allows you to define properties
|
||||
that can be useful during runtime, for instance: `maxLength` of a string or a `pattern` to match, etc. Let's say
|
||||
we have the following model:
|
||||
|
||||
@ -158,7 +158,7 @@ export interface MyModel {
|
||||
}
|
||||
```
|
||||
|
||||
The interface does not contain any properties like `maxLength` or `pattern`. However they could be useful
|
||||
The interface does not contain any properties like `maxLength` or `pattern`. However, they could be useful
|
||||
if we wanted to create some form where a user could create such a model. In that form you would iterate
|
||||
over the properties to render form fields based on their type and validate the input based on the `maxLength`
|
||||
or `pattern` property. This requires us to have this information somewhere... For this we can use the
|
||||
@ -222,7 +222,7 @@ const MyForm = () => (
|
||||
|
||||
### Enum with custom names and descriptions
|
||||
You can use `x-enum-varnames` and `x-enum-descriptions` in your spec to generate enum with custom names and descriptions.
|
||||
It's not in official [spec](https://github.com/OAI/OpenAPI-Specification/issues/681) yet. But its a supported extension
|
||||
It's not in official [spec](https://github.com/OAI/OpenAPI-Specification/issues/681) yet. But it's a supported extension
|
||||
that can help developers use more meaningful enumerators.
|
||||
```json
|
||||
{
|
||||
@ -274,3 +274,7 @@ import { OpenAPI } from './generated';
|
||||
|
||||
OpenAPI.TOKEN = 'some-bearer-token';
|
||||
```
|
||||
|
||||
|
||||
### Compare to other libraries
|
||||
LINK
|
||||
|
||||
3
samples/.gitignore
vendored
Normal file
3
samples/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
swagger-codegen-cli-v2.jar
|
||||
swagger-codegen-cli-v3.jar
|
||||
examples
|
||||
149
samples/README.md
Normal file
149
samples/README.md
Normal file
@ -0,0 +1,149 @@
|
||||
# Compare to other libraries
|
||||
|
||||
Depending on which generator you use, you will see different output. For instance:
|
||||
Different ways of generating models, services, level of quality, HTTP client, etc.
|
||||
I've compiled a list below with the results per area and how they compare
|
||||
against the openapi-typescript-codegen.
|
||||
|
||||
I've used the standard petshop examples from OpenAPI:
|
||||
- https://petstore3.swagger.io/api/v3/openapi.json
|
||||
- https://petstore.swagger.io/v2/swagger.json
|
||||
|
||||
And used the following generators with their default options:
|
||||
|
||||
- typescript-aurelia
|
||||
- typescript-angular
|
||||
- typescript-inversify
|
||||
- typescript-angular
|
||||
- typescript-fetch
|
||||
- typescript-jquery
|
||||
- typescript-node
|
||||
|
||||
#Results
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>openapi-typscript-codegen</th>
|
||||
<th>aurelia</th>
|
||||
<th>inversify</th>
|
||||
<th>angular</th>
|
||||
<th>fetch</th>
|
||||
<th>jquery</th>
|
||||
<th>node</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Supports OpenApi v2 specification</th>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Supports OpenApi v3 specification</th>
|
||||
<td>✅</td>
|
||||
<td>❌</td>
|
||||
<td>❌</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>❌</td>
|
||||
<td>❌</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Supports authentication</th>
|
||||
<td>✅ Bearer token</td>
|
||||
<td>❌</td>
|
||||
<td>✅ Bearer token</td>
|
||||
<td>✅ Bearer token</td>
|
||||
<td>✅ Bearer token</td>
|
||||
<td>✅ Bearer token</td>
|
||||
<td>✅ Bearer token</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Strongly typed models</th>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅ Using classes instead of simple interfaces</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Strongly typed enums</th>
|
||||
<td>✅</td>
|
||||
<td>✅ No enum is exported</td>
|
||||
<td>✅</td>
|
||||
<td>✅ Odd cast to <code><any></code></td>
|
||||
<td>✅ Odd cast to <code><any></code></td>
|
||||
<td>✅ Odd cast to <code><any></code></td>
|
||||
<td>✅ Odd cast to <code><any></code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Models and services exported as individual files</th>
|
||||
<td>✅</td>
|
||||
<td>❌ All models inside one file</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>❌ All models and services inside one file</td>
|
||||
<td>✅</td>
|
||||
<td>❌ All models and services inside one file</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Index file that exports all services and models</th>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>❌</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>❌</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Service returns typed result</th>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>❌</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Service supports sending and receiving binary content</th>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
<td>❌ Passing file as application/octet-stream</td>
|
||||
<td>❌ Passing file as application/octet-stream</td>
|
||||
<td>✅</td>
|
||||
<td>✅</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Models and services contain inline documentation</th>
|
||||
<td>✅</td>
|
||||
<td>❌</td>
|
||||
<td>❌</td>
|
||||
<td>❌</td>
|
||||
<td>❌</td>
|
||||
<td>❌</td>
|
||||
<td>❌</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Framework agnostic</th>
|
||||
<td>✅</td>
|
||||
<td>❌ No, using <code>aurelia</code></td>
|
||||
<td>❌ No, using <code>inversify</code> and <code>rxjs</code></td>
|
||||
<td>❌ No, using <code>angular</code></td>
|
||||
<td>✅ But depends on <code>portable-fetch</code></td>
|
||||
<td>❌ No, using <code>jquery</code></td>
|
||||
<td>❌ No, can only be used with NodeJS <code>http</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
17
samples/codegen.sh
Executable file
17
samples/codegen.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-aurelia -o examples/v2/typescript-aurelia/
|
||||
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-angular -o examples/v2/typescript-angular/
|
||||
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-inversify -o examples/v2/typescript-inversify/
|
||||
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-fetch -o examples/v2/typescript-fetch/
|
||||
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-jquery -o examples/v2/typescript-jquery/
|
||||
java -jar ./swagger-codegen-cli-v2.jar generate -i v2/spec.json -l typescript-node -o examples/v2/typescript-node/
|
||||
|
||||
java -jar ./swagger-codegen-cli-v3.jar generate -i v3/spec.json -l typescript-angular -o examples/v3/typescript-angular/
|
||||
java -jar ./swagger-codegen-cli-v3.jar generate -i v3/spec.json -l typescript-fetch -o examples/v3/typescript-fetch/
|
||||
|
||||
node ../bin/index.js --input v2/spec.json --output examples/v2/openapi-typescript-codegen/
|
||||
node ../bin/index.js --input v3/spec.json --output examples/v3/openapi-typescript-codegen/
|
||||
1054
samples/v2/spec.json
Normal file
1054
samples/v2/spec.json
Normal file
File diff suppressed because it is too large
Load Diff
1225
samples/v3/spec.json
Normal file
1225
samples/v3/spec.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,11 +0,0 @@
|
||||
If you want to generate and compare the output of the
|
||||
`openapi-typescript-codegen` vs the official `swagger-codegen`.
|
||||
Then the easiest way to do this is to install the swagger codegen
|
||||
using Homebrew:
|
||||
|
||||
```shell script
|
||||
brew cask install homebrew/cask-versions/adoptopenjdk8
|
||||
brew install swagger-codegen
|
||||
./codegen.sh
|
||||
```
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
swagger-codegen generate --input-spec v2/spec.json --lang java --output examples/v2/java/
|
||||
swagger-codegen generate --input-spec v2/spec.json --lang typescript-angular --output examples/v2/typescript-angular/
|
||||
swagger-codegen generate --input-spec v2/spec.json --lang javascript --output examples/v2/javascript/
|
||||
|
||||
swagger-codegen generate --input-spec v3/spec.json --lang java --output examples/v3/java/
|
||||
swagger-codegen generate --input-spec v3/spec.json --lang typescript-angular --output examples/v3/typescript-angular/
|
||||
swagger-codegen generate --input-spec v3/spec.json --lang javascript --output examples/v3/javascript/
|
||||
Loading…
x
Reference in New Issue
Block a user