使用可重用参数

时间:2017-09-14 13:26:15

标签: swagger swagger-2.0 swagger-codegen

我有一个以下的swagger文件(使用Swagger在线编辑器解析):

swagger: '2.0'
info:
  title: Sample
  version: 1.1.0

basePath: /base

paths:
  /sample:
    get:
      summary: Gets the samples
      parameters:
        - $ref: '#parameters/reusableParam'
      responses:
        200:
          description: Success
parameters:
  reusableParam:
    in: header
    name: sample-param
    required: true
    type: string
    description: Sample reusable parameter

当我在其上运行代码生成器时:

java -jar swagger-codegen-cli-2.2.1.jar generate -i swagger.yaml -l java

失败并显示错误:

Exception in thread "main" java.lang.NullPointerException
        at io.swagger.codegen.DefaultGenerator.generateParameterId(DefaultGenerator.java:803)
        at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:727)
        at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:688)
        at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:376)
        at io.swagger.codegen.cmd.Generate.run(Generate.java:223)
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)

我在可重用参数的定义中做错了吗?

1 个答案:

答案 0 :(得分:1)

您的规范中存在拼写错误:

- $ref: '#parameters/reusableParam'

应该是

- $ref: '#/parameters/reusableParam'