Skip to content

Commit

Permalink
breaking(env): change _base to $shared
Browse files Browse the repository at this point in the history
Change `_base` to `$shared` and `DEFAULT_HEADERS` to
`$default_headers`.
  • Loading branch information
gorillamoe committed Sep 16, 2024
1 parent 873e961 commit 04bb03a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
9 changes: 5 additions & 4 deletions docs/docs/usage/dotenv-and-http-client.env.json-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ Authorization: Bearer {{API_KEY}}

You can define default HTTP headers in the `http-client.env.json` file.

You need to put them in the special `_base` property and
the `DEFAULT_HEADERS` will be merged with the headers from the HTTP requests.
You need to put them in the special `$shared` property and
the `$default_headers` will be merged with the headers from the HTTP requests.

```json title="http-client.env.json"
{
"_base": {
"DEFAULT_HEADERS": {
"$shared": {
"$default_headers": {
"Content-Type": "application/json",
"Accept": "application/json"
},
},
"dev": {
"API_KEY": "your-api-key"
Expand Down
9 changes: 5 additions & 4 deletions lua/kulala/parser/env.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ M.get_env = function()

if http_client_env_json then
local f = vim.fn.json_decode(vim.fn.readfile(http_client_env_json))
if f._base then
DB.update().http_client_env_base = vim.tbl_deep_extend("force", DB.find_unique("http_client_env_base"), f._base)
if f["$shared"] then
DB.update().http_client_env_base =
vim.tbl_deep_extend("force", DB.find_unique("http_client_env_base"), f["$shared"])
end
f._base = nil
f["$shared"] = nil
DB.update().http_client_env = vim.tbl_deep_extend("force", DB.find_unique("http_client_env"), f)
end

local http_client_env_base = DB.find_unique("http_client_env_base") or {}
for key, value in pairs(http_client_env_base) do
if key ~= "DEFAULT_HEADERS" then
if key ~= "$default_headers" then
env[key] = value
end
end
Expand Down
20 changes: 20 additions & 0 deletions schemas/http-client.env.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
"properties": {
"$schema": {
"type": "string"
},
"$shared": {
"type": "object",
"properties": {
"$default_headers": {
"type": "object",
"patternProperties": {
"^.*$": {
"type": "string"
}
},
"additionalProperties": false
}
},
"patternProperties": {
"^.*$": {
"type": "string"
}
},
"additionalProperties": false
}
},
"patternProperties": {
Expand Down

0 comments on commit 04bb03a

Please sign in to comment.