Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 不允许其他属性:可为null的招摇过市_Node.js_Express_Swagger_Swagger 2.0_Openapi - Fatal编程技术网

Node.js 不允许其他属性:可为null的招摇过市

Node.js 不允许其他属性:可为null的招摇过市,node.js,express,swagger,swagger-2.0,openapi,Node.js,Express,Swagger,Swagger 2.0,Openapi,我正在将swagger 2.0与node.js express 4.12.3和mysql db一起使用 我创建了以下模式- Country: type: "object" properties: id: type: "integer" readOnly: true description: "Country Id" country: type: "string" descr

我正在将swagger 2.0与node.js express 4.12.3和mysql db一起使用

我创建了以下模式-

  Country:
    type: "object"
    properties:
      id:
        type: "integer"
        readOnly: true
        description: "Country Id"
      country:
        type: "string"
        description: "Country name"
      created_at:
        type: "string"
        readOnly: true
        format: "date-time"
        description: "Country record creation date"
      deleted_at:
        type: "string"
        format: "date-time"
        description: "Country record delete date"
    required:
      - country
此处删除的_at字段将为空,并且在删除记录之前不会出现在数据库中。 我的基于express的nodejs服务器返回的日期如下-

[{“id”:4,“国家”:“g”,“创建地点”:“2018-01-29T04:51:46.000Z”,“删除地点”:null},{“id”:5,“国家”:“gaaaf”,“创建地点”:“2018-01-29T04:54:59.000Z”,“删除地点”:null},{“id”:6,“国家”:“abcd”,“创建地点”:“2018-01-29T04:57:02.000Z”,“删除地点”:null}]

当我试图通过swagger ui进行rest调用时,我得到以下错误-

"message":"Response validation failed: failed schema

validation","code":"SCHEMA_VALIDATION_FAILED","failedValidation":true,
{"errors":[{"code":"INVALID_TYPE","message":"Expected type string but found type null","path":["5","deleted_at"],"description":"Country record delete date"},
看完这些文件后,我做了如下工作-

  deleted_at:
    type: "string"
    format: "date-time"
    nullable: true
    description: "Country record delete date"
然后我开始在swagger ui中得到这个验证错误

消息:“不允许附加属性:可为空”

我尝试从字符串中将type设置为object,但即使这样也不起作用

 deleted_at:
        type: "object"
        format: "date-time"
        nullable: true
        description: "Country record delete date"
适用于任何类型的OpenAPI/Swagger 2.0
nullable:true
是在OpenAPI 3.0中引入的,OpenAPI/Swagger 2.0不支持它


解决方法是如果
null
deleted\u不发送到

我认为Swigger工具并不完全支持OpenApi 3.0。对吧?有些工具支持它,有些不支持。如果你是说,那么它还不支持3.0。存在一个现有的功能请求。目前我正在考虑如果它为空,则不发送已删除的\u。