Skip to content

[apigateway] incorrect mapping of id in model schema definition #14585

@amwill04

Description

@amwill04

When defining an api gateway model schema such as:

const createBlockModel = this.addModel('Model', {
    contentType: 'application/json',
    schema: {
        schema: JsonSchemaVersion.DRAFT4,
        id: 'http://example.com/my_schema.json',
        properties: {
            userId: {
                type: JsonSchemaType.STRING,
            },
        },
        required: ['userId'],
    },
});

This will generate the following template

{

"PrivateApiModelB06227A2": {
      "Type": "AWS::ApiGateway::Model",
      "Properties": {
        "RestApiId": {
          "Ref": "PrivateApi1FA926D9"
        },
        "ContentType": "application/json",
        "Schema": {
          "$schema": "http://json-schema.org/draft-04/schema#",
          "$id": "http://example.com/my_schema.json",
          "properties": {
            "userId": {
              "type": "string"
            }
          },
          "required": [
            "userId"
          ]
        }
      }
    }

}

This will now fail in cloudformation with the following error:

Invalid model specified: Validation Result: warnings : [], errors : [Invalid model schema specified. Unsupported keyword(s): ["$id"]] 

This is due to draft-04 using id rather than $id which was introduced in draft-06

Cause of the problem stems from here which uses the following to map id => $id.

private static readonly SchemaPropsWithPrefix: { [key: string]: string } = {
    schema: '$schema',
    ref: '$ref',
    id: '$id',
  };

This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-apigatewayRelated to Amazon API GatewaybugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions