Skip to content

Commit

Permalink
Add option to generate_config to use relative paths (#755)
Browse files Browse the repository at this point in the history
Closes #715

Testing:
- manual testing
  • Loading branch information
marina-p committed May 8, 2023
1 parent d219bab commit b8091d8
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/driver/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let usage() =
"Usage:
restler --version
generate_config --specs <OpenAPI file list or directory> --output_dir <output directory>
generate_config --specs <OpenAPI file list or directory> --output_dir <output directory> [--relative_path <relative path>]
[--disable_log_upload] [--logsUploadRootDirPath <log upload directory>]
[--python_path <full path to python executable>]
[--workingDirPath <local logs directory (default: cwd)>]
Expand Down Expand Up @@ -482,6 +482,7 @@ module Config =
{
specFilesOrDirs : string list
outputDir : string option
relativePath : string option
}

let rec parseGenerateConfigParameters (args:GenerateConfigParameters) = function
Expand All @@ -508,6 +509,12 @@ module Config =
rest.[0..i-1], (rest |> List.skip i)

parseGenerateConfigParameters { args with specFilesOrDirs = specs } rest
| "--relative_path"::relPath::rest ->
if Directory.Exists relPath then
parseGenerateConfigParameters { args with relativePath = Some relPath } rest
else
Logging.logError <| sprintf "Directory %s specified for the relative path does not exist." relPath
usage()
| invalidArgument::rest ->
Logging.logError <| sprintf "Invalid argument: %s" invalidArgument
usage()
Expand All @@ -517,7 +524,8 @@ module Config =
// in the list
let configParameters = parseGenerateConfigParameters
{ specFilesOrDirs = []
outputDir = None }
outputDir = None
relativePath = None }
generateConfigParameters
let configDirPath = configParameters.outputDir.Value
printf "Creating directory %s" configDirPath
Expand All @@ -544,11 +552,17 @@ module Config =

// Get absolute paths. The user will need to convert these to a relative path
// when checked in.
let swaggerSpecAbsFilePaths =
specPaths
|> Seq.map (fun filePath ->
Restler.Config.convertToAbsPath Environment.CurrentDirectory filePath)
|> Seq.toList
let swaggerSpecFilePaths =
match configParameters.relativePath with
| Some relPath ->
specPaths
|> Seq.map (fun p -> System.IO.Path.GetRelativePath(relPath, p)
.Replace(System.IO.Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))
| None ->
specPaths
|> Seq.map (fun filePath ->
Restler.Config.convertToAbsPath Environment.CurrentDirectory filePath)
let swaggerSpecFilePaths = swaggerSpecFilePaths |> Seq.toList
let dictionaryFileName = "dict.json"
let dictionaryFilePath = configDirPath ++ dictionaryFileName
let customPayloads = """{
Expand Down Expand Up @@ -581,7 +595,7 @@ module Config =
// use a JObject below instead of modifying the default config.
let config =
JObject(
JProperty("SwaggerSpecFilePath", JArray(swaggerSpecAbsFilePaths)),
JProperty("SwaggerSpecFilePath", JArray(swaggerSpecFilePaths)),
JProperty("DataFuzzing", true),
JProperty("CustomDictionaryFilePath", Restler.Workflow.Constants.NewDictionaryFileName),
JProperty("EngineSettingsFilePath", Restler.Workflow.Constants.DefaultEngineSettingsFileName),
Expand Down

0 comments on commit b8091d8

Please sign in to comment.