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

False positive when validating with schema type: string and format: binary #275

Open
Zubnix opened this issue Mar 28, 2022 · 2 comments
Open
Labels
bug Something isn't working

Comments

@Zubnix
Copy link

Zubnix commented Mar 28, 2022

Are you using jest or chai?
Jest

Are you using OpenAPI 2, 3.0.X, or 3.1.0?
3.0.x

Describe the bug clearly
Verification fails when using binary string format, incorrectly expects plain string.

Steps to reproduce the bug:

  1. Define an openapi (response) spec with
content:
  application/octet-stream:
    schema:
      type: string
      format: binary
  1. Return binary data.
  2. See error (please paste error output or a screenshot)
Error: expect(received).toSatisfyApiSpec() // Matches 'received' to a response defined in your API spec, then validates 'received' against it

expected received to satisfy the '200' response defined for endpoint 'GET /webfd/{fd}' in your API spec

received did not satisfy it because: response must be string

received contained: { body: <Buffer 01 02> }

The '200' response defined for endpoint 'GET /webfd/{fd}' in API spec: {
  '200': {
    description: 'Content sent succesfully.',
    content: {
      'application/octet-stream': { schema: { type: 'string', format: 'binary' } }
    }
  }
}

What did you expect to happen instead?
Verification should succeed.

Are you going to resolve the issue?
No, as I don't know here to look.

@Zubnix Zubnix added the bug Something isn't working label Mar 28, 2022
@rwalle61
Copy link
Collaborator

Thanks @Zubnix! Would you posting a reproduction link / example of how you receive a response as a Buffer? Then I can check the code and point you / someone else in the right direction 🙂

@balazsbencs-sc
Copy link

I also have the same issue with this in a Nest project: I have an endpoint generating a PDF and in the controller I do nothing else just returning a StreamableFile. This StreamableFile gets the input as a Buffer from puppeteer - pretty simple setup.
When running test again the openapi documentation using supertest, in the console it prints out as a buffer. See examples below from my code:

    received did not satisfy it because: response must be string

    received contained: {
      body: <Buffer 25 50 44 46 2d 31 2e 34 0a 25 d3 eb e9 e1 0a 31 20 30 20 6f 62 6a 0a 3c 3c 2f 43 72 65 61 74 6f 72 20 28 43 68 72 6f 6d 69 75 6d 29 0a 2f 50 72 6f 64 ... 12824 more bytes>
    }

test:

    test('returns pdf with application/octet-stream', async () => {
      const agent = supertest(app.getHttpServer());
      const res = await agent
        .post('/v1/report/generate')
        .send([......]);
      expect(res).toSatisfyApiSpec();
    });

example openapi doc:

  /v1/report/generate:
    post:
      tags:
        - reports
      description: '...'
      summary: '...'
      operationId: generateReport
      requestBody:
        $ref: '#/components/requestBodies/........'
      responses:
        '201':
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
          description: ......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants