Skip to content

Commit

Permalink
Merge branch 'master' into bug/fix-917-python-namespace-package-folders
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario authored Jul 30, 2021
2 parents 1c00e7a + 7e89e84 commit ab0c3af
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 104 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-generators</artifactId>
<version>1.0.27-SNAPSHOT</version>
<version>1.0.28-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
Expand Down Expand Up @@ -252,10 +252,10 @@
</dependency>
</dependencies>
<properties>
<swagger-codegen-version>3.0.27-SNAPSHOT</swagger-codegen-version>
<swagger-parser-version>2.0.26</swagger-parser-version>
<swagger-core-version>2.1.9</swagger-core-version>
<jackson-version>2.11.4</jackson-version>
<swagger-codegen-version>3.0.28-SNAPSHOT</swagger-codegen-version>
<swagger-parser-version>2.0.27</swagger-parser-version>
<swagger-core-version>2.1.10</swagger-core-version>
<jackson-version>2.12.1</jackson-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
<commons-io-version>2.4</commons-io-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,12 +1358,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
addParentContainer(codegenModel, name, schema);
}
else if (schema instanceof MapSchema) {
codegenModel.getVendorExtensions().put(CodegenConstants.IS_MAP_CONTAINER_EXT_NAME, Boolean.TRUE);
codegenModel.getVendorExtensions().put(IS_CONTAINER_EXT_NAME, Boolean.TRUE);
addParentContainer(codegenModel, name, schema);
if (hasSchemaProperties(schema) || hasTrueAdditionalProperties(schema)) {
addAdditionPropertiesToCodeGenModel(codegenModel, schema);
}
processMapSchema(codegenModel, name, schema);

}
else if (schema instanceof ComposedSchema) {
Expand Down Expand Up @@ -1493,6 +1488,15 @@ else if (schema instanceof ComposedSchema) {
return codegenModel;
}

protected void processMapSchema(CodegenModel codegenModel, String name, Schema schema) {
codegenModel.getVendorExtensions().put(CodegenConstants.IS_MAP_CONTAINER_EXT_NAME, Boolean.TRUE);
codegenModel.getVendorExtensions().put(IS_CONTAINER_EXT_NAME, Boolean.TRUE);
addParentContainer(codegenModel, name, schema);
if (hasSchemaProperties(schema) || hasTrueAdditionalProperties(schema)) {
addAdditionPropertiesToCodeGenModel(codegenModel, schema);
}
}

/**
* Recursively look for a discriminator in the interface tree
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ private Object resolveSchemaToExample(String propertyName, String mediaType, Sch
Schema innerType = ((ArraySchema) schema).getItems();
if (innerType != null) {
int arrayLength = schema.getMaxItems() != null ? schema.getMaxItems() : 2;
if (arrayLength > 10) {
logger.warn("value of maxItems of property {} is {}; limiting to 10 examples", schema, arrayLength);
arrayLength = 10;
}
Object[] objectProperties = new Object[arrayLength];
Object objProperty = resolveSchemaToExample(propertyName, mediaType, innerType, processedModels);
for(int i=0; i < arrayLength; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,11 @@ protected List<Map<String, Object>> modelInheritanceSupport(List<?> allModels) {
Map<String, Object> parent = new HashMap<>();
parent.put("classname", parentModel.classname);
List<CodegenModel> childrenModels = byParent.get(parentModel);

if (childrenModels == null || childrenModels.isEmpty()) {
continue;
}

for (CodegenModel model : childrenModels) {
Map<String, Object> child = new HashMap<>();
child.put("name", model.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import io.swagger.v3.oas.models.media.Schema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.jknack.handlebars.helper.StringHelpers;
import com.github.jknack.handlebars.Handlebars;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -506,6 +508,12 @@ public String toVarName(String name) {
return super.toVarName(sanitizeKotlinSpecificNames(name));
}

@Override
public void addHandlebarHelpers(Handlebars handlebars) {
super.addHandlebarHelpers(handlebars);
handlebars.registerHelpers(StringHelpers.class);
}

/**
* Provides a strongly typed declaration for simple arrays of some type and arrays of arrays of some type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.github.jknack.handlebars.helper.StringHelpers;
import com.github.jknack.handlebars.Handlebars;
import org.apache.commons.lang3.StringUtils;

import static java.util.Collections.singletonMap;
Expand Down Expand Up @@ -228,12 +226,6 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt"));
}

@Override
public void addHandlebarHelpers(Handlebars handlebars) {
super.addHandlebarHelpers(handlebars);
handlebars.registerHelpers(StringHelpers.class);
}

@Override
public String getDefaultTemplateDir() {
return "kotlin-server";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,40 @@

import io.swagger.codegen.v3.CliOption;
import io.swagger.codegen.v3.CodegenConstants;
import io.swagger.codegen.v3.CodegenModel;
import io.swagger.codegen.v3.CodegenOperation;
import io.swagger.codegen.v3.CodegenParameter;
import io.swagger.codegen.v3.CodegenProperty;
import io.swagger.codegen.v3.CodegenSecurity;
import io.swagger.codegen.v3.CodegenType;
import io.swagger.codegen.v3.SupportingFile;
import io.swagger.codegen.v3.generators.DefaultCodegenConfig;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.BooleanSchema;
import io.swagger.v3.oas.models.media.DateSchema;
import io.swagger.v3.oas.models.media.DateTimeSchema;
import io.swagger.v3.oas.models.media.IntegerSchema;
import io.swagger.v3.oas.models.media.MapSchema;
import io.swagger.v3.oas.models.media.NumberSchema;
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.HashSet;
import java.util.regex.Matcher;

import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.apache.commons.lang3.StringUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static io.swagger.codegen.v3.generators.handlebars.ExtensionHelper.getBooleanValue;

public class PhpClientCodegen extends DefaultCodegenConfig {
Expand Down Expand Up @@ -444,6 +452,12 @@ public void setComposerProjectName(String composerProjectName) {
this.composerProjectName = composerProjectName;
}

@Override
protected void processMapSchema(CodegenModel codegenModel, String name, Schema schema) {
super.processMapSchema(codegenModel, name, schema);
addVars(codegenModel, schema.getProperties(), schema.getRequired());
}

@Override
public String toVarName(String name) {
// sanitize name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public void processOpts() {
}

if (additionalProperties.containsKey(CodegenConstants.PROJECT_NAME)) {
setProjectName((String) additionalProperties.get(CodegenConstants.PROJECT_NAME));
String projectName = (String) additionalProperties.get(CodegenConstants.PROJECT_NAME);
setProjectName(projectName.replaceAll("[^a-zA-Z0-9\\s\\-_]",""));
}
else {
// default: set project based on package name
Expand Down Expand Up @@ -470,6 +471,10 @@ public String toParamName(String name) {

@Override
public String toModelName(String name) {
if (name == null) {
// sanitizeName will return "Object" for null, but this is called "object" in python
return "object";
}
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// remove dollar sign
name = name.replaceAll("$", "");
Expand Down
Loading

0 comments on commit ab0c3af

Please sign in to comment.