Skip to content

[BUG][JAVA] Invalid code generated for jersey2 and 3 when path parameter have format uri #19129

@gtsystem

Description

@gtsystem

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

When a parameter is defined in the path with format uri, the libraries jersey2 and 3 generates invalid code that fail with error: incompatible types: URI cannot be converted to String

openapi-generator version

Tested with 7.7.0 and 7.8.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Example API v1
  description: A reference API
  contact: {}
  version: 2.0.0
paths:
  /resources/{uri}:
    get:
      operationId: list
      parameters:
        - in: path
          name: uri
          required: true
          schema:
            type: string
            format: uri
      responses:
        '200':
          description: Test
          content:
            application/json:
              schema: {}
Generation Details

language: java
library: jersey2 or jersey3

Steps to reproduce
  1. Save the file above as openapi.yml
  2. Execute docker run -v `pwd`:/temp -it openapitools/openapi-generator-cli:latest generate -g java -i /temp/openapi.yml -o /temp/build/ --library=jersey3
  3. Look at the content of the generated file build/src/main/java/org/openapitools/client/api/DefaultApi.java

Current:

    // Path parameters
    String localVarPath = "/resources/{uri}"
            .replaceAll("\\{uri}", apiClient.escapeString(uri));

Expected

    // Path parameters
    String localVarPath = "/resources/{uri}"
            .replaceAll("\\{uri}", apiClient.escapeString(uri.toString()));
Other details

This is working fine targeting the library okhttp-gson and the output is

        // create path and map variables
        String localVarPath = "/resources/{uri}"
            .replace("{" + "uri" + "}", localVarApiClient.escapeString(uri.toString()));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions