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

[BUG][SPRING]compilation errors due to different request body type in api and apiDelegate files #3905

Open
4 of 6 tasks
anuhyapolisetti opened this issue Sep 17, 2019 · 4 comments

Comments

@anuhyapolisetti
Copy link

anuhyapolisetti commented Sep 17, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

We have encountered this problem
generated Api and ApiDelegate files have different request body types (Resource/MultipartFile), which is resulting in compilation errors.

Issue seemed to have addressed in v4.0.0-beta3 version, but issue still persists when we tried with the cli version of v4.0.0-beta3.

openapi-generator version

v4.0.2

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: testapp
  version: 0.0.1
servers:
  - url: 'http://localhost:8081/api'
    description: Development server
paths:
  '/foo':
    post:
      operationId: foo
      requestBody:
        content:
          image/png:
            schema:
              type: string
              format: binary
      responses:
        default:
          description: successful operation
Command line used for generation

java -jar openapi-generator-cli.jar generate -g spring -i api.yml -o ./out --additional-properties delegatePattern=true

Steps to reproduce
  1. Run the command above with provided api.yml.
  2. Open out/src/main/java/org/openapitools/api/FooApi.java, look at generated foo method
    default ResponseEntity<Void> foo(@ApiParam(value = ""  )  @Valid @RequestBody Resource body) {
        return getDelegate().foo(body);
    }
  1. Open out/src/main/java/org/openapitools/api/FooApiDelegate.java, look at generated apiDelegate method
    default ResponseEntity<Void> foo(MultipartFile body) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }

foo from FooApiDelegate consumes MultipartFile whereas FooApi passes Resource as request body type.

Related issues/PRs
  1. [Spring] fix datatype for non-multipart file request body #2271

Issue seemed to have addressed in v4.0.0-beta3 version per above PR, but issue still persists when we tried with the cli version of v4.0.0-beta3.

  1. [BUG][Java][Server:Spring-boot] File upload spec (application/octet-stream) generates MultiPartFile Delegate #2191
Suggest a fix

Use either Multipartfile or Resource in both api and apidelegate

@auto-labeler
Copy link

auto-labeler bot commented Sep 17, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@nickshoe
Copy link

nickshoe commented Nov 7, 2019

I'm experiencing the same problem with version 4.1.3 (in a JHipster API-first project).

operation:

/attachments:
  post:
    description: Creates a new Attachment by a file upload
    operationId: createAttachment
    requestBody:
      content:
        application/octet-stream:
          schema:
            $ref: '#/components/schemas/AttachmentFile'

schema:

AttachmentFile:
  type: string
  format: binary

generated "...ApiDelegate" interface method:

default ResponseEntity<Attachment> createAttachment(MultipartFile body) { ... }

generated "...Api" interface method:

default ResponseEntity<Attachment> createAttachment(@ApiParam(value = ""  )  @Valid @RequestBody Resource body) {
    return getDelegate().createAttachment(body);
}

@saephir
Copy link
Contributor

saephir commented Jan 21, 2020

I'm dropping this workaround just in case:

Define typeMapping in pom.xml (or analogous Gradle config):

<typeMappings>binary-string=org.springframework.core.io.Resource</typeMappings>

and use binary-string in the OpenAPI specification:

requestBody:
  content:
    application/octet-stream:
      schema:
        type: binary-string

@d-j-kendall
Copy link

<typeMappings>binary-string=org.springframework.core.io.Resource</typeMappings>

Life saver my guy, I've been looking all over for a workaround as this issue is still present in 5.4.0

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

No branches or pull requests

4 participants