зеркало из
1
0
Форкнуть 0

Promote `x-ms-text` extension to `xml`'s `text` property

This commit is contained in:
David Wilson 2020-07-29 12:12:52 -07:00
Родитель 01f8e9cf2f
Коммит 52f8498b7f
2 изменённых файлов: 52 добавлений и 1 удалений

Просмотреть файл

@ -21,7 +21,8 @@ const removeKnownParameters = [
'x-ms-original',
'x-ms-requestBody-name',
'x-ms-requestBody-index',
'x-ms-api-version'
'x-ms-api-version',
'x-ms-text'
];
// ref: https://www.w3schools.com/charsets/ref_html_ascii.asp
@ -193,9 +194,14 @@ export class Interpretations {
getXmlSerialization(schema: OpenAPI.Schema): XmlSerlializationFormat | undefined {
if (schema.xml) {
if (schema.xml['x-ms-text'] && schema.xml.attribute) {
throw new Error(`XML serialization for a schema cannot be in both 'text' and 'attribute'`);
}
return {
attribute: schema.xml.attribute || false,
wrapped: schema.xml.wrapped || false,
text: schema.xml['x-ms-text'] || false,
name: schema.xml.name || undefined,
namespace: schema.xml.namespace || undefined,
prefix: schema.xml.prefix || undefined,

Просмотреть файл

@ -653,4 +653,49 @@ class Modeler {
"Header with no client name"
);
}
@test
async "x-ms-text extension in xml object will be moved to 'text' property"() {
const spec = createTestSpec();
addSchema(spec, "HasOnlyText", {
type: "object",
properties: {
message: {
type: "string",
xml: {
"x-ms-text": true
}
}
}
});
const codeModel = await runModeler(spec);
assertSchema(
"HasOnlyText",
codeModel.schemas.objects,
o => o.properties[0].schema.serialization.xml.text,
true
);
addSchema(spec, "HasTextAndAttribute", {
type: "object",
properties: {
message: {
type: "string",
xml: {
"x-ms-text": true,
attribute: true
}
}
}
});
// Should throw when both 'text' and 'attribute' are true
await assert.rejects(
() => runModeler(spec),
/XML serialization for a schema cannot be in both 'text' and 'attribute'$/
);
}
}