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

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

Closed
sjaakd opened this issue Jul 10, 2021 · 12 comments
Labels
area/swagger-ui kind/question Further information is requested

Comments

@sjaakd
Copy link

sjaakd commented Jul 10, 2021

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

   @POST
    @Path( "/graph/startregistration" )
    @Consumes( MediaType.APPLICATION_XML )
    @Produces( { MediaType.APPLICATION_SVG_XML, MediaType.APPLICATION_JSON } )
    @Operation(
        operationId = "graph-startregistration",
        summary = "Grafische weergave van de put en haar materiële historie (start)registratieverzoek.",
        description = "Geeft een grafische weergave van de put en tijdlijn in het SVG formaat. Er wordt uitgegaan van een correct brondocument (XML correct, gevalideerd)."
            + " Voorbeelden zijn: inrichting van een put (GMW_Construction), inrichting van een put met historie (GMW_ConstructionWithHistory)."
    )
    @RequestBody( content = {
        @Content(
            mediaType = MediaType.APPLICATION_XML,

            examples = {
                @ExampleObject(
                    name = "registrationRequestType",
                    value = ExampleDocuments.REGISTRATION_REQUEST_EXAMPLE,
                    description = "Voorbeeld brondocument in IMBRO XML van de inrichting van de put (GMW_Construction)."
                ),
            }
        )
    } )
    @APIResponse(
        responseCode = "200",
        content = { @Content( mediaType = MediaType.APPLICATION_SVG_XML ) },
        description = "Succesvolle opvraag van de put." )
    @APIResponse(
        responseCode = "417",
        content = {
            @Content(
                mediaType = MediaType.APPLICATION_JSON,
                schema = @Schema( implementation = ConstraintViolationErrors.class ) ),
        },
        description = "Er bevinden zich XML schemafouten in het aangeboden XML document."
    )
    @APIResponse(
        responseCode = "Other",
        content = {
            @Content(
                mediaType = MediaType.APPLICATION_JSON,
                schema = @Schema( implementation = ServiceError.class ) )
        },
        description = "Er bevinden zich andere fouten die het onmogelijk maken een grafische weergave te maken. Biedt het document eerst ter validatie aan aan de validatie service."
    )
    Response drawRegistration(@NotNull String xml) throws JAXBException;

