azure - OpenAPI 类型模式写入 Swagger 类型字段
问题描述
我的问题是关于 Azure API Management, resource type 中的 API 架构Microsoft.ApiManagement/service/apis/schemas
。
通过 Azure 门户创建的架构使用内容类型创建application/vnd.oai.openapi.components+json
并写入document/components/schemas
,这是 OpenAPI 定义中架构定义的正确路径。
样本:
{
"value": [
{
"id": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.ApiManagement/service/xxx/apis/xxx/schemas/1629566051926",
"type": "Microsoft.ApiManagement/service/apis/schemas",
"name": "1629566051926",
"properties": {
"contentType": "application/vnd.oai.openapi.components+json",
"document": {
"components": {
"schemas": {
"patch-components-id-request-1": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"documentationURL": {
"type": "string"
},
"iacURL": {
"type": "string"
},
"duration": {
"type": "integer"
},
"statusID": {
"type": "integer"
},
"owner": {
"type": "string"
}
}
}
}
}
}
}
}
],
"count": 1
}
通过REST API或Go SDK创建的模式是使用 设置的properties.document.definitions
,这导致它被写入document/definitions
,无论 contentType 是什么。
样本:
{
"value": [
{
"id": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.ApiManagement/service/xxx/apis/marble-dev-fctn/schemas/marbleschemas",
"type": "Microsoft.ApiManagement/service/apis/schemas",
"name": "marbleschemas",
"properties": {
"contentType": "application/vnd.oai.openapi.components+json",
"document": {
"definitions": {
"patch-components-id-request-1": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"documentationURL": {
"type": "string"
},
"iacURL": {
"type": "string"
},
"duration": {
"type": "integer"
},
"statusID": {
"type": "integer"
},
"owner": {
"type": "string"
}
}
}
}
}
}
}
],
"count": 1
}
将 contentType 设置application/vnd.ms-azure-apim.swagger.definitions+json
为此很好,但是将 contentType 设置application/vnd.oai.openapi.components+json
为时会出现两个问题: 导出 OpenAPI Schema 时将不包含定义(至少从 Azure 门户导出时,我没有尝试任何其他方式),因为definitions
不是有效的 OpenAPI 字段,并且不会显示在 Developer Portal 中。
据我了解,需要将定义写入document/components/schemas
forapplication/vnd.oai.openapi.components+json
和document/definitions
for application/vnd.ms-azure-apim.swagger.definitions+json
。
我可以通过在 ARM 模板或 REST API 调用中手动设置来将定义导入正确的路径,但我正在努力让 terraform 资源正常工作,这依赖于 Go SDK。可能也有解决方法,但我真的很想知道我的理解是否错误,或者这里是否存在问题。
解决方案
推荐阅读
- json - 我正在尝试使用 swift 4 解析 json,请告诉我其中有什么问题?
- javascript - React Native:图像未使用动态/本地 URI 显示
- tsql - 如何将多行子查询的行与要在 T-sql 中的 In 中使用的条件语句组合起来
- yii - Yii 渲染法语显示特殊字符的视图文件
- javascript - JQuery 在 ASP.NET Core 2.1 中返回“未定义”值
- python - 我必须删除文本文件中的特定行
- memory-leaks - 以太坊 geth:内存不足
- sql - 默认隐式参数 SQL
- oauth - MS OAuth 2.0 不适用于多因素身份验证
- python - 合并具有相似工作的excel文件和文本文件