Skip to content

Commit

Permalink
feat: Add --selfReferenceDepth as argument for the cats generate subc…
Browse files Browse the repository at this point in the history
…ommand
  • Loading branch information
en-milie committed Oct 23, 2024
1 parent dc08e39 commit 60416a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/endava/cats/command/GenerateCommand.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/endava/cats/command/LintCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 60416a6

Please sign in to comment.