Giter VIP home page Giter VIP logo

Comments (2)

jozsefsallai avatar jozsefsallai commented on May 31, 2024 5

Hello!
Really sorry for the delay! I'll try to come up with a good strategy for this in the coming days.

from insomnia-documenter.

steve-allam avatar steve-allam commented on May 31, 2024

Hi,

Just started using the documentor - really pleased with the results so far - thanks!

However, I seem to have hit the same issue - I use environment variables in the body part of a post request, like this:

{
	"email": "_.email",
	"password": "_.password",
	"strategy": "couch"
}

Which results in the insomnia export file containing data like this:

"method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"email\": \"{{ _.email }}\",\n\t\"password\": \"{{_.password}}\",\n\t\"strategy\": \"couch\"\n}"}

This causes an error whilst loading the file of:

SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 2 column 13 of the JSON data

Note that whilst I enter _.email, it still resolves to {{_.email}}

  • I can use {{email}}, which of course resolves to {{email}} which has the same issue.

Experimenting, I found that by swapping {{_.email}} with \u007B\u007B _.email \u007D \u007D
although - if you notice, there is a space between the last 2 hex codes....take the space out and you get an error again!!!

I've not bothered whether the {{ }} appear in the docs or not - I think that naming the vars better on my part will make the docs work - like:

{
	"email": "_.users_email",
	"password": "_.users_password",
	"strategy": "couch"
}

so all that remains is to get rid of the {{ }} in the insomnia.json file, or replace them... I used a small script to rewrite the export file, before moving to the web site:

var fs = require('fs')
 fs.readFile('insomnia.json', 'utf8', (err, data) => {
   if (err) { return console.log(err); }
   var str = data.replace(/{{ _\.(\w+) }}/g, "\\u007B\\u007B _.$1 \\u007D \\u007D");
   fs.writeFile('insomnia.json', str, 'utf8', (err) => { 
     if (err) { return console.log(err); }
   });
});

Hope that helps someone....

....if you are able to patch something similar, that would be great.

from insomnia-documenter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.