diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/config.yaml b/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/config.yaml deleted file mode 100644 index 406cd114b..000000000 --- a/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -files: - handlers.handlebars: - destinationFilename: {{src}}/__all_handlers.py - templateType: SupportingFiles - tests.handlebars: - destinationFilename: {{tst}}/__all_tests.py - templateType: SupportingFiles \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/handlers.ejs b/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/handlers.ejs new file mode 100644 index 000000000..af4234020 --- /dev/null +++ b/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/handlers.ejs @@ -0,0 +1,40 @@ +<%_ services.forEach((service) => { _%> +<%_ service.operations.forEach((operation) => { _%> +<%_ if (operation.vendorExtensions && operation.vendorExtensions['x-handler'] && operation.vendorExtensions['x-handler'].language === 'python') { _%> +###TSAPI_WRITE_FILE### +{ + "id": "<%- operation.name %>", + "dir": "<%- metadata.srcDir || 'src' %>", + "name": "<%- operation.operationIdSnakeCase %>", + "ext": ".py", + "overwrite": false +} +###/TSAPI_WRITE_FILE###from <%- metadata.runtimeModuleName %>.models import * +from <%- metadata.runtimeModuleName %>.response import Response +from <%- metadata.runtimeModuleName %>.interceptors import INTERCEPTORS +from <%- metadata.runtimeModuleName %>.interceptors.powertools.logger import LoggingInterceptor +from <%- metadata.runtimeModuleName %>.api.operation_config import ( + <%- operation.operationIdSnakeCase %>_handler, <%- operation.operationIdPascalCase %>Request, <%- operation.operationIdPascalCase %>OperationResponses +) + + +def <%- operation.operationIdSnakeCase %>(input: <%- operation.operationIdPascalCase %>Request, **kwargs) -> <%- operation.operationIdPascalCase %>OperationResponses: + """ + Type-safe handler for the <%- operation.operationIdPascalCase %> operation + """ + LoggingInterceptor.get_logger(input).info("Start <%- operation.operationIdPascalCase %> Operation") + + # TODO: Implement <%- operation.operationIdPascalCase %> Operation. `input` contains the request input + + return Response.internal_failure(InternalFailureErrorResponseContent( + message="Not Implemented!" + )) + + +# Entry point for the AWS Lambda handler for the <%- operation.operationIdPascalCase %> operation. +# The <%- operation.operationIdSnakeCase %>_handler method wraps the type-safe handler and manages marshalling inputs and outputs +handler = <%- operation.operationIdSnakeCase %>_handler(interceptors=INTERCEPTORS)(<%- operation.operationIdSnakeCase %>) + +<%_ } _%> +<%_ }); _%> +<%_ }); _%> \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/handlers.handlebars b/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/handlers.handlebars deleted file mode 100644 index f0ab58e2a..000000000 --- a/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/handlers.handlebars +++ /dev/null @@ -1,47 +0,0 @@ -###TSAPI_SPLIT_FILE### -{{#apiInfo ~}} -{{#apis ~}} -{{#operations ~}} -{{#operation ~}} -{{#if vendorExtensions.x-handler}} -{{#startsWith vendorExtensions.x-handler.language 'python'}} -###TSAPI_WRITE_FILE### -{ - "id": "{{operationId}}", - "dir": ".", - "name": "{{operationId}}", - "ext": ".py", - "overwrite": false -} -###/TSAPI_WRITE_FILE###from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.models import * -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.response import Response -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.interceptors import INTERCEPTORS -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.interceptors.powertools.logger import LoggingInterceptor -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.api.operation_config import ( - {{operationId}}_handler, {{operationIdCamelCase}}Request, {{operationIdCamelCase}}OperationResponses -) - - -def {{operationId}}(input: {{operationIdCamelCase}}Request, **kwargs) -> {{operationIdCamelCase}}OperationResponses: - """ - Type-safe handler for the {{operationIdCamelCase}} operation - """ - LoggingInterceptor.get_logger(input).info("Start {{operationIdCamelCase}} Operation") - - # TODO: Implement {{operationIdCamelCase}} Operation. `input` contains the request input - - return Response.internal_failure(InternalFailureErrorResponseContent( - message="Not Implemented!" - )) - - -# Entry point for the AWS Lambda handler for the {{operationIdCamelCase}} operation. -# The {{operationId}}_handler method wraps the type-safe handler and manages marshalling inputs and outputs -handler = {{operationId}}_handler(interceptors=INTERCEPTORS)({{operationId}}) - -{{~/startsWith}} -{{~/if}} -{{~/operation}} -{{~/operations}} -{{~/apis}} -{{~/apiInfo}} \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/tests.ejs b/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/tests.ejs new file mode 100644 index 000000000..fac78f7d3 --- /dev/null +++ b/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/tests.ejs @@ -0,0 +1,65 @@ +###TSAPI_WRITE_FILE### +{ + "dir": "<%- metadata.tstDir || 'tst' %>", + "name": "__init__", + "ext": ".py", + "overwrite": false +} +###/TSAPI_WRITE_FILE#### +<%_ services.forEach((service) => { _%> +<%_ service.operations.forEach((operation) => { _%> +<%_ if (operation.vendorExtensions && operation.vendorExtensions['x-handler'] && operation.vendorExtensions['x-handler'].language === 'python') { _%> +###TSAPI_WRITE_FILE### +{ + "id": "test_<%- operation.operationIdSnakeCase %>", + "dir": "<%- metadata.tstDir || 'tst' %>", + "name": "test_<%- operation.operationIdSnakeCase %>", + "ext": ".py", + "overwrite": false, + "generateConditionallyId": "<%- operation.name %>" +} +###/TSAPI_WRITE_FILE###import pytest +from aws_lambda_powertools import Logger + +from <%- metadata.moduleName %>.<%- operation.operationIdSnakeCase %> import <%- operation.operationIdSnakeCase %> +from <%- metadata.runtimeModuleName %>.api.operation_config import ( + <%- operation.operationIdPascalCase %>Request, <%- operation.operationIdPascalCase %>RequestParameters, <%- operation.operationIdPascalCase %>RequestBody +) + + +@pytest.fixture +def request_arguments(): + """ + Fixture for constructing common request arguments + """ + return { + "event": {}, + "context": None, + "interceptor_context": { + "logger": Logger(), + }, + } + + +def test_<%- operation.operationIdSnakeCase %>_should_return_not_implemented_error(request_arguments): + # TODO: Update the test as appropriate when you implement your handler + response = <%- operation.operationIdSnakeCase %>(<%- operation.operationIdPascalCase %>Request( + **request_arguments, + # request_parameters=<%- operation.operationIdPascalCase %>RequestParameters( + # # Add request parameters here... + # ), + request_parameters=None, + <%_ if (operation.parametersBody) { %> + # body=<%- operation.operationIdPascalCase %>RequestBody( + # # Add body fields here... + # ) + <%_ } _%> + body=None, + )) + + assert response.status_code == 500 + assert response.body.message == "Not Implemented!" + +<%_ } _%> +<%_ }); _%> +<%_ }); _%> \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/tests.handlebars b/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/tests.handlebars deleted file mode 100644 index 7b4c26aac..000000000 --- a/packages/type-safe-api/scripts/type-safe-api/generators/python-async-lambda-handlers/templates/tests.handlebars +++ /dev/null @@ -1,72 +0,0 @@ -###TSAPI_SPLIT_FILE### -###TSAPI_WRITE_FILE### -{ - "dir": ".", - "name": "__init__", - "ext": ".py", - "overwrite": false -} -###/TSAPI_WRITE_FILE#### -{{#apiInfo ~}} -{{#apis ~}} -{{#operations ~}} -{{#operation ~}} -{{#if vendorExtensions.x-handler}} -{{#startsWith vendorExtensions.x-handler.language 'python'}} -###TSAPI_WRITE_FILE### -{ - "id": "test_{{operationId}}", - "dir": ".", - "name": "test_{{operationId}}", - "ext": ".py", - "overwrite": false, - "generateConditionallyId": "{{operationId}}" -} -###/TSAPI_WRITE_FILE###import pytest -from aws_lambda_powertools import Logger - -from {{packageName}}.{{operationId}} import {{operationId}} -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.api.operation_config import ( - {{operationIdCamelCase}}Request, {{operationIdCamelCase}}RequestParameters, {{operationIdCamelCase}}RequestBody -) - - -@pytest.fixture -def request_arguments(): - """ - Fixture for constructing common request arguments - """ - return { - "event": {}, - "context": None, - "interceptor_context": { - "logger": Logger(), - }, - } - - -def test_{{operationId}}_should_return_not_implemented_error(request_arguments): - # TODO: Update the test as appropriate when you implement your handler - response = {{operationId}}({{operationIdCamelCase}}Request( - **request_arguments, - # request_parameters={{operationIdCamelCase}}RequestParameters( - # # Add request parameters here... - # ), - request_parameters=None, - {{#unless bodyParams.isEmpty ~}} - # body={{operationIdCamelCase}}RequestBody( - # # Add body fields here... - # ) - {{~/unless}} - body=None, - )) - - assert response.status_code == 500 - assert response.body.message == "Not Implemented!" - -{{~/startsWith}} -{{~/if}} -{{~/operation}} -{{~/operations}} -{{~/apis}} -{{~/apiInfo}} \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/config.yaml b/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/config.yaml deleted file mode 100644 index 406cd114b..000000000 --- a/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -files: - handlers.handlebars: - destinationFilename: {{src}}/__all_handlers.py - templateType: SupportingFiles - tests.handlebars: - destinationFilename: {{tst}}/__all_tests.py - templateType: SupportingFiles \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/handlers.ejs b/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/handlers.ejs new file mode 100644 index 000000000..af4234020 --- /dev/null +++ b/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/handlers.ejs @@ -0,0 +1,40 @@ +<%_ services.forEach((service) => { _%> +<%_ service.operations.forEach((operation) => { _%> +<%_ if (operation.vendorExtensions && operation.vendorExtensions['x-handler'] && operation.vendorExtensions['x-handler'].language === 'python') { _%> +###TSAPI_WRITE_FILE### +{ + "id": "<%- operation.name %>", + "dir": "<%- metadata.srcDir || 'src' %>", + "name": "<%- operation.operationIdSnakeCase %>", + "ext": ".py", + "overwrite": false +} +###/TSAPI_WRITE_FILE###from <%- metadata.runtimeModuleName %>.models import * +from <%- metadata.runtimeModuleName %>.response import Response +from <%- metadata.runtimeModuleName %>.interceptors import INTERCEPTORS +from <%- metadata.runtimeModuleName %>.interceptors.powertools.logger import LoggingInterceptor +from <%- metadata.runtimeModuleName %>.api.operation_config import ( + <%- operation.operationIdSnakeCase %>_handler, <%- operation.operationIdPascalCase %>Request, <%- operation.operationIdPascalCase %>OperationResponses +) + + +def <%- operation.operationIdSnakeCase %>(input: <%- operation.operationIdPascalCase %>Request, **kwargs) -> <%- operation.operationIdPascalCase %>OperationResponses: + """ + Type-safe handler for the <%- operation.operationIdPascalCase %> operation + """ + LoggingInterceptor.get_logger(input).info("Start <%- operation.operationIdPascalCase %> Operation") + + # TODO: Implement <%- operation.operationIdPascalCase %> Operation. `input` contains the request input + + return Response.internal_failure(InternalFailureErrorResponseContent( + message="Not Implemented!" + )) + + +# Entry point for the AWS Lambda handler for the <%- operation.operationIdPascalCase %> operation. +# The <%- operation.operationIdSnakeCase %>_handler method wraps the type-safe handler and manages marshalling inputs and outputs +handler = <%- operation.operationIdSnakeCase %>_handler(interceptors=INTERCEPTORS)(<%- operation.operationIdSnakeCase %>) + +<%_ } _%> +<%_ }); _%> +<%_ }); _%> \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/handlers.handlebars b/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/handlers.handlebars deleted file mode 100644 index f0ab58e2a..000000000 --- a/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/handlers.handlebars +++ /dev/null @@ -1,47 +0,0 @@ -###TSAPI_SPLIT_FILE### -{{#apiInfo ~}} -{{#apis ~}} -{{#operations ~}} -{{#operation ~}} -{{#if vendorExtensions.x-handler}} -{{#startsWith vendorExtensions.x-handler.language 'python'}} -###TSAPI_WRITE_FILE### -{ - "id": "{{operationId}}", - "dir": ".", - "name": "{{operationId}}", - "ext": ".py", - "overwrite": false -} -###/TSAPI_WRITE_FILE###from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.models import * -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.response import Response -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.interceptors import INTERCEPTORS -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.interceptors.powertools.logger import LoggingInterceptor -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.api.operation_config import ( - {{operationId}}_handler, {{operationIdCamelCase}}Request, {{operationIdCamelCase}}OperationResponses -) - - -def {{operationId}}(input: {{operationIdCamelCase}}Request, **kwargs) -> {{operationIdCamelCase}}OperationResponses: - """ - Type-safe handler for the {{operationIdCamelCase}} operation - """ - LoggingInterceptor.get_logger(input).info("Start {{operationIdCamelCase}} Operation") - - # TODO: Implement {{operationIdCamelCase}} Operation. `input` contains the request input - - return Response.internal_failure(InternalFailureErrorResponseContent( - message="Not Implemented!" - )) - - -# Entry point for the AWS Lambda handler for the {{operationIdCamelCase}} operation. -# The {{operationId}}_handler method wraps the type-safe handler and manages marshalling inputs and outputs -handler = {{operationId}}_handler(interceptors=INTERCEPTORS)({{operationId}}) - -{{~/startsWith}} -{{~/if}} -{{~/operation}} -{{~/operations}} -{{~/apis}} -{{~/apiInfo}} \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/tests.ejs b/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/tests.ejs new file mode 100644 index 000000000..fac78f7d3 --- /dev/null +++ b/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/tests.ejs @@ -0,0 +1,65 @@ +###TSAPI_WRITE_FILE### +{ + "dir": "<%- metadata.tstDir || 'tst' %>", + "name": "__init__", + "ext": ".py", + "overwrite": false +} +###/TSAPI_WRITE_FILE#### +<%_ services.forEach((service) => { _%> +<%_ service.operations.forEach((operation) => { _%> +<%_ if (operation.vendorExtensions && operation.vendorExtensions['x-handler'] && operation.vendorExtensions['x-handler'].language === 'python') { _%> +###TSAPI_WRITE_FILE### +{ + "id": "test_<%- operation.operationIdSnakeCase %>", + "dir": "<%- metadata.tstDir || 'tst' %>", + "name": "test_<%- operation.operationIdSnakeCase %>", + "ext": ".py", + "overwrite": false, + "generateConditionallyId": "<%- operation.name %>" +} +###/TSAPI_WRITE_FILE###import pytest +from aws_lambda_powertools import Logger + +from <%- metadata.moduleName %>.<%- operation.operationIdSnakeCase %> import <%- operation.operationIdSnakeCase %> +from <%- metadata.runtimeModuleName %>.api.operation_config import ( + <%- operation.operationIdPascalCase %>Request, <%- operation.operationIdPascalCase %>RequestParameters, <%- operation.operationIdPascalCase %>RequestBody +) + + +@pytest.fixture +def request_arguments(): + """ + Fixture for constructing common request arguments + """ + return { + "event": {}, + "context": None, + "interceptor_context": { + "logger": Logger(), + }, + } + + +def test_<%- operation.operationIdSnakeCase %>_should_return_not_implemented_error(request_arguments): + # TODO: Update the test as appropriate when you implement your handler + response = <%- operation.operationIdSnakeCase %>(<%- operation.operationIdPascalCase %>Request( + **request_arguments, + # request_parameters=<%- operation.operationIdPascalCase %>RequestParameters( + # # Add request parameters here... + # ), + request_parameters=None, + <%_ if (operation.parametersBody) { %> + # body=<%- operation.operationIdPascalCase %>RequestBody( + # # Add body fields here... + # ) + <%_ } _%> + body=None, + )) + + assert response.status_code == 500 + assert response.body.message == "Not Implemented!" + +<%_ } _%> +<%_ }); _%> +<%_ }); _%> \ No newline at end of file diff --git a/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/tests.handlebars b/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/tests.handlebars deleted file mode 100644 index 7b4c26aac..000000000 --- a/packages/type-safe-api/scripts/type-safe-api/generators/python-lambda-handlers/templates/tests.handlebars +++ /dev/null @@ -1,72 +0,0 @@ -###TSAPI_SPLIT_FILE### -###TSAPI_WRITE_FILE### -{ - "dir": ".", - "name": "__init__", - "ext": ".py", - "overwrite": false -} -###/TSAPI_WRITE_FILE#### -{{#apiInfo ~}} -{{#apis ~}} -{{#operations ~}} -{{#operation ~}} -{{#if vendorExtensions.x-handler}} -{{#startsWith vendorExtensions.x-handler.language 'python'}} -###TSAPI_WRITE_FILE### -{ - "id": "test_{{operationId}}", - "dir": ".", - "name": "test_{{operationId}}", - "ext": ".py", - "overwrite": false, - "generateConditionallyId": "{{operationId}}" -} -###/TSAPI_WRITE_FILE###import pytest -from aws_lambda_powertools import Logger - -from {{packageName}}.{{operationId}} import {{operationId}} -from {{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-runtime-module-name}}{{/apis.0}}{{/apiInfo}}.api.operation_config import ( - {{operationIdCamelCase}}Request, {{operationIdCamelCase}}RequestParameters, {{operationIdCamelCase}}RequestBody -) - - -@pytest.fixture -def request_arguments(): - """ - Fixture for constructing common request arguments - """ - return { - "event": {}, - "context": None, - "interceptor_context": { - "logger": Logger(), - }, - } - - -def test_{{operationId}}_should_return_not_implemented_error(request_arguments): - # TODO: Update the test as appropriate when you implement your handler - response = {{operationId}}({{operationIdCamelCase}}Request( - **request_arguments, - # request_parameters={{operationIdCamelCase}}RequestParameters( - # # Add request parameters here... - # ), - request_parameters=None, - {{#unless bodyParams.isEmpty ~}} - # body={{operationIdCamelCase}}RequestBody( - # # Add body fields here... - # ) - {{~/unless}} - body=None, - )) - - assert response.status_code == 500 - assert response.body.message == "Not Implemented!" - -{{~/startsWith}} -{{~/if}} -{{~/operation}} -{{~/operations}} -{{~/apis}} -{{~/apiInfo}} \ No newline at end of file diff --git a/packages/type-safe-api/src/project/codegen/handlers/generated-python-async-handlers-project.ts b/packages/type-safe-api/src/project/codegen/handlers/generated-python-async-handlers-project.ts index 186b357bc..80ccb7c21 100644 --- a/packages/type-safe-api/src/project/codegen/handlers/generated-python-async-handlers-project.ts +++ b/packages/type-safe-api/src/project/codegen/handlers/generated-python-async-handlers-project.ts @@ -4,7 +4,7 @@ import { GeneratedPythonHandlersBaseProject, GeneratedPythonHandlersBaseProjectOptions, } from "./generated-python-handlers-base-project"; -import { GenerationOptions, OtherGenerators } from "../components/utils"; +import { CodegenOptions, OtherGenerators } from "../components/utils"; export interface GeneratedPythonAsyncHandlersProjectOptions extends GeneratedPythonHandlersBaseProjectOptions {} @@ -14,23 +14,15 @@ export class GeneratedPythonAsyncHandlersProject extends GeneratedPythonHandlers super(options); } - public buildOpenApiGeneratorOptions(): GenerationOptions { + public buildCodegenOptions(): CodegenOptions { return { - generator: "python-nextgen", specPath: this.options.specPath, - generatorDirectory: OtherGenerators.PYTHON_ASYNC_LAMBDA_HANDLERS, - // Tell the generator where python source files live - srcDir: this.moduleName, - tstDir: this.tstDir, - additionalProperties: { - packageName: this.moduleName, - projectName: this.name, - }, - normalizers: { - KEEP_ONLY_FIRST_TAG_IN_OPERATION: true, - }, - extraVendorExtensions: { - "x-runtime-module-name": this.options.generatedPythonTypes.moduleName, + templateDirs: [OtherGenerators.PYTHON_ASYNC_LAMBDA_HANDLERS], + metadata: { + srcDir: this.moduleName, + tstDir: this.tstDir, + runtimeModuleName: this.options.generatedPythonTypes.moduleName, + moduleName: this.moduleName, }, }; } diff --git a/packages/type-safe-api/src/project/codegen/handlers/generated-python-handlers-base-project.ts b/packages/type-safe-api/src/project/codegen/handlers/generated-python-handlers-base-project.ts index 7ef9ea221..c0bda7883 100644 --- a/packages/type-safe-api/src/project/codegen/handlers/generated-python-handlers-base-project.ts +++ b/packages/type-safe-api/src/project/codegen/handlers/generated-python-handlers-base-project.ts @@ -9,15 +9,11 @@ import { GeneratedPythonHandlersOptions, Architecture, } from "../../types"; -import { OpenApiGeneratorHandlebarsIgnoreFile } from "../components/open-api-generator-handlebars-ignore-file"; -import { OpenApiGeneratorIgnoreFile } from "../components/open-api-generator-ignore-file"; -import { OpenApiToolsJsonFile } from "../components/open-api-tools-json-file"; import { TypeSafeApiCommandEnvironment } from "../components/type-safe-api-command-environment"; import { - buildCleanOpenApiGeneratedCodeCommand, - buildInvokeOpenApiGeneratorCommandArgs, + buildCodegenCommandArgs, buildTypeSafeApiExecCommand, - GenerationOptions, + CodegenOptions, TypeSafeApiScript, } from "../components/utils"; import { GeneratedPythonRuntimeBaseProject } from "../runtime/generated-python-runtime-base-project"; @@ -86,32 +82,10 @@ export abstract class GeneratedPythonHandlersBaseProject extends PythonProject { .filter((dep) => !this.deps.tryGetDependency(dep, DependencyType.RUNTIME)) .forEach((dep) => this.addDependency(dep)); - // Ignore everything for the first mustache pass - const openapiGeneratorIgnore = new OpenApiGeneratorIgnoreFile(this); - openapiGeneratorIgnore.addPatterns("/*", "**/*", "*"); - // Ignore everything but the handler files for the handlebars pass - const openapiGeneratorHandlebarsIgnore = - new OpenApiGeneratorHandlebarsIgnoreFile(this); - openapiGeneratorHandlebarsIgnore.addPatterns( - "/*", - "**/*", - "*", - // This will be split into a file per targeted handler - `!${this.moduleName}/__all_handlers.py`, - `!${this.tstDir}/__all_tests.py` - ); - - // Add OpenAPI Generator cli configuration - OpenApiToolsJsonFile.ensure(this).addOpenApiGeneratorCliConfig({ - version: "6.6.0", - ...options.openApiGeneratorCliConfig, - }); - const generateTask = this.addTask("generate"); - generateTask.exec(buildCleanOpenApiGeneratedCodeCommand()); generateTask.exec( buildTypeSafeApiExecCommand( - TypeSafeApiScript.GENERATE, + TypeSafeApiScript.GENERATE_NEXT, this.buildGenerateCommandArgs() ) ); @@ -119,7 +93,7 @@ export abstract class GeneratedPythonHandlersBaseProject extends PythonProject { this.preCompileTask.spawn(generateTask); // Ignore the generated code - this.gitignore.addPatterns(".openapi-generator"); + this.gitignore.addPatterns(".openapi-generator", ".tsapi-manifest"); // Write __init__.py as sample code new SampleFile(this, path.join(this.moduleName, "__init__.py"), { @@ -148,10 +122,8 @@ export abstract class GeneratedPythonHandlersBaseProject extends PythonProject { } public buildGenerateCommandArgs = () => { - return buildInvokeOpenApiGeneratorCommandArgs( - this.buildOpenApiGeneratorOptions() - ); + return buildCodegenCommandArgs(this.buildCodegenOptions()); }; - public abstract buildOpenApiGeneratorOptions(): GenerationOptions; + public abstract buildCodegenOptions(): CodegenOptions; } diff --git a/packages/type-safe-api/src/project/codegen/handlers/generated-python-handlers-project.ts b/packages/type-safe-api/src/project/codegen/handlers/generated-python-handlers-project.ts index 68bbbb879..5430fa89d 100644 --- a/packages/type-safe-api/src/project/codegen/handlers/generated-python-handlers-project.ts +++ b/packages/type-safe-api/src/project/codegen/handlers/generated-python-handlers-project.ts @@ -4,7 +4,7 @@ import { GeneratedPythonHandlersBaseProject, GeneratedPythonHandlersBaseProjectOptions, } from "./generated-python-handlers-base-project"; -import { GenerationOptions, OtherGenerators } from "../components/utils"; +import { CodegenOptions, OtherGenerators } from "../components/utils"; export interface GeneratedPythonHandlersProjectOptions extends GeneratedPythonHandlersBaseProjectOptions {} @@ -14,23 +14,15 @@ export class GeneratedPythonHandlersProject extends GeneratedPythonHandlersBaseP super(options); } - public buildOpenApiGeneratorOptions(): GenerationOptions { + public buildCodegenOptions(): CodegenOptions { return { - generator: "python-nextgen", specPath: this.options.specPath, - generatorDirectory: OtherGenerators.PYTHON_LAMBDA_HANDLERS, - // Tell the generator where python source files live - srcDir: this.moduleName, - tstDir: this.tstDir, - additionalProperties: { - packageName: this.moduleName, - projectName: this.name, - }, - normalizers: { - KEEP_ONLY_FIRST_TAG_IN_OPERATION: true, - }, - extraVendorExtensions: { - "x-runtime-module-name": this.options.generatedPythonTypes.moduleName, + templateDirs: [OtherGenerators.PYTHON_LAMBDA_HANDLERS], + metadata: { + srcDir: this.moduleName, + tstDir: this.tstDir, + runtimeModuleName: this.options.generatedPythonTypes.moduleName, + moduleName: this.moduleName, }, }; } diff --git a/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap b/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap index ae622ba67..5d82ef7b0 100644 --- a/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap +++ b/packages/type-safe-api/test/project/__snapshots__/type-safe-api-project.test.ts.snap @@ -31116,9 +31116,6 @@ dist/java /.gitattributes linguist-generated /.gitignore linguist-generated -/.openapi-generator-ignore linguist-generated -/.openapi-generator-ignore-handlebars linguist-generated -/.pdk/dynamic-files/openapitools.json linguist-generated /.projen/** linguist-generated /.projen/deps.json linguist-generated /.projen/files.json linguist-generated @@ -31208,35 +31205,10 @@ dmypy.json .pyre/ .pytype/ cython_debug/ -!/.openapi-generator-ignore -!/.openapi-generator-ignore-handlebars -!/.pdk/dynamic-files/openapitools.json -/openapitools.json .openapi-generator +.tsapi-manifest !/project.json ", - "handlers/python/.openapi-generator-ignore": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". -.gitignore -/* -**/* -* -", - "handlers/python/.openapi-generator-ignore-handlebars": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". -/* -**/* -* -!smithy_handlers_python_handlers/__all_handlers.py -!test/__all_tests.py -", - "handlers/python/.pdk/dynamic-files/openapitools.json": { - "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", - "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", - "generator-cli": { - "storageDir": "~/.open-api-generator-cli", - "version": "6.6.0", - }, - "spaces": 2, - }, "handlers/python/.projen/deps.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".", "dependencies": [ @@ -31262,9 +31234,6 @@ cython_debug/ "files": [ ".gitattributes", ".gitignore", - ".openapi-generator-ignore", - ".openapi-generator-ignore-handlebars", - ".pdk/dynamic-files/openapitools.json", ".projen/deps.json", ".projen/files.json", ".projen/tasks.json", @@ -31306,14 +31275,6 @@ cython_debug/ "description": "Only compile", "name": "compile", }, - "create-openapitools.json": { - "name": "create-openapitools.json", - "steps": [ - { - "exec": "cp -f .pdk/dynamic-files/openapitools.json openapitools.json", - }, - ], - }, "default": { "description": "Synthesize project files", "name": "default", @@ -31328,13 +31289,7 @@ cython_debug/ "name": "generate", "steps": [ { - "spawn": "create-openapitools.json", - }, - { - "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.clean-openapi-generated-code --code-path .", - }, - { - "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.generate --generator python-nextgen --spec-path ../../model/.api.json --output-path . --generator-dir python-lambda-handlers --src-dir smithy_handlers_python_handlers --tst-dir test --additional-properties "packageName=smithy_handlers_python_handlers,projectName=smithy-handlers-python-handlers" --openapi-normalizer "KEEP_ONLY_FIRST_TAG_IN_OPERATION=true" --extra-vendor-extensions '{"x-runtime-module-name":"smithy_handlers_python_runtime"}' --generate-alias-as-model", + "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api generate --specPath ../../model/.api.json --outputPath . --templateDirs "python-lambda-handlers" --metadata '{"srcDir":"smithy_handlers_python_handlers","tstDir":"test","runtimeModuleName":"smithy_handlers_python_runtime","moduleName":"smithy_handlers_python_handlers"}'", }, ], }, @@ -31447,13 +31402,6 @@ url = "https://test.pypi.org/legacy/" "cwd": "handlers/python", }, }, - "create-openapitools.json": { - "executor": "nx:run-commands", - "options": { - "command": "npx projen create-openapitools.json", - "cwd": "handlers/python", - }, - }, "default": { "executor": "nx:run-commands", "options": { diff --git a/packages/type-safe-api/test/project/codegen/handlers/__snapshots__/generated-python-async-handlers-project.test.ts.snap b/packages/type-safe-api/test/project/codegen/handlers/__snapshots__/generated-python-async-handlers-project.test.ts.snap index 3617d8dfb..6c6bd544e 100644 --- a/packages/type-safe-api/test/project/codegen/handlers/__snapshots__/generated-python-async-handlers-project.test.ts.snap +++ b/packages/type-safe-api/test/project/codegen/handlers/__snapshots__/generated-python-async-handlers-project.test.ts.snap @@ -7,9 +7,6 @@ exports[`Generated Python Async Handlers Code Unit Tests Synth 1`] = ` /.gitattributes linguist-generated /.github/workflows/pull-request-lint.yml linguist-generated /.gitignore linguist-generated -/.openapi-generator-ignore linguist-generated -/.openapi-generator-ignore-handlebars linguist-generated -/.pdk/dynamic-files/openapitools.json linguist-generated /.projen/** linguist-generated /.projen/deps.json linguist-generated /.projen/files.json linguist-generated @@ -128,35 +125,10 @@ dmypy.json .pyre/ .pytype/ cython_debug/ -!/.openapi-generator-ignore -!/.openapi-generator-ignore-handlebars -!/.pdk/dynamic-files/openapitools.json -/openapitools.json .openapi-generator +.tsapi-manifest !/.projenrc.py ", - ".openapi-generator-ignore": "# ~~ Generated by projen. To modify, edit .projenrc.py and run "npx projen". -.gitignore -/* -**/* -* -", - ".openapi-generator-ignore-handlebars": "# ~~ Generated by projen. To modify, edit .projenrc.py and run "npx projen". -/* -**/* -* -!test_handlers/__all_handlers.py -!test/__all_tests.py -", - ".pdk/dynamic-files/openapitools.json": { - "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", - "//": "~~ Generated by projen. To modify, edit .projenrc.py and run "npx projen".", - "generator-cli": { - "storageDir": "~/.open-api-generator-cli", - "version": "6.6.0", - }, - "spaces": 2, - }, ".projen/deps.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.py and run "npx projen".", "dependencies": [ @@ -188,9 +160,6 @@ cython_debug/ ".gitattributes", ".github/workflows/pull-request-lint.yml", ".gitignore", - ".openapi-generator-ignore", - ".openapi-generator-ignore-handlebars", - ".pdk/dynamic-files/openapitools.json", ".projen/deps.json", ".projen/files.json", ".projen/tasks.json", @@ -266,14 +235,6 @@ cython_debug/ "description": "Only compile", "name": "compile", }, - "create-openapitools.json": { - "name": "create-openapitools.json", - "steps": [ - { - "exec": "cp -f .pdk/dynamic-files/openapitools.json openapitools.json", - }, - ], - }, "default": { "description": "Synthesize project files", "name": "default", @@ -299,13 +260,7 @@ cython_debug/ "name": "generate", "steps": [ { - "spawn": "create-openapitools.json", - }, - { - "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.clean-openapi-generated-code --code-path .", - }, - { - "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.generate --generator python-nextgen --spec-path my-spec.json --output-path . --generator-dir python-async-lambda-handlers --src-dir test_handlers --tst-dir test --additional-properties "packageName=test_handlers,projectName=test-python-handlers" --openapi-normalizer "KEEP_ONLY_FIRST_TAG_IN_OPERATION=true" --extra-vendor-extensions '{"x-runtime-module-name":"test_client"}' --generate-alias-as-model", + "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api generate --specPath my-spec.json --outputPath . --templateDirs "python-async-lambda-handlers" --metadata '{"srcDir":"test_handlers","tstDir":"test","runtimeModuleName":"test_client","moduleName":"test_handlers"}'", }, ], }, diff --git a/packages/type-safe-api/test/project/codegen/handlers/__snapshots__/generated-python-handlers-project.test.ts.snap b/packages/type-safe-api/test/project/codegen/handlers/__snapshots__/generated-python-handlers-project.test.ts.snap index 892178f8c..3d27c8de8 100644 --- a/packages/type-safe-api/test/project/codegen/handlers/__snapshots__/generated-python-handlers-project.test.ts.snap +++ b/packages/type-safe-api/test/project/codegen/handlers/__snapshots__/generated-python-handlers-project.test.ts.snap @@ -7,9 +7,6 @@ exports[`Generated Python Handlers Code Unit Tests Synth 1`] = ` /.gitattributes linguist-generated /.github/workflows/pull-request-lint.yml linguist-generated /.gitignore linguist-generated -/.openapi-generator-ignore linguist-generated -/.openapi-generator-ignore-handlebars linguist-generated -/.pdk/dynamic-files/openapitools.json linguist-generated /.projen/** linguist-generated /.projen/deps.json linguist-generated /.projen/files.json linguist-generated @@ -128,35 +125,10 @@ dmypy.json .pyre/ .pytype/ cython_debug/ -!/.openapi-generator-ignore -!/.openapi-generator-ignore-handlebars -!/.pdk/dynamic-files/openapitools.json -/openapitools.json .openapi-generator +.tsapi-manifest !/.projenrc.py ", - ".openapi-generator-ignore": "# ~~ Generated by projen. To modify, edit .projenrc.py and run "npx projen". -.gitignore -/* -**/* -* -", - ".openapi-generator-ignore-handlebars": "# ~~ Generated by projen. To modify, edit .projenrc.py and run "npx projen". -/* -**/* -* -!test_handlers/__all_handlers.py -!test/__all_tests.py -", - ".pdk/dynamic-files/openapitools.json": { - "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", - "//": "~~ Generated by projen. To modify, edit .projenrc.py and run "npx projen".", - "generator-cli": { - "storageDir": "~/.open-api-generator-cli", - "version": "6.6.0", - }, - "spaces": 2, - }, ".projen/deps.json": { "//": "~~ Generated by projen. To modify, edit .projenrc.py and run "npx projen".", "dependencies": [ @@ -188,9 +160,6 @@ cython_debug/ ".gitattributes", ".github/workflows/pull-request-lint.yml", ".gitignore", - ".openapi-generator-ignore", - ".openapi-generator-ignore-handlebars", - ".pdk/dynamic-files/openapitools.json", ".projen/deps.json", ".projen/files.json", ".projen/tasks.json", @@ -266,14 +235,6 @@ cython_debug/ "description": "Only compile", "name": "compile", }, - "create-openapitools.json": { - "name": "create-openapitools.json", - "steps": [ - { - "exec": "cp -f .pdk/dynamic-files/openapitools.json openapitools.json", - }, - ], - }, "default": { "description": "Synthesize project files", "name": "default", @@ -299,13 +260,7 @@ cython_debug/ "name": "generate", "steps": [ { - "spawn": "create-openapitools.json", - }, - { - "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.clean-openapi-generated-code --code-path .", - }, - { - "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api.generate --generator python-nextgen --spec-path my-spec.json --output-path . --generator-dir python-lambda-handlers --src-dir test_handlers --tst-dir test --additional-properties "packageName=test_handlers,projectName=test-python-handlers" --openapi-normalizer "KEEP_ONLY_FIRST_TAG_IN_OPERATION=true" --extra-vendor-extensions '{"x-runtime-module-name":"test_client"}' --generate-alias-as-model", + "exec": "npx --yes -p @aws/pdk@$AWS_PDK_VERSION type-safe-api generate --specPath my-spec.json --outputPath . --templateDirs "python-lambda-handlers" --metadata '{"srcDir":"test_handlers","tstDir":"test","runtimeModuleName":"test_client","moduleName":"test_handlers"}'", }, ], }, diff --git a/packages/type-safe-api/test/scripts/generators/__snapshots__/python-lambda-handlers.test.ts.snap b/packages/type-safe-api/test/scripts/generators/__snapshots__/python-lambda-handlers.test.ts.snap index 2b2f98bb8..47b65a67e 100644 --- a/packages/type-safe-api/test/scripts/generators/__snapshots__/python-lambda-handlers.test.ts.snap +++ b/packages/type-safe-api/test/scripts/generators/__snapshots__/python-lambda-handlers.test.ts.snap @@ -92,7 +92,6 @@ def test_python_one_should_return_not_implemented_error(request_arguments): # # Add request parameters here... # ), request_parameters=None, - body=None, )) @@ -134,7 +133,6 @@ def test_python_two_should_return_not_implemented_error(request_arguments): # # Add request parameters here... # ), request_parameters=None, - body=None, )) diff --git a/packages/type-safe-api/test/scripts/generators/async/__snapshots__/python-lambda-handlers.test.ts.snap b/packages/type-safe-api/test/scripts/generators/async/__snapshots__/python-lambda-handlers.test.ts.snap index c4a5dea35..f3baa35dd 100644 --- a/packages/type-safe-api/test/scripts/generators/async/__snapshots__/python-lambda-handlers.test.ts.snap +++ b/packages/type-safe-api/test/scripts/generators/async/__snapshots__/python-lambda-handlers.test.ts.snap @@ -92,6 +92,7 @@ def test_python_one_should_return_not_implemented_error(request_arguments): # # Add request parameters here... # ), request_parameters=None, + # body=PythonOneRequestBody( # # Add body fields here... # ) @@ -136,6 +137,7 @@ def test_python_two_should_return_not_implemented_error(request_arguments): # # Add request parameters here... # ), request_parameters=None, + # body=PythonTwoRequestBody( # # Add body fields here... # ) diff --git a/packages/type-safe-api/test/scripts/generators/async/python-lambda-handlers.test.ts b/packages/type-safe-api/test/scripts/generators/async/python-lambda-handlers.test.ts index 016cee8b8..e7a2c6016 100644 --- a/packages/type-safe-api/test/scripts/generators/async/python-lambda-handlers.test.ts +++ b/packages/type-safe-api/test/scripts/generators/async/python-lambda-handlers.test.ts @@ -40,13 +40,10 @@ describe("Python Async Handlers Code Generation Script Unit Tests", () => { generatedPythonTypes: client, }); project.synth(); - exec(project.tasks.tryFind("create-openapitools.json")!.steps[0].exec!, { - cwd: handlersOutdir, - }); exec( `${path.resolve( __dirname, - "../../../../scripts/type-safe-api/generators/generate" + "../../../../scripts/type-safe-api/run.js generate" )} ${project.buildGenerateCommandArgs()}`, { cwd: handlersOutdir, diff --git a/packages/type-safe-api/test/scripts/generators/python-lambda-handlers.test.ts b/packages/type-safe-api/test/scripts/generators/python-lambda-handlers.test.ts index e89dccced..a9b5f58c4 100644 --- a/packages/type-safe-api/test/scripts/generators/python-lambda-handlers.test.ts +++ b/packages/type-safe-api/test/scripts/generators/python-lambda-handlers.test.ts @@ -37,13 +37,10 @@ describe("Python Handlers Code Generation Script Unit Tests", () => { generatedPythonTypes: client, }); project.synth(); - exec(project.tasks.tryFind("create-openapitools.json")!.steps[0].exec!, { - cwd: handlersOutdir, - }); exec( `${path.resolve( __dirname, - "../../../scripts/type-safe-api/generators/generate" + "../../../scripts/type-safe-api/run.js generate" )} ${project.buildGenerateCommandArgs()}`, { cwd: handlersOutdir,