swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.9k stars 6.03k forks source link

[JAVA] [jaxrs-jersey] Multiline description strings in the definition of requestBodies leads to invalid @ApiParam Java annotations #8664

Open pneumcke opened 6 years ago

pneumcke commented 6 years ago
Description

Having a multiline string in the definition of a request body leads to a multiline @ApiParam annotation in the generated file which results in compile errors

Swagger-codegen version

3.0.0-rc1

Swagger declaration file content or url

https://berlingroup.stackstorage.com/s/d4KSrRW9bDYmrSg

line 8691 defines the request body "paymentInitiation" with a multiline description:

    paymentInitiation:
      description: |
        JSON request body for a payment inition request message 

        There are the following payment-products supported:
          * "sepa-credit-transfers" with JSON-Body
          * "instant-sepa-credit-transfers" with JSON-Body
          * "target-2-payments" with JSON-Body
          * "cross-border-credit-transfers" with JSON-Body
          * "pain.001-sepa-credit-transfers" with XML pain.001.001.03 body for SCT scheme
          * "pain.001-instant-sepa-credit-transfers" with XML pain.001.001.03 body for SCT INST scheme
          * "pain.001-target-2-payments" with pain.001 body. 
            Only country specific schemes are currently available
          * "pain.001-cross-border-credit-transfers" with pain.001 body. 
            Only country specific schemes are currently available

        There are the following payment-services supported:
          * "payments"
          * "periodic-payments"
          * "bulk-paments"

        All optional, conditional and predefined but not yet used fields are defined.
      required: true
Command line used for generation

java -jar swagger-codegen-cli-3.0.0-rc1.jar generate -l jaxrs-jersey -i psd2-api\ 1.2\ Update\ 2018-08-17.yaml --api-package test --model-package test --library jersey2

Steps to reproduce

Have a look at the generated file src/gen/java/test/V1Api.java. Line 1231 shows the invalid @ApiParam:

public Response initiatePayment(@ApiParam(value = "JSON request body for a payment inition request message 

There are the following payment-products supported:
  * "sepa-credit-transfers" with JSON-Body
  * "instant-sepa-credit-transfers" with JSON-Body
....
Suggest a fix/enhancement

Multiline descriptions work for parameters. See e.g. line 8168 in the yaml file, where a parameter "paymentService" is defined:

    paymentService:
      name: payment-service
      in: path
      description: |
        Payment service:

        Possible values are:
        * payments
        * bulk-payments
        * periodic-payments
      required: true

This leads to a totally valid single line @ApiParam definition, see e.g. Line 121 in the generated file V1Api.java.

Please handle multine descriptions for requestBodies exactly as in parameters.

HugoMario commented 5 years ago

hi @pneumcke, , can you please try with https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.0 ? and let me know if there is still something wrong?

d-ryzhov commented 5 years ago

v3.0.4 - same issue: @ApiParam(value = "desciption " ,required=true )