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

Add support for nested environment variables #20

Open
devhammed opened this issue Jul 2, 2020 · 2 comments
Open

Add support for nested environment variables #20

devhammed opened this issue Jul 2, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@devhammed
Copy link
Collaborator

devhammed commented Jul 2, 2020

First of all, good job on this tool but I am currently using a nested environment variables structure for an API I am developing but the merging always conflicts with the base settings for endpoint...You can check it out here: https://fanfaro-accounting-api-docs.vercel.app

Base Settings:

{
  "base": "http://fanfaro.test/api"
}

Folder Settings (e.g auth):

{
  "base": "{{ base }}/auth"
}

Insomnia Documenter Output:

http://fanfaro.test/api

Expected Output:

http://fanfaro.test/api/auth


This works fine in the Insomnia app.

@jozsefsallai
Copy link
Collaborator

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

@jozsefsallai jozsefsallai added the enhancement New feature or request label May 21, 2021
@steve-allam
Copy link

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.

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

No branches or pull requests

3 participants