From 20eb1ff0340936478d90fbb31789a915339c44cc Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Fri, 19 Jun 2020 23:01:12 +0200 Subject: [PATCH] - Fixed issue with anyOf --- README.md | 2 +- package.json | 2 +- samples/codegen.sh | 4 ---- samples/{README.html => index.html} | 35 ++++++++++++++++++++--------- src/openApi/v3/parser/getModel.ts | 7 ++++-- 5 files changed, 32 insertions(+), 18 deletions(-) rename samples/{README.html => index.html} (92%) diff --git a/README.md b/README.md index dfea185c..5c4a2ff2 100644 --- a/README.md +++ b/README.md @@ -277,4 +277,4 @@ OpenAPI.TOKEN = 'some-bearer-token'; ### Compare to other libraries -https://htmlpreview.github.io/?https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/samples/README.html +[samples/README.html](https://htmlpreview.github.io/?https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/samples/README.html) diff --git a/package.json b/package.json index 19bc2485..0853e084 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-typescript-codegen", - "version": "0.4.5", + "version": "0.4.6", "description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", "homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen", diff --git a/samples/codegen.sh b/samples/codegen.sh index e1ef1264..cf9574df 100755 --- a/samples/codegen.sh +++ b/samples/codegen.sh @@ -20,7 +20,3 @@ echo v3/openapi-typescript-codegen && time node ../bin/index.js --input v3/spec. yarn install yarn run build - -cd examples -find . -type f ! -iname "*.ts" -delete -cd ../ diff --git a/samples/README.html b/samples/index.html similarity index 92% rename from samples/README.html rename to samples/index.html index 1addbbef..bff0d41f 100644 --- a/samples/README.html +++ b/samples/index.html @@ -8,6 +8,11 @@ Compared to other generators +
@@ -137,14 +142,16 @@ ✅ ✅ + ⚠️
- ⚠️ + Details

V3 version sends data as application/octet-stream instead of application/x-www-form-urlencoded

+ ⚠️
- ⚠️ + Details

V3 version sends data as application/octet-stream instead of application/x-www-form-urlencoded

@@ -168,15 +175,17 @@ ❌ ❌ + ⚠️
- ⚠️ + Details

Requires portable-fetch

❌ + ⚠️
- ⚠️ + Details

Requires bluebird

@@ -185,38 +194,44 @@ Compiles in strict mode without issues ✅ +
- + Details

Errors when compiling: PetApi.ts:147:30 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'

+
- + Details

Errors when compiling: pet.service.ts:312:159 - error TS2304: Cannot find name 'body'

+
- + Details

Errors when compiling: pet.service.ts:528:26 - error TS1345: An expression of type 'void' cannot be tested for truthiness

+
- + Details

Errors when compiling: api.ts:2276:67 - error TS2300: Duplicate identifier 'username'

+
- + Details

Errors when compiling: PetApi.ts:25:12 - error TS2322: Type 'null' is not assignable to type 'JQueryAjaxSettings | undefined'

+
- + Details

Errors when compiling: api.ts:1631:45 - error TS2694: Namespace '"http"' has no exported member 'ClientResponse'

diff --git a/src/openApi/v3/parser/getModel.ts b/src/openApi/v3/parser/getModel.ts index b0251ce0..050624b3 100644 --- a/src/openApi/v3/parser/getModel.ts +++ b/src/openApi/v3/parser/getModel.ts @@ -114,7 +114,10 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti } } - if (definition.anyOf && definition.anyOf.length) { + // TODO: Add correct support for oneOf, anyOf, allOf + // TODO: https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/ + + if (definition.anyOf && definition.anyOf.length && !definition.properties) { model.export = 'generic'; const compositionTypes = definition.anyOf.filter(type => type.$ref).map(type => getType(type.$ref)); const composition = compositionTypes @@ -127,7 +130,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, isDefiniti return model; } - if (definition.oneOf && definition.oneOf.length) { + if (definition.oneOf && definition.oneOf.length && !definition.properties) { model.export = 'generic'; const compositionTypes = definition.oneOf.filter(type => type.$ref).map(type => getType(type.$ref)); const composition = compositionTypes