使用 swagger codegen 时获取 'List<byte[]>'而不是简单的“字节[]" [英] when using swagger codegen getting 'List<byte[]>' instead of simply 'byte[]'
问题描述
一个 byte[] 在 swagger 文件中被建模为一个 byte[]
数组.当使用 swagger codegen 时,我们得到 List
而不是简单的 byte[]
A byte[] is modelled in swagger file as an Array of byte[]
. When using swagger codegen we are getting List<byte[]>
instead of simply byte[]
Swagger.json
Swagger.json
"document": {
"type": "array",
"items":
{
"type": "string",
"format": "byte"
}
}
pom.xml
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.json</inputSpec>
<language>java</language>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
推荐答案
问题在于生成 swagger.json 文件,即 maven 插件 swagger-maven-plugin.byte[] 的正确 swagger.json 文件应如下所示:
The issue is in generating the swagger.json file ie the maven plugin swagger-maven-plugin. The correct swagger.json file for a byte[] should look like:
"document": {
"type": "string",
"format": "byte"
}
为了实现这一点,我们必须完全按照以下链接添加自定义 ModelConvertors:https://github.com/kongchen/swagger-maven-plugin/issues/422
In order to achieve this we have to add custom ModelConvertors exactly as shown in below link: https://github.com/kongchen/swagger-maven-plugin/issues/422
还要在项目 pom 文件中添加 ModelConvertors 标记,其中包含自定义模型转换器位置的路径.
Also add ModelConvertors tag in the project pom file with the path to the location of your custom modelconvertor.
注意:swagger-codegen-maven-plugin 没有变化.
Note: There is no change in swagger-codegen-maven-plugin.
这篇关于使用 swagger codegen 时获取 'List<byte[]>'而不是简单的“字节[]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!