Skip to content

Conversation

@rhusar
Copy link
Member

@rhusar rhusar commented Dec 19, 2025

@rhusar rhusar requested a review from emmartins as a code owner December 19, 2025 08:52
@rhusar rhusar changed the title R39.0.0.beta1 with openapi fix https://issues.redhat.com/browse/WFLY-21302 R39.0.0.beta1 with openapi fix WFLY-21302 Dec 19, 2025
@rhusar
Copy link
Member Author

rhusar commented Dec 19, 2025

Lets go with #1118

@rhusar rhusar closed this Dec 19, 2025
@emmartins emmartins reopened this Dec 19, 2025
@emmartins
Copy link
Contributor

please update this one instead, otherwise will need to wait or manually close all pending tests

@emmartins
Copy link
Contributor

once in this route, till the end :)

@rhusar rhusar force-pushed the r39.0.0.Beta1-with-openapi branch from 0c320ef to 0abd619 Compare December 19, 2025 09:06
@emmartins emmartins merged commit 2f6f604 into wildfly:main Dec 19, 2025
581 checks passed
@rhusar rhusar deleted the r39.0.0.Beta1-with-openapi branch December 19, 2025 11:01
@rhusar
Copy link
Member Author

rhusar commented Dec 19, 2025

Awesome!

.followRedirects(HttpClient.Redirect.ALWAYS)
.connectTimeout(Duration.ofMinutes(1))
.build();
final HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not portable. If the OpenAPI request does not define a specific encoding, via the Accept-Charset (or Accept) header, then it will use UTF-8 was specified in the request. Since the above request does include this header, the response may differ from the default charset of the test client.

Either:

  • Specify an Accept-Charset or Accept header in the request (using the default charset of the test client)
  • Read the body using default encoding of the OpenAPI endpoint, i.e. HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pferraro The "response may differ from the default charset of the test client" statement is false.

The no-argument version of HttpResponse.BodyHandlers.ofString() does NOT use "the default charset of the test client" (not to be confused with Charset.defaultCharset()).

Instead, it

  1. Uses the charset specified in the response's Content-Type header if present
  2. Falls back to UTF-8 if no charset is specified in the response

See javadoc: https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpResponse.BodyHandlers.html#ofString()

Also, this same code is used in most of the quickstarts here, so if this were to be problematic, it could affect more of the QSs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - you are correct sir ... even if your javadoc reference is old :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, now I'm questioning how we actually handle this stuff...

According to:
https://www.rfc-editor.org/rfc/rfc8259#section-8.1
https://yaml.org/spec/1.2.2/#52-character-encodings

... we should actually return a 406 response if the client requests anything other than unicode (specifically, UTF-8, for application/json).
I was not very familiar with these formats when I wrote this stuff, and thus treated them as text formats.

Comment on lines 51 to +52
String[] bodyLines = response.body().split("\n");
assertTrue(bodyLines[1].startsWith("openapi:"));
assertTrue("Document does not contain \"openapi:\" field", Arrays.stream(bodyLines).anyMatch(line -> line.startsWith("openapi:")));
Copy link
Contributor

@pferraro pferraro Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better, but still more fragile than necessary, as it assumes no root indentation. Why not just parse the content into a YAML model and use that for any test assertions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scope of the test is to verify presence of non-dummy /openapi endopoint, i.e. to help a user quickly realize the mistake of using a server profile with absent openapi subsystem, so as such does not attempt to do anything more. Moreover, these tests are asking users to run in isolation, so there is no root indentation at play. Nevertheless, it would not hurt to demostrate this while making this less fragile in the process. We could fix this for 39 Final. 👍🏼

Copy link
Contributor

@pferraro pferraro Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, these tests are asking users to run in isolation, so there is no root indentation at play.

That is controlled by the implementation - so, still a superfluous test assumption (but also not a big deal).

Copy link
Member Author

@rhusar rhusar Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pferraro Can you open a Jira please? Feel free to assign to me to fix this since I caused it!

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

Successfully merging this pull request may close these issues.

3 participants