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

Header generation for PDF download ? #1186

Open
mrlubos opened this issue Oct 23, 2024 Discussed in #1185 · 2 comments
Open

Header generation for PDF download ? #1186

mrlubos opened this issue Oct 23, 2024 Discussed in #1185 · 2 comments
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon
Milestone

Comments

@mrlubos
Copy link
Member

mrlubos commented Oct 23, 2024

Discussed in https://github.com/orgs/hey-api/discussions/1185

Originally posted by jeromeduprazdange October 23, 2024
Hello !

I have a put endpoint that returns a PDF, here is the openapi spec:

"/v1/pdf/preview": {
      "put": {
        "tags": ["pdf-controller"],
        "operationId": "convertHtmlToPdf",
        "parameters": [
          { "name": "accept", "in": "header", "schema": { "type": "string", "enum": ["application/pdf"] } }
        ],
        "requestBody": {
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PreviewPdfCommand" } } },
          "required": true
        },
        "responses": {
          "default": {
            "description": "default response",
            "content": { "application/pdf": { "schema": { "type": "string", "format": "binary" } } }
          }
        }
      }
    },

But when I generate my client, I have this:

export class PdfControllerService {
  public static convertHtmlToPdf<ThrowOnError extends boolean = false>(
    options: Options<ConvertHtmlToPdfData, ThrowOnError>,
  ) {
    return (options?.client ?? client).put<ConvertHtmlToPdfResponse, ConvertHtmlToPdfError, ThrowOnError>({
      ...options,
      url: '/v1/pdf/preview',
    });
  }
}

And I don't have a working PDF if I don't manually add these to the request:

responseType: 'blob',
headers: {
  Accept: 'application/pdf',
}

I don't understand why it's not added to my convertHtmlToPdf automatically and if I'm doing something bad.
Also, I use '@hey-api/client-axios' with the 'asClass' option to true.

Thanks!

@mrlubos mrlubos added bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon labels Oct 23, 2024
@mrlubos mrlubos added this to the Parser milestone Oct 23, 2024
@mrlubos
Copy link
Member Author

mrlubos commented Oct 23, 2024

@jeromeduprazdange I'm pretty certain this is on me, nothing wrong on your end. Your workaround works, you can always override/set the headers manually if they're incorrect.

As for this issue, mind sharing which OpenAPI version you're on? I'm working on a new parser and will aim to address this as part of that release. You could try it out when it's ready?

@jeromeduprazdange
Copy link

@mrlubos Thanks for the reply. My openapi version is 3.0.1.

Yes no problem for testing the new release :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working prioritized 🚚 This issue has been prioritized and will be worked on soon
Projects
None yet
Development

No branches or pull requests

2 participants