Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spring] Required post body with path parameters produces uncompilable code #255

Closed
staale opened this issue Dec 7, 2018 · 5 comments
Closed

Comments

@staale
Copy link

staale commented Dec 7, 2018

If you have a required requestBody in combination with path parameters, the body will be placed first, and there will be no comma after it in the generated codes argument list:

Attached sample openapi.yaml, invoke with:

java -jar swagger-codegen-cli-3.0.3.jar generate -i openapi.yaml -l spring -o test

Resulting code:

    ResponseEntity<Body> failure(
        @ApiParam(value = "" ,required=true )  @Valid @RequestBody
        Body body@ApiParam(value = "First value",required=true) @PathVariable("first") 
        String first,
        @ApiParam(value = "Second value",required=true) @PathVariable("second") String second);

I have reformatted the code slightly to highlight the error.

openapi.txt

@totothekiller
Copy link

I have the same issue (with swagger-codegen-maven-plugin 3.0.3)
In my case, the type of @RequestBody body variable is wrongly set to Object.

@wvitte
Copy link

wvitte commented Jan 3, 2019

I had similar issue with swagger-codegen-maven-plugin 3.0.3. I see the no comma after it generated code.

default ResponseEntity<IndexRequestResponse> createIndex( IndexRequest body String id) {

@voydz
Copy link

voydz commented Jan 9, 2019

Hi,

Maybe this issue has to be generalized? I am experiencing the same issue for both csharp generators (csharp and csharp-dotnet2).

Example:

Request method definition:

...
"/api/v1/Device/AddUserDevice":{
   "post":{
      "tags":[
         "Device"
      ],
      "operationId":"Device_AddUserDevice",
      "consumes":[
         "application/json",
         "text/json",
         "application/xml",
         "text/xml",
         "application/x-www-form-urlencoded"
      ],
      "produces":[
         "application/json",
         "text/json",
         "application/xml",
         "text/xml"
      ],
      "parameters":[
         {
            "name":"value",
            "in":"body",
            "required":true,
            "schema":{
               "$ref":"#/definitions/DeviceModel"
            }
         }
      ],
      "responses":{
         "200":{
            "description":"OK"
         },
         "400":{
            "description":"BadRequest"
         }
      }
   }
}
...

Body schema definition:

...
"DeviceModel":{
   "type":"object",
   "properties":{
      "id":{
         "type":"string"
      },
      "created":{
         "format":"date-time",
         "type":"string"
      },
      "additionalInformation":{
         "type":"string"
      },
      "deviceId":{
         "type":"string"
      },
      "deviceTypeId":{
         "format":"int32",
         "type":"integer"
      },
      "userId":{
         "type":"string"
      },
      "deviceName":{
         "type":"string"
      },
      "controlAuthorizationLevel":{
         "format":"int32",
         "type":"integer"
      },
      "isOwnedByMe":{
         "type":"boolean"
      },
      "isSharedToOthers":{
         "type":"boolean"
      }
   }
}
...

And the output I get for <SwaggerGeneratedProjectRoot>/Api/DeviceApi.cs is:

    /// <summary>
    /// Represents a collection of functions to interact with the API endpoints
    /// </summary>
    public interface IDeviceApi : IApiAccessor
    {
        #region Synchronous Operations
        /// <summary>
        /// 
        /// </summary>
        /// <remarks>
        /// 
        /// </remarks>
        /// <exception cref="Api.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body"></param>
        /// <param name="id"> (optional)</param>
        /// <param name="created"> (optional)</param>
        /// <param name="additionalInformation"> (optional)</param>
        /// <param name="deviceId"> (optional)</param>
        /// <param name="deviceTypeId"> (optional)</param>
        /// <param name="userId"> (optional)</param>
        /// <param name="deviceName"> (optional)</param>
        /// <param name="controlAuthorizationLevel"> (optional)</param>
        /// <param name="isOwnedByMe"> (optional)</param>
        /// <param name="isSharedToOthers"> (optional)</param>
        /// <returns></returns>
        void DeviceAddUserDevice (DeviceModel bodystring id = null, DateTime? created = null, string additionalInformation = null, string deviceId = null, int? deviceTypeId = null, string userId = null, string deviceName = null, int? controlAuthorizationLevel = null, bool? isOwnedByMe = null, bool? isSharedToOthers = null);
...

Notice the missing comma between the first and second parameter. DeviceModel bodystring id = null would have to be DeviceModel body, string id = null.

@wvitte
Copy link

wvitte commented Jan 9, 2019

it works for me if I remove

"required":true,

@HugoMario
Copy link
Contributor

hello guys, this issue has been fixed with PR #267. Going to close this ticket but please let me know if there's still something wrong and i'll handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants