-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Deno support to typescript(experimental) generator #6732
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -66,7 +74,7 @@ export type RequestBody = undefined | string | FormData; | |||
export class RequestContext { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand. I try it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove it and try running the integration test.
@@ -5,7 +5,7 @@ | |||
import * as btoa from "btoa"; | |||
{{/node}} | |||
{{/platforms}} | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like there is no intention to support inversify on the Deno platform - is that so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Inversify may work on Deno. But I think it's probably not easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/[email protected]/dts/inversify.d.ts"
import { Container, injectable } from "https://jspm.dev/[email protected]";
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/[email protected]
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/inversify.d.ts
Download https://jspm.dev/npm:[email protected]/_/2b7febed.js
Download https://jspm.dev/npm:[email protected]/_/2e4eea2e.js
Download https://jspm.dev/npm:[email protected]/_/d819b7b6.js
Download https://jspm.dev/npm:[email protected]/_/8b88d942.js
Download https://jspm.dev/npm:[email protected]!cjs
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/constants/metadata_keys
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/container/container
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/constants/literal_types
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/container/container_module
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/injectable
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/tagged
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/named
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/inject
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/optional
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/unmanaged
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/multi_inject
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/target_name
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/post_construct
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/planning/metadata_reader
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/utils/id
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/interfaces/interfaces
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/annotation/decorator_utils
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/syntax/constraint_helpers
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/utils/serialization
Download https://cdn.jsdelivr.net/npm/[email protected]/dts/utils/binding_utils
Download https://jspm.dev/npm:@jspm/core@2/nodelibs/process
Download https://jspm.dev/npm:[email protected]!cjs
Download https://jspm.dev/npm:@jspm/[email protected]/_/de9a8dfb.js
error: Import 'https://cdn.jsdelivr.net/npm/[email protected]/dts/utils/binding_utils' failed: 404 Not Found
Imported from "https://cdn.jsdelivr.net/npm/[email protected]/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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change looks redundant, since this whole line is not generated for Deno (which uses a built-in fetch
anyway)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I fixed.
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.sh
to 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)