From 18fc72fd75a2208f4445e55bbf3d41803fff3a83 Mon Sep 17 00:00:00 2001 From: David Gamero Date: Tue, 3 Jan 2023 17:15:27 -0500 Subject: [PATCH] migrate --- .../resources/typescript/http/http.mustache | 60 +++---------------- .../builds/with-unique-items/http/http.ts | 17 +++--- .../typescript/builds/browser/http/http.ts | 17 +++--- .../builds/composed-schemas/http/http.ts | 17 +++--- .../typescript/builds/default/http/http.ts | 19 +++--- .../typescript/builds/deno/http/http.ts | 49 +++------------ .../typescript/builds/inversify/http/http.ts | 19 +++--- .../typescript/builds/jquery/http/http.ts | 17 +++--- .../builds/object_params/http/http.ts | 19 +++--- 9 files changed, 76 insertions(+), 158 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript/http/http.mustache b/modules/openapi-generator/src/main/resources/typescript/http/http.mustache index 2cc4f4a12845..5b4593968c7e 100644 --- a/modules/openapi-generator/src/main/resources/typescript/http/http.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/http/http.mustache @@ -2,16 +2,12 @@ {{#node}} // TODO: evaluate if we can easily get rid of this library import {{^supportsES6}}* as{{/supportsES6}} FormData from "form-data"; -import { URLSearchParams } from 'url'; +import { URL, URLSearchParams } from 'url'; import * as http from 'http'; import * as https from 'https'; {{/node}} {{/platforms}} -{{#platforms}} -{{^deno}} -import {{^supportsES6}}* as{{/supportsES6}} URLParse from "url-parse"; -{{/deno}} -{{/platforms}} + import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub{{importFileExtension}}'{{/useRxJS}}; {{#platforms}} @@ -57,44 +53,6 @@ export type HttpFile = {{{fileContentDataType}}} & { readonly name: string }; {{/node}} {{/platforms}} -{{#platforms}} -{{#deno}} -/** - * URLParse Wrapper for Deno - */ -class URLParse { - private url: URL; - - constructor(address: string, _parser: boolean) { - this.url = new URL(address); - } - - public set(_part: 'query', obj: {[key: string]: string | undefined}) { - for (const key in obj) { - const value = obj[key]; - if (value) { - this.url.searchParams.set(key, value); - } else { - this.url.searchParams.set(key, ""); - } - } - } - - public get query() { - const obj: {[key: string]: string} = {}; - for (const [key, value] of this.url.searchParams.entries()) { - obj[key] = value; - } - return obj; - } - - public toString() { - return this.url.toString(); - } -} -{{/deno}} -{{/platforms}} - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -112,7 +70,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; {{#platforms}} {{#node}} private agent: http.Agent | https.Agent | undefined = undefined; @@ -126,7 +84,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -134,7 +92,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -142,7 +102,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -171,9 +131,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /** diff --git a/samples/client/others/typescript/builds/with-unique-items/http/http.ts b/samples/client/others/typescript/builds/with-unique-items/http/http.ts index 579326776771..166b2bfb8969 100644 --- a/samples/client/others/typescript/builds/with-unique-items/http/http.ts +++ b/samples/client/others/typescript/builds/with-unique-items/http/http.ts @@ -1,4 +1,4 @@ -import * as URLParse from "url-parse"; + import { Observable, from } from '../rxjsStub'; export * from './isomorphic-fetch'; @@ -23,7 +23,6 @@ export enum HttpMethod { */ export type HttpFile = Blob & { readonly name: string }; - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -41,7 +40,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; /** * Creates the request context using a http method and request resource url @@ -50,7 +49,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -58,7 +57,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -66,7 +67,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -95,9 +96,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts index f8f62d6ce6f6..166b2bfb8969 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts @@ -1,4 +1,4 @@ -import URLParse from "url-parse"; + import { Observable, from } from '../rxjsStub'; export * from './isomorphic-fetch'; @@ -23,7 +23,6 @@ export enum HttpMethod { */ export type HttpFile = Blob & { readonly name: string }; - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -41,7 +40,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; /** * Creates the request context using a http method and request resource url @@ -50,7 +49,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -58,7 +57,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -66,7 +67,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -95,9 +96,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts index 579326776771..166b2bfb8969 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts @@ -1,4 +1,4 @@ -import * as URLParse from "url-parse"; + import { Observable, from } from '../rxjsStub'; export * from './isomorphic-fetch'; @@ -23,7 +23,6 @@ export enum HttpMethod { */ export type HttpFile = Blob & { readonly name: string }; - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -41,7 +40,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; /** * Creates the request context using a http method and request resource url @@ -50,7 +49,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -58,7 +57,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -66,7 +67,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -95,9 +96,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts index 7daeb7728cb1..c82f55b03640 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts @@ -1,9 +1,9 @@ // TODO: evaluate if we can easily get rid of this library import * as FormData from "form-data"; -import { URLSearchParams } from 'url'; +import { URL, URLSearchParams } from 'url'; import * as http from 'http'; import * as https from 'https'; -import * as URLParse from "url-parse"; + import { Observable, from } from '../rxjsStub'; export * from './isomorphic-fetch'; @@ -31,7 +31,6 @@ export type HttpFile = { name: string }; - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -49,7 +48,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; private agent: http.Agent | https.Agent | undefined = undefined; /** @@ -59,7 +58,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -67,7 +66,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -75,7 +76,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -104,9 +105,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts index 139149cec973..efe58f7cc165 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts @@ -1,3 +1,4 @@ + import { Observable, from } from '../rxjsStub.ts'; @@ -21,40 +22,6 @@ export enum HttpMethod { */ export type HttpFile = Blob & { readonly name: string }; -/** - * URLParse Wrapper for Deno - */ -class URLParse { - private url: URL; - - constructor(address: string, _parser: boolean) { - this.url = new URL(address); - } - - public set(_part: 'query', obj: {[key: string]: string | undefined}) { - for (const key in obj) { - const value = obj[key]; - if (value) { - this.url.searchParams.set(key, value); - } else { - this.url.searchParams.set(key, ""); - } - } - } - - public get query() { - const obj: {[key: string]: string} = {}; - for (const [key, value] of this.url.searchParams.entries()) { - obj[key] = value; - } - return obj; - } - - public toString() { - return this.url.toString(); - } -} - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -72,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; /** * Creates the request context using a http method and request resource url @@ -81,7 +48,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -89,7 +56,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -97,7 +66,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -126,9 +95,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts index 7daeb7728cb1..c82f55b03640 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts @@ -1,9 +1,9 @@ // TODO: evaluate if we can easily get rid of this library import * as FormData from "form-data"; -import { URLSearchParams } from 'url'; +import { URL, URLSearchParams } from 'url'; import * as http from 'http'; import * as https from 'https'; -import * as URLParse from "url-parse"; + import { Observable, from } from '../rxjsStub'; export * from './isomorphic-fetch'; @@ -31,7 +31,6 @@ export type HttpFile = { name: string }; - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -49,7 +48,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; private agent: http.Agent | https.Agent | undefined = undefined; /** @@ -59,7 +58,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -67,7 +66,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -75,7 +76,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -104,9 +105,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts index 8e4d7d66f282..7712ca1d1314 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts @@ -1,4 +1,4 @@ -import * as URLParse from "url-parse"; + import { Observable, from } from '../rxjsStub'; export * from './jquery'; @@ -23,7 +23,6 @@ export enum HttpMethod { */ export type HttpFile = Blob & { readonly name: string }; - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -41,7 +40,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; /** * Creates the request context using a http method and request resource url @@ -50,7 +49,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -58,7 +57,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -66,7 +67,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -95,9 +96,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts index 7daeb7728cb1..c82f55b03640 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts @@ -1,9 +1,9 @@ // TODO: evaluate if we can easily get rid of this library import * as FormData from "form-data"; -import { URLSearchParams } from 'url'; +import { URL, URLSearchParams } from 'url'; import * as http from 'http'; import * as https from 'https'; -import * as URLParse from "url-parse"; + import { Observable, from } from '../rxjsStub'; export * from './isomorphic-fetch'; @@ -31,7 +31,6 @@ export type HttpFile = { name: string }; - export class HttpException extends Error { public constructor(msg: string) { super(msg); @@ -49,7 +48,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams; export class RequestContext { private headers: { [key: string]: string } = {}; private body: RequestBody = undefined; - private url: URLParse; + private url: URL; private agent: http.Agent | https.Agent | undefined = undefined; /** @@ -59,7 +58,7 @@ export class RequestContext { * @param httpMethod http method */ public constructor(url: string, private httpMethod: HttpMethod) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /* @@ -67,7 +66,9 @@ export class RequestContext { * */ public getUrl(): string { - return this.url.toString(); + return this.url.toString().endsWith("/") ? + this.url.toString().slice(0, -1) + : this.url.toString(); } /** @@ -75,7 +76,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URL(url); } /** @@ -104,9 +105,7 @@ export class RequestContext { } public setQueryParam(name: string, value: string) { - let queryObj = this.url.query; - queryObj[name] = value; - this.url.set("query", queryObj); + this.url.searchParams.set(name, value); } /**