微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swagger客户端生成器-与Response.class冲突

如何解决Swagger客户端生成器-与Response.class冲突

我正在使用io.swagger生成器和给定的yaml文件创建一个rest客户端,该yaml定义了一个Response元素,该元素导致生成器创建一个Response.class。问题在于,在另一个生成的DefaultApi类中,导入包括该类和一个未使用的javax.ws.rs.core.Response,但会在两个导入之间产生冲突。如果我在yaml文件重命名Response元素,问题就消失了,但实际上我不应该更改此文件。 有没有办法指示生成器使用其他名称(别名)创建类?我正在训练不要更改yaml文件

pom.xml

<dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jaxrs</artifactId>
            <scope>compile</scope>
            <version>${swagger-core-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-rs-client</artifactId>
            <version>${cxf-version}</version>
            <scope>compile</scope>
        </dependency>

...

    <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>${swagger-codegen-maven-plugin.version}</version>
                <configuration>
                    <generateApiTests>false</generateApiTests>
                    <generateModelTests>false</generateModelTests>
                    <!-- <language>java</language> -->
                    <language>jaxrs-cxf-client</language>
                </configuration>

                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>src/main/resources/technicalViability.yaml</inputSpec>
<!--                            <supportingFilesToGenerate>ApiCallback.java,apiclient.java,ApiException.java,ApiResponse.java,Configuration.java,Pair.java,ProgressRequestBody.java,ProgressResponseBody.java,StringUtil.java,ApiKeyAuth.java,Authentication.java,HttpBasicAuth.java,JSON.java,OAuth.java</supportingFilesToGenerate> -->
                            <configOptions>
                                <sourceFolder>src/</sourceFolder>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

...

<lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>io.swagger</groupId>
                                        <artifactId>swagger-codegen-maven-plugin</artifactId>
                                        <versionRange>${swagger-codegen-maven-plugin.version}</versionRange>
                                        <goals>
                                            <goal>generate</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>

technicalViability.yml

paths:
 /technicalViability:
   get:
     produces:
        - application/xml
        - application/json
     parameters:
     - name: "tlkServiceId"
       in: "query"
       description: "Servicio TLK"
       required: false
       type: "string"
     - name: "tincoServiceId"
       in: "query"
       description: "Servicio Tinco"
       required: false
       type: "string"

     responses:
       "200":
         description: "OK"
         schema:
          $ref: "#/deFinitions/response"
     security:
      - sso_auth: []

securityDeFinitions:
  sso_auth:
    type: "oauth2"
    flow: accessCode
    authorizationUrl: "--"
    tokenUrl: "--"

deFinitions:
  response:
    type: "object"
    properties:
      code:
        type: "integer"
        description: "codigo de respuesta"
      message:
        type: "string"
        description: "mensaje descriptivo"
      listaFacilidades:
        type: "array"
        items:
          $ref: "#/deFinitions/facilidad"
  facilidad:
    type: "object"
    properties:
      wp_cod_sefp:
        type: "string"
        description: "codigo psef"
      wp_tipo_sefp:
        type: "string"
        description: "tipo de psef"

DefaultApi.class

package io.swagger.api;

import io.swagger.model.Response;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
import org.apache.cxf.jaxrs.ext.multipart.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH;

/**
 * Technical Viability
 *
 * <p>No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
 *
 */
@Path("/")
@Api(value = "/",description = "")
public interface DefaultApi  {

    @GET
    @Path("/technicalViability")
    @Produces({ "application/xml","application/json" })
    @ApiOperation(value = "",tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200,message = "OK",response = Response.class) })
    public Response technicalViabilityGet(@QueryParam("tlkServiceId")String tlkServiceId,@QueryParam("tincoServiceId")String tincoServiceId);
}

错误:导入javax.ws.rs.core.Response与另一个导入语句冲突

解决方法

在这种情况下,您应该选择一个在imports中使用,另一个选择完全合格的类名(包名+类名)以指定要放置的位置。否则,您将面临导入xxxx。响应与另一个导入语句冲突。因此,例如从导入中删除 io.swagger.model.Response,然后:

public  io.swagger.model.Response technicalViabilityGet(@QueryParam("tlkServiceId")String tlkServiceId,@QueryParam("tincoServiceId")String tincoServiceId);
,

最后,我改变了生成客户端的方式,问题消失了。

pom.xml

<dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jaxrs</artifactId>
            <scope>compile</scope>
            <version>1.5.22</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp</groupId>
            <artifactId>logging-interceptor</artifactId>
            <version>2.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.threeten</groupId>
            <artifactId>threetenbp</artifactId>
            <version>1.4.5</version>
        </dependency>
        <dependency>
            <groupId>io.gsonfire</groupId>
            <artifactId>gson-fire</artifactId>
            <version>1.8.4</version>
        </dependency>
...
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>${swagger-codegen-maven-plugin.version}</version>
                <configuration>
                    <generateApiTests>false</generateApiTests>
                    <generateModelTests>false</generateModelTests>
                    <language>java</language>
                </configuration>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。