Add Deno support to typescript(experimental) generator#6732
Add Deno support to typescript(experimental) generator#6732macjohnny merged 12 commits intoOpenAPITools:masterfrom chibat:deno
Conversation
TiFu
left a comment
There was a problem hiding this comment.
Thanks for the PR! I have some questions and potentially one small change request - see my comments in the code.
...napi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java
Show resolved
Hide resolved
| private headers: { [key: string]: string } = {}; | ||
| private body: RequestBody = undefined; | ||
| private url: URLParse; | ||
| private url: {{#platforms}}{{#deno}}URL{{/deno}}{{^deno}}URLParse{{/deno}}{{/platforms}}; |
There was a problem hiding this comment.
Could we instead create a separate module that wraps deno's URL and provides a URLParse like interface?
We could then import this module instead of adding all of these conditions.
There was a problem hiding this comment.
I understand. I try it.
There was a problem hiding this comment.
Why do we use URLParse (external dependency) at all? Node provides whatwg-compatible URL (https://nodejs.org/docs/latest-v12.x/api/url.html#url_class_url), as well as modern browsers.
There was a problem hiding this comment.
We are using url-parse to support IE ?
If we want to support IE, is it better to use URLSearchParams Polyfill ?
There was a problem hiding this comment.
I think we had this discussion in one of the PRs of the original generator. I think the decision was based on url-parse being easier to use compared to the polyfill. url-parse also only has two dependencies (including recursive dependencies).
Open to replacing url-parse in the browser as long as we hide it behind an interface. @bodograumann similarly added a workaround for uploading files in IE.
There was a problem hiding this comment.
The question for me is, where do we draw the line?
We could use Blob.text(), as it is a WebAPI, but it is not supported in lots of browsers.
Then there is URLSearchParams.
And of course fetch API.
When someone generates the code, they don't know which polyfills they need to get it running in a certain set of browsers. In my experience babel does not automatically add polyfills for (most of) these things.
I think it is a complex issue and maybe you can open a separate issue, @amakhrov. I would love to discuss the details.
There was a problem hiding this comment.
This time, I have created URLParse wrapper for Deno.
Type of URLParse is complex..
I have replaced instantiating from a function call to new.
There was a problem hiding this comment.
I agree with @bodograumann - let's discuss how we want to proceed. I'd prefer something that just works out of the box in the targeted environment - be it node or browsers or deno.
There was a problem hiding this comment.
Users must have a choice. Right now we force them to depend on a specific polyfill, regardless on the platform they target
|
Could you also please run |
| @@ -1,41 +1,45 @@ | |||
| {{#platforms}} | |||
| {{^deno}} | |||
| import "es6-promise/auto"; | |||
There was a problem hiding this comment.
Also curious why we enforce this polyfill instead of delegating that to the end consumer (which might already have a different polyfill in their app!)
It's not a comment about this PR, though - it's actually about the typescript generator already in master :)
There was a problem hiding this comment.
I remove it and try running the integration test.
| import { RequestContext } from "../http/http"; | ||
| import { RequestContext } from "../http/http{{#platforms}}{{#deno}}.ts{{/deno}}{{/platforms}}"; | ||
| {{#useInversify}} | ||
| import { injectable, inject, named } from "inversify"; |
There was a problem hiding this comment.
looks like there is no intention to support inversify on the Deno platform - is that so?
There was a problem hiding this comment.
Yes. Inversify may work on Deno. But I think it's probably not easy.
There was a problem hiding this comment.
Why would it be difficult to add?
If we can't support inversify on deno, could you please document that in the inversify option?
There was a problem hiding this comment.
I have checked that if we can use Inversify on Deno.
Deno Third Party Modules
Inversify is not listed in Deno Third Party Modules.
Pika
https://www.pika.dev/search?q=inversify
message: "Package found! However, no web-optimized "module" entrypoint was found in its package.json manifest."
jspm
$ cat inversify_sample.ts
import "https://jspm.dev/reflect-metadata";
// @deno-types="https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/inversify.d.ts"
import { Container, injectable } from "https://jspm.dev/inversify@5.0.1";
var container = new Container();
$ ~/data/work$ deno run --reload -c tsconfig.json inversify_sample.ts
Download https://jspm.dev/reflect-metadata
Download https://jspm.dev/inversify@5.0.1
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/inversify.d.ts
Download https://jspm.dev/npm:inversify@5.0.1/_/2b7febed.js
Download https://jspm.dev/npm:inversify@5.0.1/_/2e4eea2e.js
Download https://jspm.dev/npm:inversify@5.0.1/_/d819b7b6.js
Download https://jspm.dev/npm:inversify@5.0.1/_/8b88d942.js
Download https://jspm.dev/npm:inversify@5.0.1!cjs
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/constants/metadata_keys
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/container/container
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/constants/literal_types
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/container/container_module
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/injectable
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/tagged
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/named
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/inject
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/optional
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/unmanaged
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/multi_inject
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/target_name
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/post_construct
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/planning/metadata_reader
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/utils/id
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/interfaces/interfaces
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/annotation/decorator_utils
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/syntax/constraint_helpers
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/utils/serialization
Download https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/utils/binding_utils
Download https://jspm.dev/npm:@jspm/core@2/nodelibs/process
Download https://jspm.dev/npm:reflect-metadata@0.1.13!cjs
Download https://jspm.dev/npm:@jspm/core@2.0.0-beta.7/_/de9a8dfb.js
error: Import 'https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/utils/binding_utils' failed: 404 Not Found
Imported from "https://cdn.jsdelivr.net/npm/inversify@5.0.1/dts/inversify.d.ts:21"
$ echo $?
1
Inversify may work on Deno via jspm. But I couldn't load the Type Definition file.
Inversify may officially support Deno in the future.
At the moment, I think it's better not to support by openapi-generator yet.
This time, I added a description to the documentation that it is not currently supported.
| {{#frameworks}} | ||
| {{#fetch-api}} | ||
| export * from './isomorphic-fetch'; | ||
| export * from './isomorphic-fetch{{#platforms}}{{#deno}}.ts{{/deno}}{{/platforms}}'; |
There was a problem hiding this comment.
this change looks redundant, since this whole line is not generated for Deno (which uses a built-in fetch anyway)
modules/openapi-generator/src/main/resources/typescript/api/api.mustache
Outdated
Show resolved
Hide resolved
|
anyone against merging this so it will be part of the 5.0.0 release? |
|
Thanks for your contribution, @chibat One small note: |
|
Thanks for your reviews.
Sorry.. I'll be careful. |
This PR add Deno support to typescript(experimental) generator.
closes #3174
PR checklist
./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/config/java*. For Windows users, please run the script in Git BASH.master@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02)