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

OpenAPI generates wrong example for URLs #42101

Closed
BrianSetz opened this issue Jul 24, 2024 · 3 comments · Fixed by #41037
Closed

OpenAPI generates wrong example for URLs #42101

BrianSetz opened this issue Jul 24, 2024 · 3 comments · Fixed by #41037
Labels
Milestone

Comments

@BrianSetz
Copy link

Describe the bug

Any URL (object) in the request body is translated to

{
  "protocol": "string",
  "host": "string",
  "port": 0,
  "file": "string",
  "authority": "string",
  "ref": "string",
  "hashCode": 0,
  "defaultPort": 0,
  "content": "string",
  "serializedHashCode": 0
}

In the SwaggerUI. The generated example does not actually work since the request expects a string (e.g. "https://example.com)

Expected behavior

URLs in the request body should be converted to strings.

Actual behavior

URLs in the request body are converted to a dump of the URL object itself.

How to Reproduce?

Reproducer, use REST + REST Jackson + OpenAPI extensions:

@Path("/hello")
class ExampleResource {

    /**
     * This produces in invalid schema example for the request body:
     *
     * {
     *   "protocol": "string",
     *   "host": "string",
     *   "port": 0,
     *   "file": "string",
     *   "authority": "string",
     *   "ref": "string",
     *   "hashCode": 0,
     *   "defaultPort": 0,
     *   "content": "string",
     *   "serializedHashCode": 0
     * }
     *
     * The response will be 400 Bad Request.
     *
     * When manually specifying the following request body:
     *
     * "https://example.com"
     *
     * The response will be 200 OK "Received URL: https://example.com".
     */
    @POST
    @Path("/url-invalid-schema")
    fun postUrlInvalidSchemaExample(url: URL) = "Received URL: $url"
}

Output of uname -a or ver

Ubuntu

Output of java -version

Java 21

Quarkus version or git rev

3.12.3

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 8.8

Additional information

Perhaps we need a TYPE_MAP.put(DotName.createSimple(java.net.URL.class.getName()), URL_FORMAT); in https://github.com/smallrye/smallrye-open-api/blob/8ffefb1bfc45a3a3345f6cd10d3db9d050c4c9ba/core/src/main/java/io/smallrye/openapi/runtime/util/TypeUtil.java#L133

@BrianSetz BrianSetz added the kind/bug Something isn't working label Jul 24, 2024
Copy link

quarkus-bot bot commented Jul 24, 2024

/cc @MikeEdgar (swagger-ui), @geoand (kotlin), @phillip-kruger (swagger-ui)

@phillip-kruger phillip-kruger changed the title Swagger UI generates wrong example for URLs OpenAPI generates wrong example for URLs Jul 24, 2024
@phillip-kruger
Copy link
Member

I am going to open an issue against the SmallRye OpenAPI repo that reference this issue, as this will most likely needs to be fixed there.

@phillip-kruger
Copy link
Member

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

Successfully merging a pull request may close this issue.

2 participants