Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(ApiGateway): Support loading API gateway Model schemas from an object #17471

Closed
2 tasks
mongeon opened this issue Nov 11, 2021 · 2 comments
Closed
2 tasks

(ApiGateway): Support loading API gateway Model schemas from an object #17471

mongeon opened this issue Nov 11, 2021 · 2 comments
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@mongeon
Copy link

mongeon commented Nov 11, 2021

Description

I would like to load JsonSchema from a class definition and populate a JsonSchema object.

Use Case

Being able to add models and validation in my ApiGateway definition based on a class. This will enable model validation at the ApiGateway level and won't call my lambda function.

Proposed Solution

This is a C# example:

var schema = JsonSchema.FromType<MyClass>();

var requestValidator = new RequestValidator(this, "APayloadValidator", new RequestValidatorProps
{
    RestApi = api,
    RequestValidatorName = "my-payload-validator",
    ValidateRequestBody = true
});

var model = new Model(this, "AModel", new ModelProps
{
    ContentType = "application/json",
    ModelName = "A-Model-name",
    RestApi = api,
    Schema = schema
});

resource.AddMethod(HttpMethod.Post, Integration, new MethodOptions
{
    RequestValidator = requestValidator,
    RequestModels = new Dictionary<string, IModel>
    {
        {"application/json", model }
    }
});

Other information

Similar to #17470 and #10818

See the JsonSchema implementation from code from others library: http://json-schema.org/implementations.html#from-code

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change
@mongeon mongeon added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 11, 2021
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Nov 11, 2021
@nija-at nija-at assigned otaviomacedo and unassigned nija-at Dec 2, 2021
@otaviomacedo otaviomacedo added effort/medium Medium work item – several days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2021
@otaviomacedo otaviomacedo removed their assignment Dec 3, 2021
@github-actions
Copy link

github-actions bot commented Dec 3, 2022

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 3, 2022
@github-actions github-actions bot closed this as completed Dec 8, 2022
@tomvonheill
Copy link

Dang, this is what I am looking for too. Any other way to create the models from the schemas? I'm still getting _ErrorResponse(error='Error: Resolution error: Supplied properties not correct for "CfnModelProps"\n schema: "{\\"title\\": \\"DateRange\\", \\"type\\": \\"object\\", \\"properties\\": {\\"startDate\\": {\\"title\\": \\"Startdate\\", \\"type\\": \\"string\\", \\"format\\": \\"date\\"}, \\"endDate\\": {\\"title\\": \\"Enddate\\", \\"type\\": \\"string\\", \\"format\\": \\"date\\"}}, \\"required\\": [\\"startDate\\", \\"endDate\\"]}" should be an \'object\'.', stack='@jsii/kernel.RuntimeError: Error: Resolution error: Supplied properties not correct for "CfnModelProps"\n schema: "{\\"title\\": \\"DateRange\\", \\"type\\": \\"object\\", \\"properties\\": {\\"startDate\\": {\\"title\\": \\"Startdate\\", \\"type\\": \\"string\\", \\"format\\": \\"date\\"}, \\"endDate\\": {\\"title\\": \\"Enddate\\", \\"type\\": \\"string\\", \\"format\\": \\"date\\"}}, \\"required\\": [\\"startDate\\", \\"endDate\\"]}" should be an \'object\'.\n at Kernel._ensureSync (/private/var/folders/9y/p5rv7rqx75j18s_3ttrlnxrw0000gq/T/tmpu60weq22/lib/program.js:10369:27)\n at Kernel.invoke (/private/var/folders/9y/p5rv7rqx75j18s_3ttrlnxrw0000gq/T/tmpu60weq22/lib/program.js:9769:34)\n at KernelHost.processRequest (/private/var/folders/9y/p5rv7rqx75j18s_3ttrlnxrw0000gq/T/tmpu60weq22/lib/program.js:11544:36)\n at KernelHost.run (/private/var/folders/9y/p5rv7rqx75j18s_3ttrlnxrw0000gq/T/tmpu60weq22/lib/program.js:11504:22)\n at Immediate._onImmediate (/private/var/folders/9y/p5rv7rqx75j18s_3ttrlnxrw0000gq/T/tmpu60weq22/lib/program.js:11505:46)\n at process.processImmediate (node:internal/timers:471:21)', name='@jsii/kernel.RuntimeError') which doesn't make too much sense to me. We need it to be a json schema and not converting automatically from json schema strings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

4 participants