Skip to content

Commit

Permalink
Adds getModelNameToSchemaCache
Browse files Browse the repository at this point in the history
  • Loading branch information
spacether committed Aug 19, 2020
1 parent dcf0f09 commit fa5ac8b
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
package org.openapitools.codegen.languages;

import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.MediaType;
Expand All @@ -28,7 +26,6 @@
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.CodegenDiscriminator.MappedModel;
Expand All @@ -51,11 +48,11 @@
import java.util.regex.Matcher;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

public class PythonClientExperimentalCodegen extends PythonClientCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(PythonClientExperimentalCodegen.class);
// A cache to efficiently lookup a Schema instance based on the return value of `toModelName()`.
private Map<String, Schema> modelNameToSchemaCache;

public PythonClientExperimentalCodegen() {
super();
Expand Down Expand Up @@ -1653,4 +1650,21 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
//codegenParameter.collectionFormat = getCollectionFormat(propertySchema);
return codegenParameter;
}

/**
* Return a map from model name to Schema for efficient lookup.
*
* @return map from model name to Schema.
*/
protected Map<String, Schema> getModelNameToSchemaCache() {
if (modelNameToSchemaCache == null) {
// Create a cache to efficiently lookup schema based on model name.
Map<String, Schema> m = new HashMap<String, Schema>();
ModelUtils.getSchemas(openAPI).forEach((key, schema) -> {
m.put(toModelName(key), schema);
});
modelNameToSchemaCache = Collections.unmodifiableMap(m);
}
return modelNameToSchemaCache;
}
}

0 comments on commit fa5ac8b

Please sign in to comment.