ng-openapi-gen icon indicating copy to clipboard operation
ng-openapi-gen copied to clipboard

How to use correctly customizedResponseType property in config?

Open TE-GVGroup opened this issue 1 year ago • 3 comments

ng-openapi-gen generates methods which use responseType 'blob' like that:

return http.request( rb.build({ responseType: 'blob', accept: '*/*', context }) ).pipe( filter((r: any): r is HttpResponse<any> => r instanceof HttpResponse), map((r: HttpResponse<any>) => { return r as StrictHttpResponse<UserInfoDto>; }) ); }

I need to change default responseType from blob to json and have this piece of code in config, but this is not working: "customizedResponseType": { ".*": { "toUse": "json" } }

how to configure correctly customizedResponseType propery?

TE-GVGroup avatar Sep 06 '24 13:09 TE-GVGroup

Can you share your specification yaml / json? The customizedResponseType was added via a PR, so I myself have never used it, but it doesn't support patterns, but matches for exact paths.

luisfpg avatar Sep 06 '24 18:09 luisfpg

Can you share your specification yaml / json? The customizedResponseType was added via a PR, so I myself have never used it, but it doesn't support patterns, but matches for exact paths.

I think the solution will be custom handlebars if I can use it with ng-openapi-gen command. There is no specific information about which responseType has each endpoint in my yaml/json.

Thanks for your attention.

TE-GVGroup avatar Sep 09 '24 06:09 TE-GVGroup

It seems that you have some content type in responses that isn't being recognized as JSON.

luisfpg avatar Nov 19 '24 19:11 luisfpg

+1 I have the same issue. The yaml does not specify the response type at all.

/foo/bar:
[...] 
  responses:
      "200":
        description: OK
        content:
          '*/*':
            schema:
              $ref: "#/..."

I thought this is exaclty the case for customizedResponseType?!

Unfortunately I can not use patternProperties as expected.

It works when configured with:

"customizedResponseType": {
    "/foo/bar": {
      "toUse": "json"
    }
  }

but not for

"customizedResponseType": {
    ".*": {
      "toUse": "json"
    }
  },

If this is the corresponding in the code:

private inferResponseType(successResponse: Content, operation: Operation, { customizedResponseType = {} }: Pick<Options, 'customizedResponseType'>): string {
    const customizedResponseTypeByPath = customizedResponseType[operation.path];
    if (customizedResponseTypeByPath) {
      return customizedResponseTypeByPath.toUse;
    }
...

It seems like there is some kind of path/regex operation missing when customizedResponseTypeByPath is identified

on-rails-at-web avatar Jun 19 '25 06:06 on-rails-at-web