Class ApiDefinition
Represents an OpenAPI definition asset.
Namespace: Amazon.CDK.AWS.APIGateway
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public abstract class ApiDefinition : DeputyBase
Syntax (vb)
Public MustInherit Class ApiDefinition
Inherits DeputyBase
Remarks
ExampleMetadata: infused
Examples
var myApiDefinition = ApiDefinition.FromAsset("path-to-file.json");
var specRestApi = new SpecRestApi(this, "my-specrest-api", new SpecRestApiProps {
Deploy = false,
ApiDefinition = myApiDefinition
});
// Use `stageName` to deploy to an existing stage
var deployment = new Deployment(this, "my-deployment", new DeploymentProps {
Api = specRestApi,
StageName = "dev",
RetainDeployments = true
});
// Trigger a new deployment on OpenAPI definition updates
deployment.AddToLogicalId(myApiDefinition);
Synopsis
Constructors
ApiDefinition() | |
ApiDefinition(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
ApiDefinition(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Methods
Bind(Construct) | Called when the specification is initialized to allow this object to bind to the stack, add resources and have fun. |
BindAfterCreate(Construct, IRestApi) | Called after the CFN RestApi resource has been created to allow the Api Definition to bind to it. |
FromAsset(String, IAssetOptions) | Loads the API specification from a local disk asset. |
FromBucket(IBucket, String, String) | Creates an API definition from a specification file in an S3 bucket. |
FromInline(Object) | Create an API definition from an inline object. |
Constructors
ApiDefinition()
protected ApiDefinition()
ApiDefinition(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected ApiDefinition(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
ApiDefinition(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected ApiDefinition(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
Bind(Construct)
Called when the specification is initialized to allow this object to bind to the stack, add resources and have fun.
public abstract IApiDefinitionConfig Bind(Construct scope)
Parameters
- scope Constructs.Construct
The binding scope.
Returns
BindAfterCreate(Construct, IRestApi)
Called after the CFN RestApi resource has been created to allow the Api Definition to bind to it.
public virtual void BindAfterCreate(Construct scope, IRestApi restApi)
Parameters
- scope Constructs.Construct
- restApi IRestApi
Remarks
Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.
FromAsset(String, IAssetOptions)
Loads the API specification from a local disk asset.
public static AssetApiDefinition FromAsset(string file, IAssetOptions options = null)
Parameters
- file System.String
- options IAssetOptions
Returns
FromBucket(IBucket, String, String)
Creates an API definition from a specification file in an S3 bucket.
public static S3ApiDefinition FromBucket(IBucket bucket, string key, string objectVersion = null)
Parameters
- bucket IBucket
- key System.String
- objectVersion System.String
Returns
FromInline(Object)
Create an API definition from an inline object.
public static InlineApiDefinition FromInline(object definition)
Parameters
- definition System.Object
Returns
Remarks
The inline object must follow the schema of OpenAPI 2.0 or OpenAPI 3.0
Examples
ApiDefinition.FromInline(new Dictionary<string, object> {
{ "openapi", "3.0.2" },
{ "paths", new Struct {
/pets = new Struct {
Get = new Struct {
Responses = new Struct {
200 = new Struct {
Content = new Struct {
Application/json = new Struct {
Schema = new Struct {
$ref = "#/components/schemas/Empty"
}
}
}
}
},
X-amazon-apigateway-integration = new Struct {
Responses = new Struct {
Default = new Struct {
StatusCode = "200"
}
},
RequestTemplates = new Struct {
Application/json = "{\"statusCode\": 200}"
},
PassthroughBehavior = "when_no_match",
Type = "mock"
}
}
}
} },
{ "components", new Struct {
Schemas = new Struct {
Empty = new Struct {
Title = "Empty Schema",
Type = "object"
}
}
} }
});