The example is just a String with the example document.

   public static final String REGISTRATION_REQUEST_EXAMPLE =
        "<ns:registrationRequest xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.broservices.nl/xsd/isgmw/1.1\" xmlns:ns1=\"http://www.broservices.nl/xsd/brocommon/3.0\" xmlns:ns2=\"http://www.broservices.nl/xsd/gmwcommon/1.1\" xmlns:ns3=\"http://www.opengis.net/gml/3.2\">\n"
            + "         <ns1:requestReference>CI-GMW_TestCase12-1</ns1:requestReference>\n"
            + "        <!--Optional:-->\n"
            + "         <ns1:deliveryAccountableParty>52766179</ns1:deliveryAccountableParty>\n"
            + "         <ns1:qualityRegime>IMBRO/A</ns1:qualityRegime>\n"
            + "         <ns:sourceDocument>\n"
            + "            <!--You have a CHOICE of the next 12 items at this level-->\n"
            + "            <ns:GMW_Construction>\n"
            + "               <ns:objectIdAccountableParty>B07F0076</ns:objectIdAccountableParty>\n"
            + "               <ns:deliveryContext codeSpace=\"urn:bro:gmw:DeliveryContext\">publiekeTaak</ns:deliveryContext>\n"
            + "               <ns:constructionStandard codeSpace=\"urn:bro:gmw:ConstructionStandard\">RWSgwmon</ns:constructionStandard>\n"
            + "               <ns:initialFunction codeSpace=\"urn:bro:gmw:InitialFunction\">stand</ns:initialFunction>\n"
            + "               <ns:numberOfMonitoringTubes>1</ns:numberOfMonitoringTubes>\n"
            + "               <ns:groundLevelStable>nee</ns:groundLevelStable>\n"
            + "               <ns:wellStability codeSpace=\"urn:bro:gmw:WellStability\">stabielNAP</ns:wellStability>\n"
            + "               <ns:nitgCode>B01B2345</ns:nitgCode>\n"
            + "               <ns:owner>27376655</ns:owner>\n"
            + "               <ns:maintenanceResponsibleParty>27376655</ns:maintenanceResponsibleParty>\n"
            + "               <ns:wellHeadProtector codeSpace=\"urn:bro:gmw:WellHeadProtector\">geen</ns:wellHeadProtector>\n"
            + "               <ns:wellConstructionDate>\n"
            + "                  <ns1:date>2015-01-01</ns1:date>\n"
            + "               </ns:wellConstructionDate>\n"
            + "               <ns:deliveredLocation>\n"
            + "                  <ns2:location ns3:id=\"id-dad78bf5-3f4a-4286-8819-ebed615836e7\" srsName=\"urn:ogc:def:crs:EPSG::28992\">\n"
            + "                     <ns3:pos>134750.0 477800.0</ns3:pos>\n"
            + "                  </ns2:location>\n"
            + "                  <ns2:horizontalPositioningMethod codeSpace=\"urn:bro:gmw:HorizontalPositioningMethod\">RTKGPS10tot50cm</ns2:horizontalPositioningMethod>\n"
            + "               </ns:deliveredLocation>\n"
            + "               <ns:deliveredVerticalPosition>\n"
            + "                  <ns2:localVerticalReferencePoint codeSpace=\"urn:bro:gmw:LocalVerticalReferencePoint\">NAP</ns2:localVerticalReferencePoint>\n"
            + "                  <ns2:offset uom=\"m\">0.000</ns2:offset>\n"
            + "                  <ns2:verticalDatum codeSpace=\"urn:bro:gmw:VerticalDatum\">NAP</ns2:verticalDatum>\n"
            + "                  <ns2:groundLevelPosition uom=\"m\">3.18</ns2:groundLevelPosition>\n"
            + "                  <ns2:groundLevelPositioningMethod codeSpace=\"urn:bro:gmw:GroundLevelPositioningMethod\">RTKGPS20tot100cm</ns2:groundLevelPositioningMethod>\n"
            + "               </ns:deliveredVerticalPosition>\n"
            + "               <ns:monitoringTube>\n"
            + "                  <ns:tubeNumber>1</ns:tubeNumber>\n"
            + "                  <ns:tubeType codeSpace=\"urn:bro:gmw:TubeType\">standaardbuis</ns:tubeType>\n"
            + "                  <ns:artesianWellCapPresent>nee</ns:artesianWellCapPresent>\n"
            + "                  <ns:sedimentSumpPresent>ja</ns:sedimentSumpPresent>\n"
            + "                  <ns:numberOfGeoOhmCables>1</ns:numberOfGeoOhmCables>\n"
            + "                  <ns:tubeTopDiameter uom=\"mm\">32</ns:tubeTopDiameter>\n"
            + "                  <ns:variableDiameter>nee</ns:variableDiameter>\n"
            + "                  <ns:tubeStatus codeSpace=\"urn:bro:gmw:TubeStatus\">gebruiksklaar</ns:tubeStatus>\n"
            + "                  <ns:tubeTopPosition uom=\"m\">3.420</ns:tubeTopPosition>\n"
            + "                  <ns:tubeTopPositioningMethod codeSpace=\"urn:bro:gmw:TubeTopPositioningMethod\">afgeleidSbl</ns:tubeTopPositioningMethod>\n"
            + "                  <ns:materialUsed>\n"
            + "                     <ns2:tubePackingMaterial codeSpace=\"urn:bro:gmw:TubePackingMaterial\">bentoniet</ns2:tubePackingMaterial>\n"
            + "                     <ns2:tubeMaterial codeSpace=\"urn:bro:gmw:TubeMaterial\">peHighDensity</ns2:tubeMaterial>\n"
            + "                     <ns2:glue codeSpace=\"urn:bro:gmw:Glue\">geen</ns2:glue>\n"
            + "                  </ns:materialUsed>\n"
            + "                  <ns:screen>\n"
            + "                     <ns:screenLength uom=\"m\">1.000</ns:screenLength>\n"
            + "                     <ns:sockMaterial codeSpace=\"urn:bro:gmw:SockMaterial\">geen</ns:sockMaterial>\n"
            + "                  </ns:screen>\n"
            + "                  <ns:plainTubePart>\n"
            + "                     <ns2:plainTubePartLength uom=\"m\">6.640</ns2:plainTubePartLength>\n"
            + "                  </ns:plainTubePart>\n"
            + "                  <ns:sedimentSump>\n"
            + "                     <ns2:sedimentSumpLength uom=\"m\">0.500</ns2:sedimentSumpLength>\n"
            + "                  </ns:sedimentSump>\n"
            + "                  <ns:geoOhmCable>\n"
            + "                     <ns:cableNumber>1</ns:cableNumber>\n"
            + "                     <ns:electrode>\n"
            + "                        <ns2:electrodeNumber>1</ns2:electrodeNumber>\n"
            + "                        <ns2:electrodePackingMaterial codeSpace=\"urn:bro:gmw:ElectrodePackingMaterial\">zand</ns2:electrodePackingMaterial>\n"
            + "                        <ns2:electrodeStatus codeSpace=\"urn:bro:gmw:ElectrodeStatus\">gebruiksklaar</ns2:electrodeStatus>\n"
            + "                        <ns2:electrodePosition uom=\"m\">-3.98</ns2:electrodePosition>\n"
            + "                     </ns:electrode>\n"
            + "                     <ns:electrode>\n"
            + "                        <ns2:electrodeNumber>2</ns2:electrodeNumber>\n"
            + "                        <ns2:electrodePackingMaterial codeSpace=\"urn:bro:gmw:ElectrodePackingMaterial\">zand</ns2:electrodePackingMaterial>\n"
            + "                        <ns2:electrodeStatus codeSpace=\"urn:bro:gmw:ElectrodeStatus\">gebruiksklaar</ns2:electrodeStatus>\n"
            + "                        <ns2:electrodePosition uom=\"m\">-5.98</ns2:electrodePosition>\n"
            + "                     </ns:electrode>\n"
            + "                  </ns:geoOhmCable>\n"
            + "               </ns:monitoringTube>\n"
            + "            </ns:GMW_Construction>\n"
            + "         </ns:sourceDocument>\n"
            + "      </ns:registrationRequest>";

