带有可重用参数的 Swagger 代码生成器错误
Swagger code generator error with a reusable parameter
我有以下 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)
我在可重用参数的定义中做错了什么吗?
您的规范中有错字:
- $ref: '#parameters/reusableParam'
应该是
- $ref: '#/parameters/reusableParam'
我有以下 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)
我在可重用参数的定义中做错了什么吗?
您的规范中有错字:
- $ref: '#parameters/reusableParam'
应该是
- $ref: '#/parameters/reusableParam'