Class Model
- Namespace
- Amazon.CDK.AWS.APIGateway
- Assembly
- Amazon.CDK.AWS.APIGateway.dll
public class Model : Resource, IModel
- Inheritance
-
Model
- Implements
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 } }
}
}
});
Remarks
ExampleMetadata: infused
Constructors
Model(Construct, string, IModelProps)
public Model(Construct scope, string id, IModelProps props)
Parameters
scope
Constructid
stringprops
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.
public static IModel EMPTY_MODEL { get; }
Property Value
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" }
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
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
Remarks
Attribute: true
Methods
FromModelName(Construct, string, string)
public static IModel FromModelName(Construct scope, string id, string modelName)