Skip to content

Input not taking JSON as valid data #841

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

Open
Zino-ctrlZ opened this issue Jan 27, 2025 · 4 comments
Open

Input not taking JSON as valid data #841

Zino-ctrlZ opened this issue Jan 27, 2025 · 4 comments

Comments

@Zino-ctrlZ
Copy link

Hi, I'm making use of Converter.convert from openapi-to-postmanv2 in typescript running node20. The index.d.ts file has the data property in Input set to string.
i.e in the build file,

export interface Input {
    type: "file" | "string" | "json";
    data: string;
}

so I'm getting an error when trying to pass an object to in in the data property, so the below fails

Converter.convert({type: "json", data:"data_as_json"},{}, ()=>{})

is there no support for passing data as json in node ?

@Zino-ctrlZ
Copy link
Author

Can someone confirm if this package supports esm modules ?

@Zino-ctrlZ Zino-ctrlZ changed the title Schema Faking happening after setting schemaFaker option to false Input not taking JSON as valid data Jan 28, 2025
@SharmilaChoudhary
Copy link

const examplejson = {
openapi: '3.0.0',
info: {
title: 'Sample API',
version: '1.0.0',
},
paths: {
'/users': {
get: {
summary: 'Get all users',
responses: {
'200': {
description: 'A list of users',
},
},
},
},
},
};

Converter.convert(
{ type: 'json', data: JSON.stringify(examplejson) },
{},
() => {}
);

pass your json using JSON.stringify()

@Zino-ctrlZ
Copy link
Author

my json has circular dependency so JSON.strinfgify will throw an error but also jSON.stringify returns a string. so although you state the type as json, youre still passing string in the in the data property of input .

Importing the package as commonjs allows me to pass a json as data without typescript getting mad at me, but the converter uses JSON.stringify internally when the type is json so the convert doesn't work anyways..

I handled the circular dependency externally using fast-safe-stringify (it replaces circular dep with [circular]. This works and generates a collection. I put that in quotes because the resulting collection.json fails when trying to import it to postman. I just get an import failed

@HabiburRahmaan
Copy link

HabiburRahmaan commented Mar 15, 2025

Hi @Zino-ctrlZ
When converting Swagger 2.0 specifications to Postman Collections using the postman-collection or swagger2-postman2 NodeJS module, the UserError: Specification must contain a semantic version number of the OAS specification occurs. This happens because the converter expects the openapi field instead of the swagger field for Swagger 2.0 specs. While changing swagger: "2.0" to openapi: "2.0" bypasses the error, it breaks the output. OpenAPI 3.x conversions work seamlessly.

Suggested Fixes:

Ensure the converter library is updated to a version that properly supports Swagger 2.0 via the swagger field.

If the issue persists, file a bug report with the library maintainers to address the incorrect validation logic for Swagger 2.0 specs.

Alternative Solution with Apyhub:
Consider using Apyhub's API Converter, which handles Swagger 2.0, OpenAPI 3.x, and other formats without manual modifications. Example usage:

`const apyhub = require("apyhub");

async function convertSpec() {
const data = {
file: await apyhub.prepareFile("swagger.json"),
output_format: "postman"
};

const response = await apyhub.convert("specification", data);
console.log(response);
}

convertSpec();`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants