python - (Swagger 2.0/ Connexion)无类型不是“字符串”类型
问题描述
我正在尝试通过 python connexion 创建一个简单的 post API。这是我的 api yaml 文件:
swagger: "2.0"
info:
title: "My first API"
version: "1.0"
basePath: /v1.0
paths:
/potential:
post:
operationId: api.data.create_potential_data
summary: Create the potential data
parameters:
- name: alertCategory
in: body
required: True
description: The potential API request AlertCategoryDto object with settings of alert category (categorySystemName, alert Kpis etc.)
schema:
$ref: "#/definitions/alert"
responses:
201:
description: Successfully created potential data
definitions:
alert:
properties:
systemName:
type: string
name:
type: string
moduleSystemName:
type: string
name
但是对于我们允许用户输入null
值的属性之一。如果他们真的这样做,我们将得到error: None type is not of type 'string'
那么在 swagger 2.0 中有没有让属性可以为空?网上找不到太多资料。谢谢!
解决方案
我认为你应该记下 type: string nullable: true
从这里我获得了信息 这个链接
它会是这样的:
definitions:
alert:
properties:
systemName:
type: string
name:
type: string
nullable: true
moduleSystemName:
type: string
推荐阅读
- java - 尝试使用 import java.util.Scanner 时出错
- javascript - 显示日期选择器使用适用于 Chrome 的 javascript
- vba - 多次打开工作簿提示
- c - CLion 中的 EOF 错误
- javascript - 指出 JavaScript 循环中的错误
- javascript - 带有单选按钮的 getElementById 不起作用
- c# - Azure 服务器,“ExceptionType”:“System.NullReferenceException”C#,SQL Server,在本地主机上工作,而不是在服务器上
- angular - Angular 5 Http 发布请求
- json - json_agg() 中的重复行在具有 2 个横向连接的查询中
- django - 在 openshift 源上安装 numpy