Я использую спецификацию swagger 2.0 и swagger-codegen-maven-plugin v.2.2.3
В моем проекте я использую небольшие файлы JSON для определения классов моделей, таких как
abstract.json
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "A part of model"
},
"paths": {},
"definitions": {
"A": {
"title": "A",
"type": "object",
"properties": {
"Aproperty": {
"type": "string",
"description": "Property which can be used in other classes"
}
}
}
}
}
real1.json
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "B part of model"
},
"paths": {},
"definitions": {
"B": {
"title": "B",
"type": "object",
"properties": {
"Bproperty": {
"$ref": "./abstract.json#/definitions/A"
}
}
}
}
}
real2.json
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "C part of model"
},
"paths": {},
"definitions": {
"C": {
"title": "C",
"type": "object",
"properties": {
"Cproperty": {
"$ref": "./abstract.json#/definitions/A"
}
}
}
}
}
Таким образом, другие компоненты могут использовать ту же модель, что и часть объекта в других компонентах. Он работает нормально и поддерживается из спецификации Swagger 2.0.
Но проблема начинается с попытки генерации Java-классов с помощью swagger-codegen-maven-plugin с другим пакетом
например, я использую конфигурацию типа
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-A-model</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger/abstract.json
</inputSpec>
<language>io.swagger.codegen.languages.JavaClientCodegen</language>
<library>feign</library>
<environmentVariables>
<models></models>
<modelDocs>false</modelDocs>
<supportingFiles>false</supportingFiles>
<apis>false</apis>
<apiTests>false</apiTests>
</environmentVariables>
<modelPackage>com.project.model.external.abstract</modelPackage>
<configOptions>
<sourceFolder>.</sourceFolder>
</configOptions>
<output>${project.build.directory}/generated-sources/swagger</output>
<addCompileSourceRoot>true</addCompileSourceRoot>
</configuration>
</execution>
<execution>
<id>generate-B-model</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger/real1.json
</inputSpec>
<language>io.swagger.codegen.languages.JavaClientCodegen</language>
<library>feign</library>
<environmentVariables>
<models></models>
<modelDocs>false</modelDocs>
<supportingFiles>false</supportingFiles>
<apis>false</apis>
<apiTests>false</apiTests>
</environmentVariables>
<modelPackage>com.project.model.external.real1</modelPackage>
<configOptions>
<sourceFolder>.</sourceFolder>
</configOptions>
<output>${project.build.directory}/generated-sources/swagger</output>
<addCompileSourceRoot>true</addCompileSourceRoot>
</configuration>
</execution>
<execution>
<id>generate-C-model</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger/real2.json
</inputSpec>
<language>io.swagger.codegen.languages.JavaClientCodegen</language>
<library>feign</library>
<environmentVariables>
<models></models>
<modelDocs>false</modelDocs>
<supportingFiles>false</supportingFiles>
<apis>false</apis>
<apiTests>false</apiTests>
</environmentVariables>
<modelPackage>com.project.model.external.real2</modelPackage>
<configOptions>
<sourceFolder>.</sourceFolder>
</configOptions>
<output>${project.build.directory}/generated-sources/swagger</output>
<addCompileSourceRoot>true</addCompileSourceRoot>
</configuration>
</execution>
У меня будет три одинаковых класса A.java в трех пакетах
- пакет com.project.model.external.abstract.A.java
- пакет com.project.model.external.real1.A.java
- пакет com.project.model.external.real2.A.java
Возможно ли иметь только один класс A в абстрактном пакете вместо дерева дубликатов файлов с swagger-codegen-maven-plugin?