Skip to content

Commit

Permalink
Merge pull request #728 from Backbase/feat/generate-podfile-too
Browse files Browse the repository at this point in the history
Add `dependenciesAs` additional property to allow for `Podfile` generation
  • Loading branch information
DevAgani authored Jan 8, 2024
2 parents cc13b23 + 1d800f7 commit a98014a
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.SupportingFile;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.WordUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.utils.ModelUtils;

import java.util.*;


public class BoatSwift5Codegen extends Swift5ClientCodegen implements CodegenConfig {
private static final String LIBRARY_DBS = "dbsDataProvider";
public static final String LIBRARY_DBS = "dbsDataProvider";
public static final String DEPENDENCY_MANAGEMENT = "dependenciesAs";
public static final String DEPENDENCY_MANAGEMENT_PODFILE = "Podfile";
protected static final String DEPENDENCY_MANAGEMENT_CARTFILE = "Cartfile";
protected static final String[] DEPENDENCY_MANAGEMENT_OPTIONS = {DEPENDENCY_MANAGEMENT_CARTFILE, DEPENDENCY_MANAGEMENT_PODFILE};
protected String[] dependenciesAs = new String[0];

/**
* Constructor for the BoatSwift5Codegen codegen module.
Expand All @@ -38,6 +42,11 @@ public BoatSwift5Codegen() {
this.typeMapping.remove("AnyType");
this.typeMapping.put("object", "Any");
this.typeMapping.put("AnyType", "Any");

cliOptions.add(new CliOption(DEPENDENCY_MANAGEMENT,
"Available dependency managers "
+ StringUtils.join(DEPENDENCY_MANAGEMENT_OPTIONS, ", ")
+ " are available."));
}

@Override
Expand All @@ -55,7 +64,20 @@ public void processOpts() {
super.processOpts();
additionalProperties.put("useDBSDataProvider", getLibrary().equals(LIBRARY_DBS));
supportingFiles.add(new SupportingFile("AnyCodable.swift.mustache", sourceFolder, "AnyCodable.swift"));
this.supportingFiles.add(new SupportingFile("AnyCodable.swift.mustache", this.sourceFolder, "AnyCodable.swift"));

if (additionalProperties.containsKey(DEPENDENCY_MANAGEMENT)) {
Object dependenciesAsObject = additionalProperties.get(DEPENDENCY_MANAGEMENT);
if (dependenciesAsObject instanceof String) {
setDependenciesAs((WordUtils.capitalizeFully((String) dependenciesAsObject).split(",")));
}
}

additionalProperties.put(DEPENDENCY_MANAGEMENT, dependenciesAs);
if (ArrayUtils.contains(dependenciesAs, DEPENDENCY_MANAGEMENT_PODFILE)) {
supportingFiles.add(new SupportingFile("Podfile.mustache",
"",
DEPENDENCY_MANAGEMENT_PODFILE));
}
}

// Fix issues with generating arrays with Set.
Expand All @@ -71,7 +93,6 @@ public String getTypeDeclaration(Schema p) {

@Override
public CodegenModel fromModel(String name, Schema model) {
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
CodegenModel codegenModel = super.fromModel(name, model);
if (codegenModel.description != null) {
codegenModel.imports.add("ApiModel");
Expand All @@ -82,6 +103,11 @@ public CodegenModel fromModel(String name, Schema model) {
return codegenModel;
}

public void setDependenciesAs(String[] dependenciesAs) {
this.dependenciesAs = dependenciesAs;
}


/*
This is added as a compatibility requirement for API specs containing free form objects
missing `additionalProperties` property
Expand Down
Loading

0 comments on commit a98014a

Please sign in to comment.