zijianhuang / webapiclientgen

Strongly Typed Client API Generators generate strongly typed client APIs in C# .NET and in TypeScript for jQuery and Angular 2+ from ASP.NET Web API and .NET Core Web API
MIT License
167 stars 38 forks source link

consider to to replace JSON.stringify(requestBody) to requestBody in the generated post/put call. #143

Open zijianhuang opened 5 months ago

zijianhuang commented 5 months ago

So the generated NG codes could be shorter.

In https://github.com/angular/angular/blob/7b4d275f494a64c38b61cea7045ba8b6e8447b78/packages/common/http/src/request.ts


 serializeBody(): ArrayBuffer|Blob|FormData|URLSearchParams|string|null {
    // If no body is present, no need to serialize it.
    if (this.body === null) {
      return null;
    }
    // Check whether the body is already in a serialized form. If so,
    // it can just be returned directly.
    if (isArrayBuffer(this.body) || isBlob(this.body) || isFormData(this.body) ||
        isUrlSearchParams(this.body) || typeof this.body === 'string') {
      return this.body;
    }
    // Check whether the body is an instance of HttpUrlEncodedParams.
    if (this.body instanceof HttpParams) {
      return this.body.toString();
    }
    // Check whether the body is an object or array, and serialize with JSON if so.
    if (typeof this.body === 'object' || typeof this.body === 'boolean' ||
        Array.isArray(this.body)) {
      return JSON.stringify(this.body);
    }
    // Fall back on toString() for everything else.
    return (this.body as any).toString();
  }