-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
When Quarkus is updated from 1.10.5.final to 1.12.1.Final XML schema validation seems to be activated on the swagger examples. #18587
Comments
@sjaakd - does the response being returned by the openapi endpoint look correct? I'm trying to determine if it's a problem with the generator or the UI. |
The response looks ok.
It looks like only the example is not rendered correctly in the swagger
interface. In the previous version it was just rendered as plain text.
|
To be more complete: When copying the example from the 'live' version (based on 1.10.5.final) and copying it in the 'try it out' window in my (locally running) 1.12.1 version it works as expected. See the screenshot: However, when I change the '[Modified Value]' back to the provided example 'registrationRequest' the problem in 1.12.1 occurs again: When executing the service, the results are the same. So it is not present in the result parsing. It seems to be somewhere in rendering the example solely. |
Added reproducer comment / uncomment the <quarkus.platform.version>1.12.1.Final</quarkus.platform.version>
<quarkus-plugin.version>1.12.1.Final</quarkus-plugin.version>
<!-- <quarkus.platform.version>1.10.5.Final</quarkus.platform.version>-->
<!-- <quarkus-plugin.version>1.10.5.Final</quarkus-plugin.version>--> |
@MikeEdgar do you need additional information? |
@sjaakd - no questions, I just haven't had a chance to look back at this. |
Mkay, I had some fun debugging this one. AFAICS, it's an issue in Swagger UI, a ton of person are complaining here: swagger-api/swagger-ui#4650 . I was able to make it work by tweaking the OpenAPI document like so: paths:
/reproducer/reproduce:
post:
summary: Summary
description: The Description
operationId: example
requestBody:
content:
application/xml:
schema:
type: object
xml:
name: foobar
examples:
An XML:
description: XML
value: |-
<ns1:registrationRequest The important part is this section: schema:
type: object
xml:
name: foobar Problem is: AFAICS, there is no way to define the |
Hi @gsmet - I actually have no idea :) I can do some investigation at some point. Maybe @MikeEdgar knows ? |
You might try something like below. Note the dummy class to place an @XmlRootElement(name = "registrationRequest")
static class BroServicesRegistrationRequest {
}
...
@RequestBody( content = {
@Content(
mediaType = MediaType.APPLICATION_XML,
schema = @Schema(implementation = BroServicesRegistrationRequest.class)
examples = {
@ExampleObject(
name = "registrationRequestType",
value = ExampleDocuments.REGISTRATION_REQUEST_EXAMPLE,
description = "Voorbeeld brondocument in IMBRO XML van de inrichting van de put (GMW_Construction)."
),
}
)
} ) |
Ah thanks @MikeEdgar . I can confirm the following diff fixes the issue: diff --git a/src/main/java/nl/reproducer/resources/RestResource.java b/src/main/java/nl/reproducer/resources/RestResource.java
index ed21371..7f183ed 100644
--- a/src/main/java/nl/reproducer/resources/RestResource.java
+++ b/src/main/java/nl/reproducer/resources/RestResource.java
@@ -6,6 +6,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.media.Content;
@@ -29,6 +30,7 @@
@RequestBody(
content = @Content(
mediaType = MediaType.APPLICATION_XML,
+ schema = @Schema(implementation = FooBar.class),
examples = {
@ExampleObject(
name = "An XML",
@@ -47,4 +49,8 @@
description = "The result."
)
Response register(String xml);
+
+ @XmlRootElement(name = "foobar")
+ static class FooBar {
+ }
} |
Thanks. I'll try the dummy class. I even think I have one at hand to do XML schema validation. But still strange that Swagger suddenly starts to validate requests / examples. It should be a user choice though. The examples (after all) are under my own control. One of the scenarios could even be deliberately specifying an example with wrong XML on order for the service to detect this to demonstrate (custom) XML validation works. |
Describe the bug
When Quarkus is updated from 1.10.5.final to 1.12.1.Final XML schema validation seems to be activated on the swagger examples.
Expected behavior
No Validation on the examples. See also here.
Actual behavior
Swagger example refuses to show XML and try-it button does not work anymore.
To Reproduce
The example is just a
String
with the example document.Screenshots
Reproducer
https://github.com/sjaakd/reproducer
The text was updated successfully, but these errors were encountered: