superfaceai / cli

Let AI connect the APIs for you
https://superface.ai
MIT License
22 stars 4 forks source link

fix: `.env` doesn't contain duplicate variables #333

Closed kysely closed 1 year ago

kysely commented 1 year ago

Description

Fixing dotenv utility so that it doesn't create duplicate env variables in .env.

The first commit is just refactoring of the test code. Easier to review just the second commit.

Motivation and Context

When provider has >1 security schemes of same type (or same-named parameters but that shouldn't happen), env vars are added to .env multiple times.

{
  "name": "hubspot",
  "defaultService": "default",
  "parameters": [],
  "services": [
    {
      "baseUrl": "https://api.hubapi.com/",
      "id": "default"
    }
  ],
  "securitySchemes": [
    {
      "type": "apiKey",
      "name": "private-app-legacy",
      "in": "header",
      "id": "private_apps_legacy"
    },
    {
      "type": "apiKey",
      "name": "private-app",
      "in": "header",
      "id": "private_apps"
    }
  ]
}

creates the following .env

HUBSPOT_API_KEY=
HUBSPOT_API_KEY=

Types of changes

Checklist: