Skip to content

Commit fa5ac8b

Browse files
committed
Adds getModelNameToSchemaCache
1 parent dcf0f09 commit fa5ac8b

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package org.openapitools.codegen.languages;
1818

1919
import io.swagger.v3.core.util.Json;
20-
import io.swagger.v3.oas.models.OpenAPI;
2120
import io.swagger.v3.oas.models.Operation;
22-
import io.swagger.v3.oas.models.examples.Example;
2321
import io.swagger.v3.oas.models.media.*;
2422
import io.swagger.v3.oas.models.media.ArraySchema;
2523
import io.swagger.v3.oas.models.media.MediaType;
@@ -28,7 +26,6 @@
2826
import io.swagger.v3.oas.models.parameters.RequestBody;
2927
import io.swagger.v3.oas.models.responses.ApiResponse;
3028
import io.swagger.v3.oas.models.security.SecurityScheme;
31-
import org.apache.commons.io.FilenameUtils;
3229
import org.apache.commons.lang3.StringUtils;
3330
import org.openapitools.codegen.*;
3431
import org.openapitools.codegen.CodegenDiscriminator.MappedModel;
@@ -51,11 +48,11 @@
5148
import java.util.regex.Matcher;
5249

5350
import static org.openapitools.codegen.utils.OnceLogger.once;
54-
import static org.openapitools.codegen.utils.StringUtils.camelize;
55-
import static org.openapitools.codegen.utils.StringUtils.underscore;
5651

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

6057
public PythonClientExperimentalCodegen() {
6158
super();
@@ -1653,4 +1650,21 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
16531650
//codegenParameter.collectionFormat = getCollectionFormat(propertySchema);
16541651
return codegenParameter;
16551652
}
1653+
1654+
/**
1655+
* Return a map from model name to Schema for efficient lookup.
1656+
*
1657+
* @return map from model name to Schema.
1658+
*/
1659+
protected Map<String, Schema> getModelNameToSchemaCache() {
1660+
if (modelNameToSchemaCache == null) {
1661+
// Create a cache to efficiently lookup schema based on model name.
1662+
Map<String, Schema> m = new HashMap<String, Schema>();
1663+
ModelUtils.getSchemas(openAPI).forEach((key, schema) -> {
1664+
m.put(toModelName(key), schema);
1665+
});
1666+
modelNameToSchemaCache = Collections.unmodifiableMap(m);
1667+
}
1668+
return modelNameToSchemaCache;
1669+
}
16561670
}

0 commit comments

Comments
 (0)