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

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

Description

@andriokha

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions