为什么不通过swagger验证来自json模式的此正则表达式模式?

时间:2019-06-19 01:47:42

标签: java json swagger schema jsonschema

我正在使用json模式,使用Open API 3.0验证Swagger定义的输入。在Swagger编辑器中,如果我尝试在数字字段中引入字符串,则验证可以完美地进行。但是,我注意到name属性的模式不起作用,因为当我插入小写字符时,swagger认为它是有效数据,这是不正确的。

我注意到如果我使用minLength来验证字符串的长度,我也会遇到同样的问题。另外,json模式工作正常,因为如果我使用小写字符,它将正确验证json对象。

这是我昂扬的定义:

openapi: 3.0.0
info:
  version: '1.0.0'
  title: 'EXAMPLE1'
  description: 'Example API to test jsonschema'
  termsOfService: https://smasrtbear.com/terms-of-use
  contact:
    name: something
    url: smartbear.com
    email: aaa@asdad.net
  license:
    name: SmartBear License
    url: http://license.foo.com
servers:
  - url: https://dev.foo.com
    description: Dev Server
  - url: https://prod.foo.com
    description: Prod Server
paths: 
  /example:
    get:
      description: To get some information
      parameters:
        - name: id
          in: query
          description: Some Id example
          schema:
            $ref: 'http://localhost:5555/mytest#/properties/id'
        - name: name
          in: query
          description: some name for example
          schema:
            $ref: 'http://localhost:5555/mytest#/properties/name'
        - name: price
          in: query
          description: some price for example
          schema:
            $ref: 'http://localhost:5555/mytest#/properties/price'
      responses:
        200:
          description: Successful example
          content:
            application/json:
              schema:
                type: array
                items:
                  properties:
                    id:
                      type: integer
                      example: 4
                    name:
                      type: string
                      example: John Smith
                    price:
                      type: integer
                      example: 114

请注意,我正在使用#ref连接到远程json模式

这是架构。

{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://example.com/example.json",
  "type": "object",
  "title": "The Root Schema",
  "required": [
    "id",
    "name",
    "price"
  ],
  "properties": {
    "id": {
      "$id": "/properties/id",
      "type": "integer",
      "title": "The Id Schema",
      "default": 0,
      "examples": [
        1
      ]
    },
    "name": {
      "$id": "/properties/name",
      "type": "string",
      "title": "The Name Schema",
      "default": "",
      "examples": [
        "A GREEN DOOR"
      ],
      "pattern": "^([A-Z]*)$"
    },
    "price": {
      "$id": "/properties/price",
      "type": "number",
      "title": "The Price Schema",
      "default": 12,
      "examples": [
        12
      ]
    }
  }
}

这应该无效。

{     “ id”:4     “ name”:“ abcdefg”,     “价格”:114   }

OpenApi3.0是否会出现问题? 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我从SwaggerEditor切换到SwaggerHub。