Skip to content
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

Merged
merged 12 commits into from
Jun 27, 2020
Merged

Add Deno support to typescript(experimental) generator #6732

merged 12 commits into from
Jun 27, 2020

Conversation

chibat
Copy link
Contributor

@chibat chibat commented Jun 21, 2020

This PR add Deno support to typescript(experimental) generator.
closes #3174

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./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.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@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)

Copy link
Contributor

@TiFu TiFu left a 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.

@@ -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}};
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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 ?

Copy link
Contributor

@TiFu TiFu Jun 23, 2020

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amakhrov I absolutely agree! @TiFu would you mind removing the polyfills before the 5.0.0 release?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@amakhrov amakhrov Jun 27, 2020

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

@TiFu
Copy link
Contributor

TiFu commented Jun 21, 2020

Could you also please run ./bin/utils/export_docs_generator.sh to update the documentation of the generator? (that's what circleci is complaining about)

@@ -1,41 +1,45 @@
{{#platforms}}
{{^deno}}
import "es6-promise/auto";
Copy link
Contributor

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 :)

Copy link
Contributor Author

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";
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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}}';
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I fixed.

@chibat chibat marked this pull request as ready for review June 22, 2020 22:54
@macjohnny
Copy link
Member

anyone against merging this so it will be part of the 5.0.0 release?

@bodograumann
Copy link
Contributor

Thanks for your contribution, @chibat
I think it's a good addition, which increases our reach. (deno is the future?!?)

One small note:
I would have preferred a cleaner commit history to better understand the changes and look at them in chunks.

@chibat chibat requested a review from TiFu June 27, 2020 00:10
@chibat
Copy link
Contributor Author

chibat commented Jun 27, 2020

Thanks for your reviews.
I look forward to the future of Deno !
Although the current phase may be for early adopters ..

@bodograumann

I would have preferred a cleaner commit history to better understand the changes and look at them in chunks.

Sorry.. I'll be careful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deno typescript OpenAPI generators
6 participants