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

application/x-www-form-urlencoded not generated correctly #70

Closed
elonmallin opened this issue Feb 18, 2020 · 3 comments
Closed

application/x-www-form-urlencoded not generated correctly #70

elonmallin opened this issue Feb 18, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@elonmallin
Copy link

I have an endpoint that should use application/x-www-form-urlencoded but the data is sent as a json string with the content type being application/x-www-form-urlencoded.

I got this function generated:

/**
   * This method provides access to the full `HttpResponse`, allowing access to response headers.
   * To access only the response body, use `authAccessToken()` instead.
   *
   * This method sends `application/x-www-form-urlencoded` and handles request body of type `application/x-www-form-urlencoded`.
   */
  authAccessToken$Response(params?: {
    body?: { 'grant_type': string, 'scope'?: string, 'client_id'?: string, 'client_secret'?: string }
  }): Observable<StrictHttpResponse<TokenAuthenticateResult>> {

    const rb = new RequestBuilder(this.rootUrl, AuthService.AuthAccessTokenPath, 'post');
    if (params) {

      rb.body(params.body, 'application/x-www-form-urlencoded');
    }
    return this.http.request(rb.build({
      responseType: 'json',
      accept: 'application/json'
    })).pipe(
      filter((r: any) => r instanceof HttpResponse),
      map((r: HttpResponse<any>) => {
        return r as StrictHttpResponse<TokenAuthenticateResult>;
      })
    );
  }

But the problem seems to be in: rb.body which has this content:

body(value: any, contentType = 'application/json'): void {
    if (value instanceof Blob) {
      this._bodyContentType = value.type;
    } else {
      this._bodyContentType = contentType;
    }
    if ((this._bodyContentType || '').startsWith('multipart/form-data')) {
      // Handle multipart form data
      const formData = new FormData();
      if (value != null) {
        for (const key of Object.keys(value)) {
          const val = value[key];
          if (val instanceof Array) {
            for (const v of val) {
              const toAppend = this.formDataValue(v);
              if (toAppend !== null) {
                formData.append(key, toAppend);
              }
            }
          } else {
            const toAppend = this.formDataValue(val);
            if (toAppend !== null) {
              formData.set(key, toAppend);
            }
          }
        }
      }
      this._bodyContent = formData;
    } else {
      // The body is the plain content
      this._bodyContent = value;
    }
  }

Probably there needs to be a check for application/x-www-form-urlencoded also?

@elonmallin
Copy link
Author

This is the requestBody of that method in the apoen api json.

"requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "required": [
                  "grant_type"
                ],
                "type": "object",
                "properties": {
                  "grant_type": {
                    "type": "string"
                  },
                  "scope": {
                    "type": "string"
                  },
                  "client_id": {
                    "type": "string"
                  },
                  "client_secret": {
                    "type": "string"
                  }
                }
              },
              "encoding": {
                "grant_type": {
                  "style": "form"
                },
                "scope": {
                  "style": "form"
                },
                "client_id": {
                  "style": "form"
                },
                "client_secret": {
                  "style": "form"
                }
              }
            }
          }
        },

It's generated from Swashbuckle.Swaggergen for C#.

@luisfpg luisfpg added the enhancement New feature or request label Feb 18, 2020
@luisfpg
Copy link
Contributor

luisfpg commented Feb 18, 2020

application/x-www-form-urlencoded is not currently implemented.
Will be for version 0.8.0.

@elonmallin
Copy link
Author

Okey, nice =)

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

No branches or pull requests

2 participants