Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ public boolean getHasBodyParam() {
return nonEmpty(bodyParams);
}

/**
* Check if there's at least one optional body parameter
*
* @return true if optional body parameter exists, false otherwise
*/
public boolean getHasOptionalBodyParam() {
return nonEmpty(bodyParams) && nonEmpty(optionalParams) && bodyParams.stream().anyMatch(optionalParams::contains);
}

/**
* Check if there's at least one query parameter
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
private void addConditionalImportInformation(OperationsMap operations) {
boolean hasPathParams = false;
boolean hasBodyParams = false;
boolean hasOptionalBodyParams = false;

for (CodegenOperation op : operations.getOperations().getOperation()) {
if (op.getHasPathParams()) {
Expand All @@ -418,10 +419,14 @@ private void addConditionalImportInformation(OperationsMap operations) {
if (op.getHasBodyParam()) {
hasBodyParams = true;
}
if (op.getHasOptionalBodyParam()) {
hasOptionalBodyParams = true;
}
}

additionalProperties.put("hasPathParams", hasPathParams);
additionalProperties.put("hasBodyParams", hasBodyParams);
additionalProperties.put("hasOptionalBodyParams", hasOptionalBodyParams);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
{{#hasBodyParams}}
"encoding/json"
{{/hasBodyParams}}
{{#isBodyParam}}
{{^required}}
{{#hasOptionalBodyParams}}
"errors"
"io"
{{/required}}
{{/isBodyParam}}
{{/hasOptionalBodyParams}}
"net/http"
"strings"
{{#imports}} "{{import}}"
Expand Down
Loading