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 rest multipart - combine file and json object #327

Open
bulalak opened this issue Jun 15, 2018 · 3 comments
Open

spring rest multipart - combine file and json object #327

bulalak opened this issue Jun 15, 2018 · 3 comments

Comments

@bulalak
Copy link

bulalak commented Jun 15, 2018

I described a multipart request in the yml where I want to combine more data (file + json object) into single body. But generated code (interface) for spring rest is used with @RequestParam annotation and it is not working. When I manually replace it with @RequestPart it is working correctly.

plugin in pom

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>3.0.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/src/main/resources/swagger-api.yml</inputSpec>
                <generatorName>spring</generatorName>
                <modelNameSuffix>DTO</modelNameSuffix>
                <apiPackage>sk.xxx.document.api</apiPackage>
                <modelPackage>sk.xxx.document.model</modelPackage>
                <generateSupportingFiles>false</generateSupportingFiles>
                <configOptions>
                    <interfaceOnly>true</interfaceOnly>
                    <dateLibrary>java8</dateLibrary>
                    <java8>false</java8>
                    <jdk8>true</jdk8>
                    <library>spring-boot</library>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

yml

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger document
servers:
  - url: http://localhost:9999
paths:
  /documents:
    post:
      operationId: addDocument
      requestBody:
        description: add document
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                person:
                  $ref: '#/components/schemas/PersonNew'
                file:
                  type: string
                  format: binary
            encoding:
              person:
                contentType: application/json
      responses:
        '200':
          description: success operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Person'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Person:
      allOf:
        - $ref: '#/components/schemas/PersonNew'
        - required:
          - id
          properties:
            id:
              type: integer
              format: int64

    PersonNew:
      type: object
      required:
        - firstName
        - lastName
      properties:
        firstName:
          type: string
        lastName:
          type: string
        bithDate:
          type: string
          format: 'date-time'

    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

generated interface

    ResponseEntity<PersonDTO> addDocument(@ApiParam(value = "", defaultValue="null") @RequestParam(value="person", required=false)  PersonNewDTO person,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile file);
@carlosmonterocanabal
Copy link

Hi @bulalak , did you resolve this bug with any workaround?

@kowlown
Copy link

kowlown commented Jul 8, 2022

This bug is still present

@lvanderbijl-kry
Copy link

Same problem here, multipart body with a json object gets generated as @RequestParam instead of @RequestPart.

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

4 participants