|
17 | 17 | package org.openapitools.codegen.languages;
|
18 | 18 |
|
19 | 19 | import io.swagger.v3.core.util.Json;
|
20 |
| -import io.swagger.v3.oas.models.OpenAPI; |
21 | 20 | import io.swagger.v3.oas.models.Operation;
|
22 |
| -import io.swagger.v3.oas.models.examples.Example; |
23 | 21 | import io.swagger.v3.oas.models.media.*;
|
24 | 22 | import io.swagger.v3.oas.models.media.ArraySchema;
|
25 | 23 | import io.swagger.v3.oas.models.media.MediaType;
|
|
28 | 26 | import io.swagger.v3.oas.models.parameters.RequestBody;
|
29 | 27 | import io.swagger.v3.oas.models.responses.ApiResponse;
|
30 | 28 | import io.swagger.v3.oas.models.security.SecurityScheme;
|
31 |
| -import org.apache.commons.io.FilenameUtils; |
32 | 29 | import org.apache.commons.lang3.StringUtils;
|
33 | 30 | import org.openapitools.codegen.*;
|
34 | 31 | import org.openapitools.codegen.CodegenDiscriminator.MappedModel;
|
|
51 | 48 | import java.util.regex.Matcher;
|
52 | 49 |
|
53 | 50 | 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; |
56 | 51 |
|
57 | 52 | public class PythonClientExperimentalCodegen extends PythonClientCodegen {
|
58 | 53 | 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; |
59 | 56 |
|
60 | 57 | public PythonClientExperimentalCodegen() {
|
61 | 58 | super();
|
@@ -1653,4 +1650,21 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
|
1653 | 1650 | //codegenParameter.collectionFormat = getCollectionFormat(propertySchema);
|
1654 | 1651 | return codegenParameter;
|
1655 | 1652 | }
|
| 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 | + } |
1656 | 1670 | }
|
0 commit comments