摇摇模型到斯卡拉案例类

时间:2019-11-06 12:50:13

标签: scala swagger swagger-akka-http

我有akka http的sbt项目。有一个文档api任务。为此,我选择了插件swagger-akka-http 2.0.4版本。 我有这种摇摇欲坠的模型,我需要将其转换为scala case class

Rules2:
  required:
  - _1
  type: object
  properties:
    _1:
      type: array
      items:
        type: string
    _2:
      type: array
      items:
        type: string
    _3:
      type: array
      items:
        type: string
    _4:
      type: array
      items:
        type: string
    _5:
      type: array
      items:
        type: string
    _6:
      type: array
      items:
        type: string
    _7:
      type: array
      items:
        type: string
    _8:
      type: array
      items:
        type: string
    _9:
      type: array
      items:
        type: string
    _10:
      type: array
      items:
        type: string
    _11:
      type: array
      items:
        type: string

我为该模型编写了案例类

case class Rules2(
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = true)) _1: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _2: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _3: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _4: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _5: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _6: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _7: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _8: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _9: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _10: String,
                   @ArraySchema(schema = new Schema(implementation = classOf[String], required = false)) _11: String
)

,此案例类的结果为:

Rules2:
      required:
      - _1
      - _2
      type: object
      properties:
        _1:
          type: array
          items:
            type: string
        _2:
          type: array
          items:
            type: string
        _3:
          type: array
          items:
            type: string
        _4:
          type: array
          items:
            type: string
        _5:
          type: array
          items:
            type: string
        _6:
          type: array
          items:
            type: string
        _7:
          type: array
          items:
            type: string
        _8:
          type: array
          items:
            type: string
        _9:
          type: array
          items:
            type: string
        _10:
          type: array
          items:
            type: string
        _11:
          type: array
          items:
            type: string

,但是您可以看到在required字段_2列中显示。为什么?如何仅使用一个必填字段创建摇摇模型?

0 个答案:

没有答案