From 60416a61bdd64ec87743d7501095066e14dc76cd Mon Sep 17 00:00:00 2001 From: Madalin Ilie Date: Wed, 23 Oct 2024 20:51:55 +0300 Subject: [PATCH] feat: Add --selfReferenceDepth as argument for the cats generate subcommand --- .../java/com/endava/cats/command/GenerateCommand.java | 10 ++++++++-- src/main/java/com/endava/cats/command/LintCommand.java | 1 - .../com/endava/cats/command/GenerateCommandTest.java | 6 +++++- .../endava/cats/factory/FuzzingDataFactoryTest.java | 2 -- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/endava/cats/command/GenerateCommand.java b/src/main/java/com/endava/cats/command/GenerateCommand.java index db3c56d5e..6f05311d1 100644 --- a/src/main/java/com/endava/cats/command/GenerateCommand.java +++ b/src/main/java/com/endava/cats/command/GenerateCommand.java @@ -1,11 +1,12 @@ package com.endava.cats.command; +import com.endava.cats.args.ProcessingArguments; import com.endava.cats.context.CatsGlobalContext; import com.endava.cats.factory.FuzzingDataFactory; import com.endava.cats.http.HttpMethod; import com.endava.cats.model.FuzzingData; -import com.endava.cats.util.OpenApiUtils; import com.endava.cats.util.JsonUtils; +import com.endava.cats.util.OpenApiUtils; import com.endava.cats.util.VersionProvider; import com.google.gson.JsonParser; import io.github.ludovicianul.prettylogger.PrettyLogger; @@ -74,14 +75,19 @@ public class GenerateCommand implements Runnable, CommandLine.IExitCodeGenerator description = "A custom mime type if the OpenAPI contract/spec uses content type negotiation versioning. Default: @|bold,underline ${DEFAULT-VALUE}|@") private String contentType = "application/json"; + @CommandLine.Option(names = {"--selfReferenceDepth", "-L"}, + description = "Max depth for request objects having cyclic dependencies. Default: @|bold,underline ${DEFAULT-VALUE}|@") + private int selfReferenceDepth = 4; + FuzzingDataFactory fuzzingDataFactory; CatsGlobalContext globalContext; @Inject - public GenerateCommand(FuzzingDataFactory fuzzingDataFactory, CatsGlobalContext globalContext) { + public GenerateCommand(FuzzingDataFactory fuzzingDataFactory, CatsGlobalContext globalContext, ProcessingArguments processingArguments) { this.fuzzingDataFactory = fuzzingDataFactory; this.globalContext = globalContext; + processingArguments.setSelfReferenceDepth(this.selfReferenceDepth); } private int exitCodeDueToErrors = 0; diff --git a/src/main/java/com/endava/cats/command/LintCommand.java b/src/main/java/com/endava/cats/command/LintCommand.java index 4e0adfe66..83791b576 100644 --- a/src/main/java/com/endava/cats/command/LintCommand.java +++ b/src/main/java/com/endava/cats/command/LintCommand.java @@ -69,7 +69,6 @@ public void run() { catsCommand.filterArguments.getSkipFuzzers().addAll(Optional.ofNullable(skipFuzzers).orElse(Collections.emptyList())); catsCommand.filterArguments.getSkipPaths().addAll(Optional.ofNullable(skipPaths).orElse(Collections.emptyList())); catsCommand.filterArguments.getCheckArguments().setIncludeContract(true); - catsCommand.processingArguments.setFilterXxxFromRequestPayloads(false); catsCommand.processingArguments.setLimitXxxOfCombinations(6); catsCommand.run(); } diff --git a/src/test/java/com/endava/cats/command/GenerateCommandTest.java b/src/test/java/com/endava/cats/command/GenerateCommandTest.java index 49edd4e5d..18a9a27a2 100644 --- a/src/test/java/com/endava/cats/command/GenerateCommandTest.java +++ b/src/test/java/com/endava/cats/command/GenerateCommandTest.java @@ -1,5 +1,6 @@ package com.endava.cats.command; +import com.endava.cats.args.ProcessingArguments; import com.endava.cats.context.CatsGlobalContext; import com.endava.cats.factory.FuzzingDataFactory; import com.google.gson.Gson; @@ -28,9 +29,12 @@ class GenerateCommandTest { @Inject CatsGlobalContext catsGlobalContext; + @Inject + ProcessingArguments processingArguments; + @BeforeEach public void init() { - generateCommand = new GenerateCommand(fuzzingDataFactory, catsGlobalContext); + generateCommand = new GenerateCommand(fuzzingDataFactory, catsGlobalContext, processingArguments); } @ParameterizedTest diff --git a/src/test/java/com/endava/cats/factory/FuzzingDataFactoryTest.java b/src/test/java/com/endava/cats/factory/FuzzingDataFactoryTest.java index 8963b7ffa..8c6242e50 100644 --- a/src/test/java/com/endava/cats/factory/FuzzingDataFactoryTest.java +++ b/src/test/java/com/endava/cats/factory/FuzzingDataFactoryTest.java @@ -63,8 +63,6 @@ void setup() { filterArguments = Mockito.mock(FilterArguments.class); Mockito.when(processingArguments.getUseExamples()).thenReturn(true); Mockito.when(processingArguments.getLimitXxxOfCombinations()).thenReturn(10); - Mockito.when(processingArguments.isGenerateAllXxxCombinationsForResponses()).thenReturn(true); - Mockito.when(processingArguments.isFilterXxxFromRequestPayloads()).thenReturn(false); Mockito.when(processingArguments.getContentType()).thenReturn(List.of(JsonUtils.JSON_WILDCARD, "application/x-www-form-urlencoded")); Mockito.when(processingArguments.examplesFlags()).thenReturn(new ProcessingArguments.ExamplesFlags(true, true, true, true)); fuzzingDataFactory = new FuzzingDataFactory(filesArguments, processingArguments, catsGlobalContext, validDataFormat, filterArguments);