Skip to content

Commit 1f27700

Browse files
authored
Add Deno support to typescript(experimental) generator (#6732)
* add 'deno' to typescript platforms * add Deno support to typescript generator * add Deno support to typescript generator * add Deno support to typescript generator * add Deno support to typescript generator * add Deno support to typescript generator * add extensionForDeno property for typescript generator * add URLParse Deno wrapper for typescript generator * update deno version in .travis.yml
1 parent f114294 commit 1f27700

65 files changed

Lines changed: 4637 additions & 96 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ cache:
4545
- $HOME/.npm
4646
- $HOME/.rvm/gems/ruby-2.4.1
4747
- $HOME/website/node_modules/
48+
- $HOME/.cache/deno
4849

4950
services:
5051
- docker
@@ -119,6 +120,9 @@ before_install:
119120
gpg --check-trustdb ;
120121
fi;
121122
- pushd .; cd website; yarn install; popd
123+
# install Deno
124+
- curl -fsSL https://deno.land/x/install/install.sh | sh -s v1.1.2
125+
- export PATH="$HOME/.deno/bin:$PATH"
122126

123127
install:
124128
# Add Godeps dependencies to GOPATH and PATH

bin/typescript.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ java $JAVA_OPTS -jar $executable $common_args $args
4545
printf "\033[32m## Creating fetch client with InversifyJS support!\033[0m\n"
4646
args="-o $samples/inversify --additional-properties=platform=node,npmName=ts-petstore-client,useInversify=true $@"
4747
java $JAVA_OPTS -jar $executable $common_args $args
48+
49+
printf "\033[32m## Creating Deno (fetch) client!\033[0m\n"
50+
args="-o $samples/deno --additional-properties=platform=deno $@"
51+
java $JAVA_OPTS -jar $executable $common_args $args

bin/windows/typescript.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ java %JAVA_OPTS% -jar %executable% %args%
1717

1818
set args=generate -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g typescript -o samples\openapi3\client\petstore\typescript\builds\inversify --additional-properties=platform=node,npmName=ts-petstore-client,useInversify
1919
java %JAVA_OPTS% -jar %executable% %args%
20+
21+
set args=generate -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g typescript -o samples\openapi3\client\petstore\typescript\builds\deno --additional-properties=platform=deno
22+
java %JAVA_OPTS% -jar %executable% %args%

docs/generators/typescript.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ sidebar_label: typescript
88
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
99
|disallowAdditionalPropertiesIfNotPresent|Specify the behavior when the 'additionalProperties' keyword is not present in the OAS document. If false: the 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications. If true: when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.This setting is currently ignored for OAS 2.0 documents: 1) When the 'additionalProperties' keyword is not present in a 2.0 schema, additional properties are NOT allowed. 2) Boolean values of the 'additionalProperties' keyword are ignored. It's as if additional properties are NOT allowed.Note: the root cause are issues #1369 and #1371, which must be resolved in the swagger-parser project.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>when the 'additionalProperties' keyword is not present in a schema, the value of 'additionalProperties' is automatically set to false, i.e. no additional properties are allowed. Note: this mode is not compliant with the JSON schema specification. This is the original openapi-generator behavior.</dd></dl>|true|
1010
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
11-
|fileContentDataType|Specifies the type to use for the content of a file - i.e. Blob (Browser) / Buffer (node)| |Buffer|
11+
|fileContentDataType|Specifies the type to use for the content of a file - i.e. Blob (Browser, Deno) / Buffer (node)| |Buffer|
1212
|framework|Specify the framework which should be used in the client code.|<dl><dt>**fetch-api**</dt><dd>fetch-api</dd><dt>**jquery**</dt><dd>jquery</dd></dl>|fetch-api|
1313
|legacyDiscriminatorBehavior|This flag is used by OpenAPITools codegen to influence the processing of the discriminator attribute in OpenAPI documents. This flag has no impact if the OAS document does not use the discriminator attribute. The default value of this flag is set in each language-specific code generator (e.g. Python, Java, go...)using the method toModelName. Note to developers supporting a language generator in OpenAPITools; to fully support the discriminator attribute as defined in the OAS specification 3.x, language generators should set this flag to true by default; however this requires updating the mustache templates to generate a language-specific discriminator lookup function that iterates over {{#mappedModels}} and does not iterate over {{children}}, {{#anyOf}}, or {{#oneOf}}.|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
1414
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
1515
|npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null|
1616
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
1717
|npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0|
18-
|platform|Specifies the platform the code should run on. The default is 'node' for the 'request' framework and 'browser' otherwise.|<dl><dt>**browser**</dt><dd>browser</dd><dt>**node**</dt><dd>node</dd></dl>|browser|
18+
|platform|Specifies the platform the code should run on. The default is 'node' for the 'request' framework and 'browser' otherwise.|<dl><dt>**browser**</dt><dd>browser</dd><dt>**node**</dt><dd>node</dd><dt>**deno**</dt><dd>deno</dd></dl>|browser|
1919
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
2020
|snapshot|When setting this property to true, the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm| |false|
2121
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
2222
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
2323
|supportsES6|Generate code that conforms to ES6.| |false|
24-
|useInversify|Enable this to generate decorators and service identifiers for the InversifyJS inversion of control container.| |false|
24+
|useInversify|Enable this to generate decorators and service identifiers for the InversifyJS inversion of control container. If you set 'deno' as 'platform', the generator will process this value as 'disable'.| |false|
2525
|useObjectParameters|Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument.| |false|
2626
|useRxJS|Enable this to internally use rxjs observables. If disabled, a stub is used instead. This is required for the 'angular' framework.| |false|
2727

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
5151
private static final String[] FRAMEWORKS = { "fetch-api", "jquery" };
5252
private static final String PLATFORM_SWITCH = "platform";
5353
private static final String PLATFORM_SWITCH_DESC = "Specifies the platform the code should run on. The default is 'node' for the 'request' framework and 'browser' otherwise.";
54-
private static final String[] PLATFORMS = { "browser", "node" };
54+
private static final String[] PLATFORMS = { "browser", "node", "deno" };
5555
private static final String FILE_CONTENT_DATA_TYPE= "fileContentDataType";
56-
private static final String FILE_CONTENT_DATA_TYPE_DESC = "Specifies the type to use for the content of a file - i.e. Blob (Browser) / Buffer (node)";
56+
private static final String FILE_CONTENT_DATA_TYPE_DESC = "Specifies the type to use for the content of a file - i.e. Blob (Browser, Deno) / Buffer (node)";
5757
private static final String USE_RXJS_SWITCH = "useRxJS";
5858
private static final String USE_RXJS_SWITCH_DESC = "Enable this to internally use rxjs observables. If disabled, a stub is used instead. This is required for the 'angular' framework.";
5959
private static final String USE_INVERSIFY_SWITCH = "useInversify";
60-
private static final String USE_INVERSIFY_SWITCH_DESC = "Enable this to generate decorators and service identifiers for the InversifyJS inversion of control container.";
60+
private static final String USE_INVERSIFY_SWITCH_DESC = "Enable this to generate decorators and service identifiers for the InversifyJS inversion of control container. If you set 'deno' as 'platform', the generator will process this value as 'disable'.";
6161

6262
private static final String USE_OBJECT_PARAMS_SWITCH = "useObjectParameters";
6363
private static final String USE_OBJECT_PARAMS_DESC = "Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument.";
@@ -187,10 +187,7 @@ public TypeScriptClientCodegen() {
187187

188188
cliOptions.add(platformOption);
189189

190-
//Documentation
191-
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
192-
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
193-
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
190+
// Git
194191
supportingFiles.add(new SupportingFile(".gitignore.mustache", "", ".gitignore"));
195192
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
196193

@@ -792,6 +789,16 @@ public void processOpts() {
792789

793790
additionalProperties.putIfAbsent(FILE_CONTENT_DATA_TYPE, propPlatform.equals("node") ? "Buffer" : "Blob");
794791

792+
if (!propPlatform.equals("deno")) {
793+
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
794+
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
795+
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
796+
}
797+
798+
if (propPlatform.equals("deno")) {
799+
additionalProperties.put("extensionForDeno", ".ts");
800+
}
801+
795802
final boolean useRxJS = convertPropertyToBooleanAndWriteBack(USE_RXJS_SWITCH);
796803
if (!useRxJS) {
797804
supportingFiles.add(new SupportingFile("rxjsStub.mustache", "rxjsStub.ts"));

modules/openapi-generator/src/main/resources/typescript/api/api.mustache

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// TODO: better import syntax?
2-
import { BaseAPIRequestFactory, RequiredError } from './baseapi';
3-
import {Configuration} from '../configuration';
4-
import { RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http';
2+
import { BaseAPIRequestFactory, RequiredError } from './baseapi{{extensionForDeno}}';
3+
import {Configuration} from '../configuration{{extensionForDeno}}';
4+
import { RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http{{extensionForDeno}}';
55
{{#platforms}}
66
{{#node}}
77
import * as FormData from "form-data";
88
{{/node}}
99
{{/platforms}}
10-
import {ObjectSerializer} from '../models/ObjectSerializer';
11-
import {ApiException} from './exception';
12-
import {isCodeInRange} from '../util';
10+
import {ObjectSerializer} from '../models/ObjectSerializer{{extensionForDeno}}';
11+
import {ApiException} from './exception{{extensionForDeno}}';
12+
import {isCodeInRange} from '../util{{extensionForDeno}}';
1313
{{#useInversify}}
1414
import { injectable } from "inversify";
1515
{{/useInversify}}
1616

1717
{{#imports}}
18-
import { {{classname}} } from '..{{filename}}';
18+
import { {{classname}} } from '..{{filename}}{{extensionForDeno}}';
1919
{{/imports}}
2020
{{#operations}}
2121

@@ -102,9 +102,9 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
102102
{{#node}}
103103
localVarFormParams.append('{{baseName}}', {{paramName}}.data, {{paramName}}.name);
104104
{{/node}}
105-
{{#browser}}
105+
{{^node}}
106106
localVarFormParams.append('{{baseName}}', {{paramName}}, {{paramName}}.name);
107-
{{/browser}}
107+
{{/node}}
108108
{{/platforms}}
109109
{{/isFile}}
110110
}

modules/openapi-generator/src/main/resources/typescript/api/baseapi.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Configuration } from '../configuration'
1+
import { Configuration } from '../configuration{{extensionForDeno}}'
22
{{#useInversify}}
33
import { injectable, inject } from "inversify";
44
import { AbstractConfiguration } from "../services/configuration";

modules/openapi-generator/src/main/resources/typescript/api/middleware.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {RequestContext, ResponseContext} from './http/http';
2-
import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'./rxjsStub'{{/useRxJS}};
1+
import {RequestContext, ResponseContext} from './http/http{{extensionForDeno}}';
2+
import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'./rxjsStub{{extensionForDeno}}'{{/useRxJS}};
33

44
/**
55
* Defines the contract for a middleware intercepting requests before

modules/openapi-generator/src/main/resources/typescript/auth/auth.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as btoa from "btoa";
66
{{/node}}
77
{{/platforms}}
8-
import { RequestContext } from "../http/http";
8+
import { RequestContext } from "../http/http{{extensionForDeno}}";
99
{{#useInversify}}
1010
import { injectable, inject, named } from "inversify";
1111
import { AbstractTokenProvider } from "../services/configuration";

modules/openapi-generator/src/main/resources/typescript/configuration.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { HttpLibrary } from "./http/http";
2-
import { Middleware, PromiseMiddleware, PromiseMiddlewareWrapper } from "./middleware";
1+
import { HttpLibrary } from "./http/http{{extensionForDeno}}";
2+
import { Middleware, PromiseMiddleware, PromiseMiddlewareWrapper } from "./middleware{{extensionForDeno}}";
33
{{#frameworks}}
44
{{#fetch-api}}
5-
import { IsomorphicFetchHttpLibrary as DefaultHttpLibrary } from "./http/isomorphic-fetch";
5+
import { IsomorphicFetchHttpLibrary as DefaultHttpLibrary } from "./http/isomorphic-fetch{{extensionForDeno}}";
66
{{/fetch-api}}
77
{{#jquery}}
88
import { JQueryHttpLibrary as DefaultHttpLibrary } from "./http/jquery";
99
{{/jquery}}
1010
{{/frameworks}}
11-
import { BaseServerConfiguration, server1 } from "./servers";
12-
import { configureAuthMethods, AuthMethods, AuthMethodsConfiguration } from "./auth/auth";
11+
import { BaseServerConfiguration, server1 } from "./servers{{extensionForDeno}}";
12+
import { configureAuthMethods, AuthMethods, AuthMethodsConfiguration } from "./auth/auth{{extensionForDeno}}";
1313

1414
export interface Configuration {
1515
readonly baseServer: BaseServerConfiguration;

0 commit comments

Comments
 (0)