question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][Java] ApiClient.java: error: no suitable method found for create(byte[],MediaType)

See original GitHub issue

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • [] What’s the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using the java generator against a basic spec, the generated project fails to compile.

openapi-generator version

5.1.0 and latest master (docker image 3c6b0382cd49)

Regression from 5.0.1

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Api

paths:
  /version:
    get:
      tags:
      - version
      summary: Gets the system version check
      operationId: getVersion
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VersionGetResponse'

components:
  schemas:
    VersionGetResponse:
      type: string
      description: The version of this service
      required:
        - status
      properties:
        status:
          type: string
          description: OK

Generation Details

java -jar openapi-generator-cli-5.1.0.jar generate -g java -i service.yaml

Steps to reproduce
  1. Run the generator as described above
  2. Try to compile the code with ./gradlew compileJava or similar
Expected:

It will compile

Actual:

A bunch of:

out\java\src\main\java\org\openapitools\client\ApiClient.java:818: error: no suitable method found for create(byte[],MediaType)
            return RequestBody.create((byte[]) obj, MediaType.parse(contentType));
                              ^
    method RequestBody.create(MediaType,String) is not applicable
      (argument mismatch; byte[] cannot be converted to MediaType)
    method RequestBody.create(MediaType,ByteString) is not applicable
      (argument mismatch; byte[] cannot be converted to MediaType)
    method RequestBody.create(MediaType,byte[]) is not applicable
      (argument mismatch; byte[] cannot be converted to MediaType)
    method RequestBody.create(MediaType,File) is not applicable
      (argument mismatch; byte[] cannot be converted to MediaType)
Related issues/PRs
Suggest a fix

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
cb-manideepcommented, Apr 26, 2021

@toby-murray-snow-software Please go ahead 😃

1reaction
cb-manideepcommented, Apr 11, 2021

@cb-manideep can you please file a PR with the suggested change?

Sure!

Read more comments on GitHub >

github_iconTop Results From Across the Web

no suitable method found for add() error - java - Stack Overflow
This question was caused by a typo or a problem that can no longer be ... Error:(20, 59) error: no suitable method found...
Read more >
API Client Library for Java - Google Developers
Easily access Google APIs from Java ... The Google API Client Library for Java provides functionality common to all Google APIs, for example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found