有关模板的相关部分,请参见下文。我不知道如何为Api设置模型。如果我将模型部分留给MyApi,则' sam deploy '表示:“相关的API未定义任何模型”。那么,如何为Api和功能请求模型添加模型?
次要问题:
可以在外部json / yaml文件中定义模型吗?
如何定义响应模型?
我可以在单独的模板文件中引入模型吗?
谢谢。
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: test
Models:
???
PostNewItem:
Type: AWS::ApiGateway::Model
Properties:
RestApiId: !Ref MyApi
Name: PostNewItem
ContentType: application/json
Schema:
$schema: 'http://json-schema.org/draft-04/schema#'
title: NewItemModel
type: object
properties:
name:
type: string
description:
type: string
....
MyFunction:
Type: AWS::Serverless::Function
Properties:
...
Events:
AddItem:
Type: Api
Properties:
Path: /item
Method: post
RestApiId:
!Ref MyApi
RequestModel:
Model: !Ref PostNewItem
Required: true
答案 0 :(得分:1)
要回答我自己的问题,使用无服务器,不需要AWS :: ApiGateway :: Models,而是使用Api定义它们。
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: test
Models:
PostPointModel:
type: object
required:
- name
properties:
name:
type: string
description:
type: string