swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[JAVA] Retrofit2 RXJava2 CodeGen : @Path must be before @Query, still an issue with POST methods

Open cuanp2007 opened this issue 8 years ago • 1 comments

Description

The issue with regards to "@Path must be before @Query" was fixed in issue 6391. But I'm still getting it on POST methods when there is a "body" parameter.

Swagger-codegen version

2.3.1

Swagger declaration file content or url

swagger: '2.0'
info:
  version: v1
  title: Mobile REST Service v1.0
  description: My mobile REST service
host: localhost.com
schemes:
  - https
paths:
  '/api/v{api-version}/Contacts':
    post:
      tags:
        - Contacts
      operationId: Contacts_SendListingContactMessage
      consumes:
        - application/json
        - text/json
        - application/xml
        - text/xml
        - application/x-www-form-urlencoded
      produces: []
      parameters:
        - name: contactMessageType
          in: query
          required: true
          type: string
          enum:
            - Development
            - Listing
        - name: listingNumber
          in: query
          required: true
          type: string
        - name: emailAddress
          in: query
          required: true
          type: string
        - name: name
          in: query
          required: true
          type: string
        - name: cellNumber
          in: query
          required: true
          type: string
        - name: comment
          in: query
          required: true
          type: string
        - name: logViewDetail
          in: body
          required: true
          schema:
            $ref: '#/definitions/LogViewDetail'
        - name: api-version
          in: path
          description: The requested API version
          required: true
          type: string
          default: '1.0'
        - name: P24-AppVersion
          in: header
          description: application version
          required: true
          type: string
        - name: P24-UIContextId
          in: header
          description: UI Context
          required: true
          type: integer
        - name: P24-UniqueUserId
          in: header
          description: unique user id
          required: true
          type: string
      responses:
        '204':
          description: No Content
definitions: 
  LogViewDetail:
    type: object
    properties:
      LogListingViewsReportType:
        enum:
          - Undefined
          - AlertView
        type: string
      ShouldLog:
        type: boolean
      UserId:
        format: int32
        type: integer
      PromotedListingType:
        enum:
          - None
          - LegacyFeatured
          - Premium
          - NewFeatured
        type: string
      DomainLogListingViewsReportType:
        enum:
          - Undefined
          - AlertView
          - DirectEmail
        type: string
        readOnly: true
      DomainPromotedListingLoggingType:
        enum:
          - NotApplicable
          - Premium
        type: string
        readOnly: true
      DomainPromotedListingType:
        enum:
          - Featured
          - Premium
        type: string
        readOnly: true

The generated output is as follows. with apiVersion parameter appearing in the middle of the parameters.

  @Headers({
    "Content-Type:application/json"
  })
  @POST("api/v{api-version}/Contacts")
  Observable<Void> contactsSendListingContactMessage(
    @retrofit2.http.Query("contactMessageType") String contactMessageType, @retrofit2.http.Query("listingNumber") String listingNumber, @retrofit2.http.Query("emailAddress") String emailAddress, @retrofit2.http.Query("name") String name, @retrofit2.http.Query("cellNumber") String cellNumber, @retrofit2.http.Query("comment") String comment, @retrofit2.http.Body LogViewDetail logViewDetail, @retrofit2.http.Path("api-version") String apiVersion, @retrofit2.http.Header("P24-AppVersion") String p24AppVersion, @retrofit2.http.Header("P24-UIContextId") Integer p24UIContextId, @retrofit2.http.Header("P24-UniqueUserId") String p24UniqueUserId
  );
Command line used for generation

java -jar swagger-codegen-cli.jar generate -l java --library retrofit2 --additional-properties useRxJava2=true -i swagger.yaml

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/6391

cuanp2007 avatar May 30 '18 11:05 cuanp2007

This can be ignored.

My parameters were generated in that order using Swashbuckle. I added an operation filter to reorder my parameters before generating the swagger spec. This fixed my issue.

Thanks

cuanp2007 avatar Jun 01 '18 11:06 cuanp2007