Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

v2 improves schema __new__ return type #147

Merged
merged 5 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ private void generateSchema(List<File> files, CodegenSchema schema, String jsonP
Map<String, Object> schemaData = new HashMap<>();
schemaData.put("packageName", config.packageName());
schemaData.put("schema", schema);
schemaData.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
schemaData.putAll(config.additionalProperties());
generateXs(files, jsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.SCHEMA, CodegenConstants.MODELS, schemaData, generateModels);
}
Expand Down Expand Up @@ -475,7 +476,6 @@ private void generatePathItem(List<File> files, CodegenKey pathKey, CodegenPathI
endpointInfo.put("headerSize", "#");
endpointInfo.put("complexTypePrefix", "../../components/schema/");
endpointInfo.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
endpointInfo.put("identifierToHeadingQty", new HashMap<>());
generateXDocs(files, operationJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.OPERATION, CodegenConstants.APIS, endpointInfo, true);

// paths.some_path.security.security_requirement_0.py
Expand Down Expand Up @@ -671,7 +671,6 @@ private TreeMap<String, CodegenResponse> generateResponses(List<File> files) {
templateData.put("complexTypePrefix", "../../components/schema/");
templateData.put("headerSize", "#");
templateData.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
templateData.put("identifierToHeadingQty", new HashMap<>());
templateData.put("response", response);
// TODO make this a property that can be turned off and on
generateXDocs(files, sourceJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.RESPONSE, CodegenConstants.RESPONSE_DOCS, templateData, true);
Expand Down Expand Up @@ -723,7 +722,6 @@ private TreeMap<String, CodegenSecurityScheme> generateSecuritySchemes(List<File
templateData.put("securityScheme", securityScheme);
templateData.put("headerSize", "#");
templateData.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
templateData.put("identifierToHeadingQty", new HashMap<>());
templateData.put("complexTypePrefix", "../../components/schema/");
// TODO add a flag to turn this off
generateXDocs(files, sourceJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.SECURITY_SCHEME, CodegenConstants.SECURITY_SCHEME_DOCS, templateData, true);
Expand Down Expand Up @@ -757,7 +755,6 @@ private TreeMap<String, CodegenRequestBody> generateRequestBodies(List<File> fil
templateData.put("requestBody", requestBody);
templateData.put("headerSize", "#");
templateData.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
templateData.put("identifierToHeadingQty", new HashMap<>());
templateData.put("complexTypePrefix", "../../components/schema/");
// todo add flag to turn this off
generateXDocs(files, sourceJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.REQUEST_BODY, CodegenConstants.REQUEST_BODY_DOCS, templateData, true);
Expand Down Expand Up @@ -807,7 +804,6 @@ private TreeMap<String, CodegenParameter> generateParameters(List<File> files) {
templateData.put("parameter", parameter);
templateData.put("headerSize", "#");
templateData.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
templateData.put("identifierToHeadingQty", new HashMap<>());
templateData.put("complexTypePrefix", "../../components/schema/");
// todo add flag to turn this off
generateXDocs(files, parameterJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.PARAMETER, CodegenConstants.PARAMETER_DOCS, templateData, true);
Expand Down Expand Up @@ -921,7 +917,6 @@ private TreeMap<String, CodegenHeader> generateHeaders(List<File> files) {
templateData.put("complexTypePrefix", "../../components/schema/");
templateData.put("docRoot", "../../");
templateData.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
templateData.put("identifierToHeadingQty", new HashMap<>());
// TODO add flag to turn this off
generateXDocs(files, sourceJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.HEADER, CodegenConstants.HEADER_DOCS, templateData, true);
}
Expand Down Expand Up @@ -999,7 +994,6 @@ protected TreeMap<String, CodegenSchema> generateSchemas(List<File> files) {
// to generate model documentation files
if (generateModelDocumentation) {
schemaData.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
schemaData.put("identifierToHeadingQty", new HashMap<>());
generateSchemaDocumentation(files, schemaData, jsonPath);
}

Expand Down Expand Up @@ -1338,7 +1332,6 @@ private void generateServers(List<File> files, List<CodegenServer> servers, Stri
if (server.rootServer) {
templateData.put("headerSize", "#");
templateData.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
templateData.put("identifierToHeadingQty", new HashMap<>());
generateXDocs(files, serverJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.SERVER, CodegenConstants.SERVERS, templateData, true);
}
i++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AllOf:

{{> components/schemas/_helper_refclass_staticmethod }}
{{else}}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "AllOf" jsonPathPiece) }}
{{/if}}
{{/each}}
classes = [
Expand All @@ -27,7 +27,7 @@ class OneOf:

{{> components/schemas/_helper_refclass_staticmethod }}
{{else}}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "OneOf" jsonPathPiece) }}
{{/if}}
{{/each}}
classes = [
Expand All @@ -48,7 +48,7 @@ class AnyOf:

{{> components/schemas/_helper_refclass_staticmethod }}
{{else}}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "AnyOf" jsonPathPiece) }}
{{/if}}
{{/each}}
classes = [
Expand All @@ -67,7 +67,7 @@ class AnyOf:

{{> components/schemas/_helper_refclass_staticmethod }}
{{else}}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }}
{{/if}}
{{/with}}
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Properties:

