在swagger code gen的其他项目中使用swagger中的现有模型
这就是背景: 我正在使用swagger代码生成器构建API的结构 但我的第一个问题是,实际上该API将具有公共实体的依赖性在swagger code gen的其他项目中使用swagger中的现有模型,swagger,swagger-2.0,swagger-codegen,Swagger,Swagger 2.0,Swagger Codegen,这就是背景: 我正在使用swagger代码生成器构建API的结构 但我的第一个问题是,实际上该API将具有公共实体的依赖性 My-Java-Swagger-Project -Controller -Entities(model) -Everything else My-commons-project -Common Entities 所以,如果Swagger generator将构建“我的java Swagger项目”,并且我将在其上使用我的commons项目的实体,那
My-Java-Swagger-Project
-Controller
-Entities(model)
-Everything else
My-commons-project
-Common Entities
所以,如果Swagger generator将构建“我的java Swagger项目”,并且我将在其上使用我的commons项目的实体,那么我如何指示Swagger生成并使用我的commons项目的现有类,或者不构建我在commons项目中已经拥有的实体
definitions:
Response:
type: "object"
properties:
status:
type: "string"
description: "Returns if it was successful or not. "
errors:
type: "array"
items:
$ref: "#/definitions/ErrorTO"
Request:
type: "object"
required:
- subject
- messageText
properties:
subject:
type: "string"
messageText:
type: "string"
ErrorTO: #This one must not be defined in swagger because it's on my #commons project
type: object
properties:
code:
type: "string"
description:
type: "string"
当我运行Swagger codegen输出ErrorTO entity时,但我已经在其他项目中运行了,那么我如何定义Swagger以不创建该实体并使用我的一个公用项(或仅不创建它)您可以定义
导入映射
和类型映射
到代码生成器,告诉它使用导入的类。不确定您使用的是哪种生成器,但我使用Java/spring引导服务器存根生成器。我起诉maven插件,就像
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${swagger.codegen.version}</version>
<executions>
<execution>
<id>foo</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<importMappings>
<importMapping>Foo=com.example.common.Foo</importMapping>
</importMappings>
<typeMappings>
<typeMapping>Foo=com.example.common.Foo</typeMapping>
<typeMappings>
</configuration>
</execution>
</plugin>
昂首阔步
swagger codegen maven插件
${swagger.codegen.version}
福
生成
Foo=com.example.common.Foo
Foo=com.example.common.Foo
您可以向代码生成器定义导入映射
和类型映射
,告诉它使用导入的类。不确定您使用的是哪种生成器,但我使用Java/spring引导服务器存根生成器。我起诉maven插件,就像
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${swagger.codegen.version}</version>
<executions>
<execution>
<id>foo</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<importMappings>
<importMapping>Foo=com.example.common.Foo</importMapping>
</importMappings>
<typeMappings>
<typeMapping>Foo=com.example.common.Foo</typeMapping>
<typeMappings>
</configuration>
</execution>
</plugin>
昂首阔步
swagger codegen maven插件
${swagger.codegen.version}
福
生成
Foo=com.example.common.Foo
Foo=com.example.common.Foo