Skip to content

Commit

Permalink
[typescript] Support esbuild, second attempt (OpenAPITools#11465)
Browse files Browse the repository at this point in the history
* Install correct typings for url-parse

* Use es modules compat mode when es6 output is selected

* Consolidate typescript sample generation naming scheme

* Regenerate samples

* Create new typescript sample to test esmodules in browser

* Expose RequiredError type

* Make browser integration tests pass locally

* Remove cookie tests, because we don’t allow cross-origin cookies

* Add output type to package definition

* Execute new browser tests in pipeline

* Install headless chromium dependencies in circle ci
  • Loading branch information
bodograumann authored Apr 6, 2022
1 parent edfb3e1 commit 510f799
Show file tree
Hide file tree
Showing 87 changed files with 12,162 additions and 39 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ commands: # a reusable command with parameters
- source-v2-
# Machine Setup
# If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
- run:
name: Install Headless Chrome dependencies
command: |
sudo apt-get update && sudo apt-get install -yq \
gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \
libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates \
fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm1
# The following `checkout` command checks out your code to your working directory. In 1.0 we did this implicitly. In 2.0 you can choose where in the course of a job your code should be checked out.
- checkout
# Prepare for artifact and test results collection equivalent to how it was done on 1.0.
Expand Down
10 changes: 10 additions & 0 deletions bin/configs/typescript-consolidated-browser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: typescript
outputDir: samples/openapi3/client/petstore/typescript/builds/browser
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript
additionalProperties:
framework: fetch-api
npmName: ts-petstore-client
projectName: ts-petstore-client
moduleName: petstore
supportsES6: true
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Configuration} from '../configuration{{extensionForDeno}}';
import {RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http{{extensionForDeno}}';
{{#platforms}}
{{#node}}
import * as FormData from "form-data";
import {{^supportsES6}}* as{{/supportsES6}} FormData from "form-data";
import { URLSearchParams } from 'url';
{{/node}}
{{/platforms}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// typings for btoa are incorrect
{{#platforms}}
{{#node}}
// typings for btoa are incorrect
//@ts-ignore
import * as btoa from "btoa";
import {{^supportsES6}}* as{{/supportsES6}} btoa from "btoa";
{{/node}}
{{/platforms}}
import { RequestContext } from "../http/http{{extensionForDeno}}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{{#platforms}}
{{#node}}
// TODO: evaluate if we can easily get rid of this library
import * as FormData from "form-data";
import {{^supportsES6}}* as{{/supportsES6}} FormData from "form-data";
import { URLSearchParams } from 'url';
import * as http from 'http';
import * as https from 'https';
{{/node}}
{{/platforms}}
{{#platforms}}
{{^deno}}
// typings of url-parse are incorrect...
// @ts-ignore
import * as URLParse from "url-parse";
import {{^supportsES6}}* as{{/supportsES6}} URLParse from "url-parse";
{{/deno}}
{{/platforms}}
import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub{{extensionForDeno}}'{{/useRxJS}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { createConfiguration } from "./configuration{{extensionForDeno}}"
export{{#platforms}}{{#deno}} type{{/deno}}{{/platforms}} { Configuration } from "./configuration{{extensionForDeno}}"
export * from "./apis/exception{{extensionForDeno}}";
export * from "./servers{{extensionForDeno}}";
export { RequiredError } from "./apis/baseapi{{extensionForDeno}}";

{{#useRxJS}}
export { Middleware } from './middleware{{extensionForDeno}}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
],
"license": "Unlicense",
"main": "./dist/index.js",
{{#supportsES6}}
"type": "module",
"module": "./dist/index.js",
{{/supportsES6}}
{{^supportsES6}}
"type": "commonjs",
{{/supportsES6}}
"exports": {
".": "./dist/index.js"
},
"typings": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
Expand Down Expand Up @@ -51,7 +61,8 @@
"url-parse": "^1.4.3"
},
"devDependencies": {
"typescript": "^3.9.3"
"typescript": "^3.9.3",
"@types/url-parse": "1.4.4"
}{{#npmRepository}},{{/npmRepository}}
{{#npmRepository}}
"publishConfig":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
"compilerOptions": {
"strict": true,
/* Basic Options */
"target": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}es5{{/supportsES6}}",
"module": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}commonjs{{/supportsES6}}",
{{#supportsES6}}
"target": "es6",
"esModuleInterop": true,
{{/supportsES6}}
{{^supportsES6}}
"target": "es5",
{{/supportsES6}}
"moduleResolution": "node",
"declaration": true,

Expand Down
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,18 @@
<module>samples/openapi3/client/petstore/typescript/tests/jquery</module>
</modules>
</profile>
<profile>
<id>typescript-client-tests-browser</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/openapi3/client/petstore/typescript/tests/browser</module>
</modules>
</profile>
<profile>
<id>typescript-fetch-client-tests-default</id>
<activation>
Expand Down Expand Up @@ -1205,6 +1217,8 @@
<!-- comment out due to failure in travis ci
<module>samples/openapi3/client/petstore/typescript/tests/inversify</module>
<module>samples/openapi3/client/petstore/typescript/tests/deno</module>-->
<module>samples/openapi3/client/petstore/typescript/builds/browser</module>
<module>samples/openapi3/client/petstore/typescript/tests/browser</module>
<module>samples/client/petstore/typescript-fetch/builds/default</module>
<module>samples/client/petstore/typescript-fetch/builds/es6-target</module>
<module>samples/client/petstore/typescript-fetch/builds/with-npm-version</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// typings for btoa are incorrect
import { RequestContext } from "../http/http";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// typings of url-parse are incorrect...
// @ts-ignore
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { createConfiguration } from "./configuration"
export { Configuration } from "./configuration"
export * from "./apis/exception";
export * from "./servers";
export { RequiredError } from "./apis/baseapi";

export { PromiseMiddleware as Middleware } from './middleware';
export { PromiseDefaultApi as DefaultApi } from './types/PromiseAPI';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
],
"license": "Unlicense",
"main": "./dist/index.js",
"type": "commonjs",
"exports": {
".": "./dist/index.js"
},
"typings": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
Expand All @@ -22,6 +26,7 @@
"url-parse": "^1.4.3"
},
"devDependencies": {
"typescript": "^3.9.3"
"typescript": "^3.9.3",
"@types/url-parse": "1.4.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"strict": true,
/* Basic Options */
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.gitignore
PetApi.md
README.md
StoreApi.md
UserApi.md
apis/PetApi.ts
apis/StoreApi.ts
apis/UserApi.ts
apis/baseapi.ts
apis/exception.ts
auth/auth.ts
configuration.ts
git_push.sh
http/http.ts
http/isomorphic-fetch.ts
index.ts
middleware.ts
models/ApiResponse.ts
models/Category.ts
models/ObjectSerializer.ts
models/Order.ts
models/Pet.ts
models/Tag.ts
models/User.ts
models/all.ts
package.json
rxjsStub.ts
servers.ts
tsconfig.json
types/ObjectParamAPI.ts
types/ObservableAPI.ts
types/PromiseAPI.ts
util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.0.0-SNAPSHOT
Loading

0 comments on commit 510f799

Please sign in to comment.