Hi Shah,
There are a couple issues at play here. First, looking at your definition
definitions:
body:
type: object
properties:
id:
type: string
xml:
attribute: false
wrapped: true
title: id
xml:
attribute: false
wrapped: false
required:
- id
That is a definition named "body" but it does not specify a XML root element name, just the id attribute. I believe for XML you'll need in your xml property of the overall definition a name
property:
definitions:
body:
type: object
properties:
id:
type: string
xml:
attribute: false
title: id
xml:
attribute: false
name: yourrootelementname
required:
- id
which would define a definition named body that describes <yourrootelementname id="string"/>
. Also per the OAI2 specification https://swagger.io/specification/v2/, the xml wrapped property only applies to arrays. Although that isn't the cause of your empty schema I removed your wrapped xml properties too.
However, the real issue of why you're getting the "Schema property is empty" error is that the validate v2.0.0 and above for XML uses an actual xsd to do the validation which is assumed to be created when you created the API definition, whereas in v5 and v5 compatible gateways, that xsd was actually built at runtime using the API definition for each and every API request. The ability to create this xsd when creating the API is a known open UI issue that other customers have reported, but please feel free to open a PMR on this. Unfortunately, the workaround is a little ugly until the APIM UI issue gets resolved. In involves first creating an xsd for XML that would match your yaml definition, and that xsd must be base64 encoded and added as a property to the definition. There are online XML to XSD converters you can use. For example, if your root element name was really body
, the XML <body id="1"/>
will produce something like
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="body">
<xs:complexType>
<xs:attribute name="id" type="xs:unsignedByte" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
You would base64 encode that XML string and place it into your API definition using the x-ibm-schema property as follows:
definitions:
body:
type: object
properties:
id:
type: string
xml:
attribute: false
title: id
xml:
attribute: false
name: yourrootelementname
required:
- id
x-ibm-schema:
type: xsd
file: <base64 encoded text for the xsd file string>
Best Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
------------------------------
Original Message:
Sent: Mon October 09, 2023 06:51 AM
From: Shah Wajahat
Subject: xml validation
I want to validate xml request body through validate policy. i am created definition and validate against the defination. I give an error "Schema property is empty".
------------------------------
Shah Wajahat
------------------------------