Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Unexpected end of JSON input with empty raw request body #101

Closed
andriokha opened this issue Apr 23, 2021 · 2 comments
Closed

Unexpected end of JSON input with empty raw request body #101

andriokha opened this issue Apr 23, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@andriokha
Copy link

Hi,

Thanks for the project! I'm trying it out for the first time. I'm not sure if the source file is dodgy, if I'm doing something wrong, if it's a legitimate bug, or a feature request... but I can't get it to work (:

Repro steps

  1. Download the Postman Collection (v2.1 judging by the referenced schema) file for the Afterpay payment provider's API: http://static-us.afterpay.com/api/sandbox/Afterpay_Online_US_API_v2.postman_collection.json
  2. Try to convert it to an OpenAPI file running the following script:
    'use strict'
    
    // Require Package
    const postmanToOpenApi = require('postman-to-openapi')
    
    // Postman Collection Path
    const postmanCollection = './Afterpay_Online_US_API_v2.postman_collection.json';
    // Output OpenAPI Path
    const outputFile = './AfterpayOpenAPI.yml'
    
    async function main() {
      // Async/await
      try {
        await postmanToOpenApi(postmanCollection, outputFile, {defaultTag: 'General'})
      }
      catch (err) {
        console.log(err)
      }
    }
    
    main();

Actual results

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at parseBody (/app/node_modules/postman-to-openapi/lib/index.js:132:29)
    at postmanToOpenApi (/app/node_modules/postman-to-openapi/lib/index.js:44:10)
    at async main (/app/convertpostman.js:18:5)
  • postman-to-openapi: 1.7.1
  • node: 15.11.0

Details

It looks like it's down to the empty field item[2].item[3].request.body.raw in the source file. If I change:

example: JSON.parse(raw)

to

example: raw ? JSON.parse(raw) : '',

it produces an output file. I'm not sure if there might be any negative side-effects to that.

Thanks!

@joolfe joolfe added the bug Something isn't working label Apr 23, 2021
@joolfe
Copy link
Owner

joolfe commented Apr 23, 2021

Hi @andriokha, seems to be a bug, I will fix this weekend ;-)
Thanks for report it!

@joolfe joolfe closed this as completed in 1c376cf Apr 24, 2021
@andriokha
Copy link
Author

Thanks for the quick turn-around!

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

No branches or pull requests

2 participants