{{> components/schemas/_helper_refclass_staticmethod }}
{{else}}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "Properties" jsonPathPiece.camelCase) }}
{{/if}}
{{/each}}
__annotations__ = {
Expand All @@ -49,6 +49,6 @@ class Properties:

{{> components/schemas/_helper_refclass_staticmethod }}
{{else}}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }}
{{/if}}
{{/with}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

{{> components/schemas/_helper_refclass_staticmethod }}
{{else}}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }}
{{/if}}
{{/with}}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __new__(
{{/contains}}
{{/eq}}
{{/with}}
) -> '{{jsonPathPiece.camelCase}}':
) -> '{{#each identifierPieces}}{{#if this.camelCase}}{{this.camelCase}}{{else}}{{this}}{{/if}}{{#unless @last}}.{{/unless}}{{/each}}':
return super().__new__(
cls,
{{#eq types null}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ class {{jsonPathPiece.camelCase}}(
{{> components/schemas/_helper_schema_enum }}
{{/if}}
{{#if items}}
{{> components/schemas/_helper_list_partial }}
{{> components/schemas/_helper_list_partial identifierPieces=(append identifierPieces "Schema_") }}
{{/if}}
{{#or additionalProperties requiredProperties hasDiscriminatorWithNonEmptyMapping properties}}
{{> components/schemas/_helper_dict_partial }}
{{> components/schemas/_helper_dict_partial identifierPieces=(append identifierPieces "Schema_") }}
{{/or}}
{{#unless isStub}}
{{#if hasValidation}}
{{> components/schemas/_helper_validations }}
{{/if}}
{{/unless}}
{{#or allOf anyOf oneOf not}}
{{> components/schemas/_helper_composed_schemas }}
{{> components/schemas/_helper_composed_schemas identifierPieces=(append identifierPieces "Schema_") }}
{{/or}}
{{#if enumValueToName}}
{{> components/schemas/_helper_enums }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class {{jsonPathPiece.camelCase}}(


class Schema_:
{{> components/schemas/_helper_dict_partial }}
{{> components/schemas/_helper_dict_partial identifierPieces=(append identifierPieces "Schema_") }}
{{/or}}
{{else}}
{{#or additionalProperties requiredProperties hasDiscriminatorWithNonEmptyMapping properties hasValidation}}


class Schema_:
types = {frozendict.frozendict}
{{> components/schemas/_helper_dict_partial }}
{{> components/schemas/_helper_dict_partial identifierPieces=(append identifierPieces "Schema_") }}
{{> components/schemas/_helper_validations }}
{{/or}}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class {{jsonPathPiece.camelCase}}(
{{#if hasValidation}}
{{> components/schemas/_helper_validations }}
{{/if}}
{{> components/schemas/_helper_list_partial }}
{{> components/schemas/_helper_list_partial identifierPieces=(append identifierPieces "Schema_") }}
{{/or}}

{{> components/schemas/_helper_new }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

{{/if}}
{{> _helper_imports }}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }}
{{else}}
{{> _helper_imports_schema_types }}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }}
{{#if imports}}

{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from {{packageName}} import server{{#if variables}}, schemas{{/if}}

class _Variables:
{{#each variables}}
{{> components/schemas/_helper_schema_switch_case }}
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "_Variables" jsonPathPiece.camelCase) }}
{{/each}}

_VariablesSchemas = typing_extensions.TypedDict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __new__(
foo: typing.Union[Schema_.Properties.Foo, dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, schemas.Unset] = schemas.unset,
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_0':
) -> 'AdditionalpropertiesShouldNotLookInApplicators.Schema_.AllOf._0':
return super().__new__(
cls,
*args_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class AdditionalpropertiesShouldNotLookInApplicators(
foo: typing.Union[Schema_.Properties.Foo, dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, schemas.Unset] = schemas.unset,
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_0':
) -> 'AdditionalpropertiesShouldNotLookInApplicators.Schema_.AllOf._0':
return super().__new__(
cls,
*args_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __new__(
*args_: typing.Union[dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader],
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_0':
) -> 'Allof.Schema_.AllOf._0':
return super().__new__(
cls,
*args_,
Expand Down Expand Up @@ -160,7 +160,7 @@ def __new__(
*args_: typing.Union[dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader],
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_1':
) -> 'Allof.Schema_.AllOf._1':
return super().__new__(
cls,
*args_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Allof(
*args_: typing.Union[dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader],
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_0':
) -> 'Allof.Schema_.AllOf._0':
return super().__new__(
cls,
*args_,
Expand Down Expand Up @@ -160,7 +160,7 @@ class Allof(
*args_: typing.Union[dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader],
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_1':
) -> 'Allof.Schema_.AllOf._1':
return super().__new__(
cls,
*args_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __new__(
*args_: typing.Union[dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader],
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_0':
) -> 'AllofCombinedWithAnyofOneof.Schema_.AllOf._0':
return super().__new__(
cls,
*args_,
Expand Down Expand Up @@ -83,7 +83,7 @@ def __new__(
*args_: typing.Union[dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader],
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_0':
) -> 'AllofCombinedWithAnyofOneof.Schema_.OneOf._0':
return super().__new__(
cls,
*args_,
Expand Down Expand Up @@ -112,7 +112,7 @@ def __new__(
*args_: typing.Union[dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader],
configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None,
**kwargs: typing.Union[dict, frozendict.frozendict, list, tuple, decimal.Decimal, float, int, str, datetime.date, datetime.datetime, uuid.UUID, bool, None, bytes, io.FileIO, io.BufferedReader, schemas.Schema],
) -> '_0':
) -> 'AllofCombinedWithAnyofOneof.Schema_.AnyOf._0':
return super().__new__(
cls,
*args_,
Expand Down
Loading