Show / Hide Table of Contents

Class Model

Inheritance
object
Resource
Model
Implements
IResource
IConstruct
IDependable
IEnvironmentAware
IModel
Inherited Members
Resource.IsOwnedResource(IConstruct)
Resource.IsResource(IConstruct)
Resource.ApplyRemovalPolicy(RemovalPolicy)
Resource.GeneratePhysicalName()
Resource.GetResourceArnAttribute(string, IArnComponents)
Resource.GetResourceNameAttribute(string)
Resource.Env
Resource.PhysicalName
Resource.Stack
Namespace: Amazon.CDK.AWS.APIGateway
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Model : Resource, IResource, IConstruct, IDependable, IEnvironmentAware, IModel
Syntax (vb)
Public Class Model Inherits Resource Implements IResource, IConstruct, IDependable, IEnvironmentAware, IModel
Remarks

ExampleMetadata: infused

Examples
RestApi api;


            // We define the JSON Schema for the transformed valid response
            var responseModel = api.AddModel("ResponseModel", new ModelOptions {
                ContentType = "application/json",
                ModelName = "ResponseModel",
                Schema = new JsonSchema {
                    Schema = JsonSchemaVersion.DRAFT4,
                    Title = "pollResponse",
                    Type = JsonSchemaType.OBJECT,
                    Properties = new Dictionary<string, JsonSchema> {
                        { "state", new JsonSchema { Type = JsonSchemaType.STRING } },
                        { "greeting", new JsonSchema { Type = JsonSchemaType.STRING } }
                    }
                }
            });

            // We define the JSON Schema for the transformed error response
            var errorResponseModel = api.AddModel("ErrorResponseModel", new ModelOptions {
                ContentType = "application/json",
                ModelName = "ErrorResponseModel",
                Schema = new JsonSchema {
                    Schema = JsonSchemaVersion.DRAFT4,
                    Title = "errorResponse",
                    Type = JsonSchemaType.OBJECT,
                    Properties = new Dictionary<string, JsonSchema> {
                        { "state", new JsonSchema { Type = JsonSchemaType.STRING } },
                        { "message", new JsonSchema { Type = JsonSchemaType.STRING } }
                    }
                }
            });

Synopsis

Constructors

Model(Construct, string, IModelProps)

Properties

EMPTY_MODEL

Represents a reference to a REST API's Empty model, which is available as part of the model collection by default.

ERROR_MODEL

Represents a reference to a REST API's Error model, which is available as part of the model collection by default.

ModelId

Returns the model name, such as 'myModel'.

PROPERTY_INJECTION_ID

Uniquely identifies this class.

Methods

FromModelName(Construct, string, string)

Constructors

Model(Construct, string, IModelProps)

public Model(Construct scope, string id, IModelProps props)
Parameters
scope Construct
id string
props IModelProps
Remarks

ExampleMetadata: infused

Examples
RestApi api;


            // We define the JSON Schema for the transformed valid response
            var responseModel = api.AddModel("ResponseModel", new ModelOptions {
                ContentType = "application/json",
                ModelName = "ResponseModel",
                Schema = new JsonSchema {
                    Schema = JsonSchemaVersion.DRAFT4,
                    Title = "pollResponse",
                    Type = JsonSchemaType.OBJECT,
                    Properties = new Dictionary<string, JsonSchema> {
                        { "state", new JsonSchema { Type = JsonSchemaType.STRING } },
                        { "greeting", new JsonSchema { Type = JsonSchemaType.STRING } }
                    }
                }
            });

            // We define the JSON Schema for the transformed error response
            var errorResponseModel = api.AddModel("ErrorResponseModel", new ModelOptions {
                ContentType = "application/json",
                ModelName = "ErrorResponseModel",
                Schema = new JsonSchema {
                    Schema = JsonSchemaVersion.DRAFT4,
                    Title = "errorResponse",
                    Type = JsonSchemaType.OBJECT,
                    Properties = new Dictionary<string, JsonSchema> {
                        { "state", new JsonSchema { Type = JsonSchemaType.STRING } },
                        { "message", new JsonSchema { Type = JsonSchemaType.STRING } }
                    }
                }
            });

Properties

EMPTY_MODEL

Represents a reference to a REST API's Empty model, which is available as part of the model collection by default.

public static IModel EMPTY_MODEL { get; }
Property Value

IModel

Remarks

This can be used for mapping JSON responses from an integration to what is returned to a client, where strong typing is not required. In the absence of any defined model, the Empty model will be used to return the response payload unmapped.

Definition { "$schema" : "http://json-schema.org/draft-04/schema#", "title" : "Empty Schema", "type" : "object" }

See: https://docs.amazonaws.cn/en_us/apigateway/latest/developerguide/models-mappings.html#models-mappings-models

ERROR_MODEL

Represents a reference to a REST API's Error model, which is available as part of the model collection by default.

public static IModel ERROR_MODEL { get; }
Property Value

IModel

Remarks

This can be used for mapping error JSON responses from an integration to a client, where a simple generic message field is sufficient to map and return an error payload.

Definition { "$schema" : "http://json-schema.org/draft-04/schema#", "title" : "Error Schema", "type" : "object", "properties" : { "message" : { "type" : "string" } } }

ModelId

Returns the model name, such as 'myModel'.

public virtual string ModelId { get; }
Property Value

string

Remarks

Attribute: true

PROPERTY_INJECTION_ID

Uniquely identifies this class.

public static string PROPERTY_INJECTION_ID { get; }
Property Value

string

Remarks

ExampleMetadata: infused

Methods

FromModelName(Construct, string, string)

public static IModel FromModelName(Construct scope, string id, string modelName)
Parameters
scope Construct
id string
modelName string
Returns

IModel

Remarks

ExampleMetadata: infused

Examples
RestApi api;


            // We define the JSON Schema for the transformed valid response
            var responseModel = api.AddModel("ResponseModel", new ModelOptions {
                ContentType = "application/json",
                ModelName = "ResponseModel",
                Schema = new JsonSchema {
                    Schema = JsonSchemaVersion.DRAFT4,
                    Title = "pollResponse",
                    Type = JsonSchemaType.OBJECT,
                    Properties = new Dictionary<string, JsonSchema> {
                        { "state", new JsonSchema { Type = JsonSchemaType.STRING } },
                        { "greeting", new JsonSchema { Type = JsonSchemaType.STRING } }
                    }
                }
            });

            // We define the JSON Schema for the transformed error response
            var errorResponseModel = api.AddModel("ErrorResponseModel", new ModelOptions {
                ContentType = "application/json",
                ModelName = "ErrorResponseModel",
                Schema = new JsonSchema {
                    Schema = JsonSchemaVersion.DRAFT4,
                    Title = "errorResponse",
                    Type = JsonSchemaType.OBJECT,
                    Properties = new Dictionary<string, JsonSchema> {
                        { "state", new JsonSchema { Type = JsonSchemaType.STRING } },
                        { "message", new JsonSchema { Type = JsonSchemaType.STRING } }
                    }
                }
            });

Implements

IResource
Constructs.IConstruct
Constructs.IDependable
IEnvironmentAware
IModel
Back to top Generated by DocFX