Screenshots

image

Reproducer

https://github.com/sjaakd/reproducer

@sjaakd sjaakd added the kind/bug Something isn't working label Jul 10, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 10, 2021

/cc @MikeEdgar, @phillip-kruger

@MikeEdgar
Copy link
Contributor

@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.

@sjaakd
Copy link
Author

sjaakd commented Jul 10, 2021 via email

@sjaakd
Copy link
Author

sjaakd commented Jul 10, 2021

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:

image

However, when I change the '[Modified Value]' back to the provided example 'registrationRequest' the problem in 1.12.1 occurs again:

image

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.

@sjaakd
Copy link
Author

sjaakd commented Jul 11, 2021

Added reproducer

comment / uncomment the properties in the pom.xml to demonstrate

        <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>-->

@sjaakd
Copy link
Author

sjaakd commented Jul 13, 2021

@MikeEdgar do you need additional information?

@MikeEdgar
Copy link
Contributor

@sjaakd - no questions, I just haven't had a chance to look back at this.

@gsmet
Copy link
Member

gsmet commented Jul 22, 2021

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 xml part with annotations. @phillip-kruger am I missing something?

@phillip-kruger
Copy link
Member

Hi @gsmet - I actually have no idea :) I can do some investigation at some point. Maybe @MikeEdgar knows ?

@MikeEdgar
Copy link
Contributor

You might try something like below. Note the dummy class to place an @XmlRootElement and the addition of the schema property to @Content. It's not ENTIRELY annotations since the dummy class is there...

    @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)."
                ),
            }
        )
    } )

@gsmet
Copy link
Member

gsmet commented Jul 23, 2021

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 {
+    }
 }

@gsmet gsmet closed this as completed Jul 23, 2021
@gsmet gsmet added kind/question Further information is requested and removed kind/bug Something isn't working labels Jul 23, 2021
@sjaakd
Copy link
Author

sjaakd commented Jul 25, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/swagger-ui kind/question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants