java OpenAPI 3验证错误:应匹配格式“regex”

ejk8hzay  于 3个月前  发布在  Java
关注(0)|答案(1)|浏览(65)

我从我写的Jersey RestApi代码中生成了一个openapi json规范,其中一个约束是“LEAGUE-MEMBER”请求头的regex否定前瞻模式。当我像这样将json转换为yaml时。

openapi: 3.0.1
info:
  title: Justice League Delegate Admin Sheet 
  description: 'Log Record for Temp admin access to the WatchTower'
  version: v1
servers:
  - url: https://watchtower.wayne:9443
    description: Generated server url
paths:
  /ent-watchtower-auth/v3/delegate:
    get:
      tags:
        - Search
      summary: Search for a UID
      operationId: searchForUID
      parameters:
        - name: MemberID
          in: header
          required: true
          schema:
            type: string
          example: JL000000
        - name: LEAGUE-MEMBER
          in: header
          required: true
          schema:
            pattern: '^(?!(?i)\bJOKER\b).*$'
            type: string
          example: BATMAN, JON, HAWKGIRL, ORACLE, FLASH, ANYONEBUTJOKER
      responses:
        '200':
          description: The resulting Delegate History

字符串
我在swagger.io编辑器中得到以下验证错误:

Structural error at paths./ent-watchtower-auth/v3/delegate.get.parameters.1.schema.pattern
should match format "regex"
format: regex


对于正则表达式上的上下文,'^(?!(?i)\bJOKER\b).*$'基本上允许头中除了'joker'之外的任何大小写不敏感的值。(另外,转换后的yaml没有将模式用单引号括起来,我不得不稍后添加它)。当我运行并测试我的RESTAPI时,模式按预期工作,如果值为““,则抛出ConstraintViolation。但我无法识别编辑器试图调用的内容。任何建议和可能的修复都很感激,谢谢。
更新:我已经粘贴了MWE的openapiyaml发挥周围的 Swagger 编辑器

yr9zkbsy

yr9zkbsy1#

我们遇到了同样的情况。似乎规范验证器不能识别像(?i)这样的模式标志作为有效的正则表达式。在我们的例子中,我们通过在字段注解中单独指定模式来解决这个问题:
@Pattern(regexp = "^etc$", flags = Pattern.Flag.CASE_INSENSITIVE)
这对于我们的情况来说是可以的,但并不理想,因为它没有将整个需求传达给spec消费者。

相关问题