-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to configure own path to "/api-docs/swagger.json"
- Loading branch information
Showing
7 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ erl_crash.dump | |
doc/ | ||
.rebar3 | ||
logs | ||
rebar3 | ||
priv/swagger/swagger-initializer.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
%% Reading the contents of the file | ||
case file:read_file("priv/swagger/swagger-initializer.js") of | ||
{ok, Content} -> | ||
%% Get the configuration for the path from the application configuration | ||
Path = application:get_env(cowboy_swagger, path, "/api-docs"), | ||
|
||
%% Ensure Path is a binary (if it's a list, convert to binary) | ||
BinPath = case is_binary(Path) of | ||
true -> Path; | ||
false -> list_to_binary(Path) | ||
end, | ||
|
||
%% Determine the path to the JavaScript file | ||
FilePath = "priv/swagger/swagger-initializer.js", | ||
|
||
|
||
|
||
%% Replace the placeholder in the file contents | ||
%% Ensure both the placeholder and replacement are binaries | ||
ModifiedContent = binary:replace(Content, <<"__SWAGGER_PATH__">>, <<"\'", BinPath/binary, "\'">>, [global]), | ||
|
||
%% Write the updated file back | ||
ok = file:write_file(FilePath, ModifiedContent), | ||
|
||
%% Successfully complete hook execution | ||
|
||
io:format("Swagger path updated to: ~s~n", [Path]), | ||
CONFIG; | ||
{error, Reason} -> | ||
io:format("Failed to read swagger-initializer.js: ~p~n", [Reason]), | ||
CONFIG | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters