Skip to content

[GO] fix missing utils add required supportfiles feature #13918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -703,18 +703,16 @@ void generateApis(List<File> files, List<OperationsMap> allOperations, List<Mode
}

private void generateSupportingFiles(List<File> files, Map<String, Object> bundle) {
if (!generateSupportingFiles) {
// TODO: process these anyway and report via dryRun?
LOGGER.info("Skipping generation of supporting files.");
return;
}
Set<String> supportingFilesToGenerate = null;
String supportingFiles = GlobalSettings.getProperty(CodegenConstants.SUPPORTING_FILES);
if (supportingFiles != null && !supportingFiles.isEmpty()) {
supportingFilesToGenerate = new HashSet<>(Arrays.asList(supportingFiles.split(",")));
}

for (SupportingFile support : config.supportingFiles()) {
if (!generateSupportingFiles && !support.isRequired()) {
continue;
}
try {
String outputFolder = config.outputFolder();
if (StringUtils.isNotEmpty(support.getFolder())) {
Expand Down Expand Up @@ -747,6 +745,12 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
}
}

if (!generateSupportingFiles) {
// TODO: process these anyway and report via dryRun?
LOGGER.info("Skipping generation of not required supporting files.");
return;
}

// Consider .openapi-generator-ignore a supporting file
// Output .openapi-generator-ignore if it doesn't exist and wasn't explicitly created by a generator
final String openapiGeneratorIgnore = ".openapi-generator-ignore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,28 @@
*/
public class SupportingFile extends TemplateDefinition {
private boolean canOverwrite = true;
/**
* Whether the {@link SupportingFile} is required for all generated code.
*/
private boolean required = false;

public SupportingFile(String templateFile, String destinationFilename) {
this(templateFile, "", destinationFilename);
}

public SupportingFile(String templateFile, String destinationFilename, boolean required) {
this(templateFile, "", destinationFilename, required);
}

public SupportingFile(String templateFile, String folder, String destinationFilename) {
super(templateFile, folder, destinationFilename);
}

public SupportingFile(String templateFile, String folder, String destinationFilename, boolean required) {
super(templateFile, folder, destinationFilename);
this.required = required;
}

/**
* Identifies this instance as referring to a supporting file which should not overwrite a file of the same name.
*
Expand Down Expand Up @@ -84,6 +97,13 @@ public boolean isCanOverwrite() {
return canOverwrite;
}

/**
* @return whether the {@link SupportingFile} is required for all generated code.
*/
public boolean isRequired() {
return required;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), isCanOverwrite());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("go.mod.mustache", "", "go.mod"));
supportingFiles.add(new SupportingFile("go.sum", "", "go.sum"));
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
supportingFiles.add(new SupportingFile("utils.mustache", "", "utils.go"));
supportingFiles.add(new SupportingFile("utils.mustache", "", "utils.go", true));
}

public void setUseOneOfDiscriminatorLookup(boolean useOneOfDiscriminatorLookup) {
Expand Down