-
Notifications
You must be signed in to change notification settings - Fork 214
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
Simple XML support #2970
Comments
I think this should be in a separeate |
also |
Agree we probably want @typespec/xml. I know that the proposal says "The scope of this proposal only covers the design and implementation of Xml support in OpenAPI, not any general Xml/XSD/WSDL support", but I think this is not what TypeSpec is about. We should look at this as general XML support, such that we can today emit everything we need into OpenAPI and drive codegen for clients consuming XML. We do not need to implement an XSD emitter but we should be able to convince ourselves that we can write that should the need arise. |
This is to cover the enhancement/gaps to the full compliance to OAS standards. I don't think this poposal conflict or overlap with a full @typespec/xml work item. That is another full scope of work entirely:
Again, this is to round up feature gaps for OAS, and lives under |
If the goal is to generate storage from do we know all the xml attributes that storage is using? if its just Could we also maybe then mark it as experimental(like projection log a warning) if we are unsure of where it is going? |
Does any current emitters take dependency on openapi? How does emitters do today to access any of the extension decorators (x-ms)? Does TCGC proxy it thru for language emitters? But this a good point.
|
So we could imaging the following as a first step
The prefix and namespace is what is much more confusing and we might have multiple ways of doing it. |
I am thinking to pivot to a new library @typespec/xml with namespace of |
I don't understand why we need that, yet. Do you think we can't achieve good interop with general purpose Xml annotations? |
Also have this dup issue if #1180 |
Xml Basic Support ProposalTo get basic support for xml we should get parity with OpenAPI
This means we need to have ways of specifying the following:
Attributes coverage1.
|
Scenario | TypeSpec | Xml | OpenAPI3 |
Scenario 1.1:
|
|
<XmlPet>
<tags>string</tags>
</XmlPet> |
Pet:
type: "object"
properties:
tags:
type: "array"
items:
type: string
xml:
name: "XmlPet" |
Scenario 1.2:
|
|
<XmlPet>
<ItemsTags>
<ItemsTags>string</ItemsTags>
</ItemsTags>
</XmlPet> |
Pet:
type: "object"
properties:
tags:
type: "array"
xml:
name: "ItemsTags"
wrapped: true
items:
type: string
xml:
name: "XmlPet" |
Scenario 1.3:
|
|
<XmlPet>
<ItemsName>string</ItemsName>
</XmlPet> |
Pet:
type: "object"
properties:
tags:
type: "array"
xml:
name: "ItemsTags"
items:
type: string
xml:
name: ItemsName
xml:
name: "XmlPet" |
Scenario 1.4:
|
|
<XmlPet>
<ItemsTags>
<ItemsName>string</ItemsName>
</ItemsTags>
</XmlPet> |
Pet:
type: "object"
properties:
tags:
type: "array"
xml:
name: "ItemsTags"
wrapped: true
items:
type: string
xml:
name: ItemsName
xml:
name: "XmlPet" |
2. Complex array types
Scenario | TypeSpec | Xml | OpenAPI3 |
Scenario 2.1:
|
|
<XmlPet>
<XmlTag>
<name>string</name>
</XmlTag>
</XmlPet> |
Tag:
type: "object"
properties:
name:
type: "string"
xml:
name: "XmlTag"
Pet:
type: "object"
properties:
tags:
type: "array"
items:
$ref: "#/definitions/Tag"
xml:
name: "XmlPet" |
Scenario 2.2:
|
|
<XmlPet>
<ItemsTags>
<XmlTag>
<name>string</name>
</XmlTag>
</ItemsTags>
</XmlPet> |
Tag:
type: "object"
properties:
name:
type: "string"
xml:
name: "XmlTag"
Pet:
type: "object"
properties:
tags:
type: "array"
xml:
name: "ItemsTags"
wrapped: true
items:
$ref: "#/definitions/Tag"
xml:
name: "XmlPet" |
Scenario 2.3:
|
|
<XmlPet>
<ItemsTag>
<name>string</name>
</ItemsTag>
</XmlPet> |
Tag:
type: "object"
properties:
name:
type: "string"
xml:
name: "XmlTag"
Pet:
type: "object"
properties:
tags:
type: "array"
xml:
name: "ItemsTags"
items:
$ref: "#/definitions/Tag"
xml:
name: ItemsXMLName
xml:
name: "XmlPet" |
Scenario 2.4:
|
|
<XmlPet>
<ItemsTags>
<XmlTag>
<name>string</name>
</XmlTag>
</ItemsTags>
</XmlPet> |
Tag:
type: "object"
properties:
name:
type: "string"
Pet:
type: "object"
properties:
tags:
type: "array"
xml:
name: "ItemsTags"
wrapped: true
items:
$ref: "#/definitions/Tag"
xml:
name: "XmlPet" |
3. Nested models
Scenario | TypeSpec | Xml | OpenAPI3 |
Scenario 3.1: No annotations |
|
<Book>
<author>
<name>string</name>
</author>
</Book> |
Book:
type: object
properties:
author:
$ref: "#/components/schemas/Author"
Author:
type: object
properties:
name:
type: string |
Scenario 3.2: Nested model has xml encoded name. |
|
<Book>
<author>
<name>string</name>
</author>
</Book> |
Book:
type: object
properties:
author:
allOf:
- $ref: "#/components/schemas/Author"
xml:
name: "author" # Here we have to redefine this name otherwise in OpenAPI semantic the `XmlAuthor` name would be used
Author:
type: object
properties:
name:
type: string
xml:
name: "XmlAuthor" |
Scenario 3.2: Property has encoded name |
|
<Book>
<xml-author>
<name>string</name>
</xml-author>
</Book> |
Book:
type: object
properties:
author:
allOf:
- $ref: "#/components/schemas/Author"
xml:
name: "xml-author"
Author:
type: object
properties:
name:
type: string |
4. Attributes
Scenario | TypeSpec | Xml | OpenAPI3 |
Scenario 4.1: Convert a property to an attribute |
|
<Book>
<id>0</id>
<xml-title>string</xml-title>
<author>string</author>
</Book> |
Book:
type: object
properties:
id:
type: integer
title:
type: string
xml:
name: "xml-title"
author:
type: string |
5. Namespace and prefix (inline form)
Scenario | TypeSpec | Xml | OpenAPI3 |
Scenario 5.1: On model |
|
<smp:Book xmlns:smp="http://example.com/schema">
<id>0</id>
<title>string</title>
<author>string</author>
</smp:Book> |
Book:
type: object
properties:
id:
type: integer
title:
type: string
author:
type: string
xml:
prefix: "smp"
namespace: "http://example.com/schema" |
Scenario 5.2: On model and properties |
|
<smp:Book xmlns:smp="http://example.com/schema" xmlns:sn2="http://example.com/ns2">
<id>0</id>
<smp:title>string</smp:title>
<ns2:author>string</ns2:author>
</smp:Book> |
Book:
type: object
properties:
id:
type: integer
title:
type: string
xml:
prefix: "smp"
namespace: "http://example.com/schema"
author:
type: string
xml:
prefix: "ns2"
namespace: "http://example.com/ns2"
xml:
prefix: "smp"
namespace: "http://example.com/schema" |
6. Namespace and prefix (normalized form)
Scenario | TypeSpec | Xml | OpenAPI3 |
Scenario 6.1: On model |
|
<smp:Book xmlns:smp="http://example.com/schema">
<id>0</id>
<title>string</title>
<author>string</author>
</smp:Book> |
Book:
type: object
properties:
id:
type: integer
title:
type: string
author:
type: string
xml:
prefix: "smp"
namespace: "http://example.com/schema" |
Scenario 6.2: On model and properties |
|
<smp:Book xmlns:smp="http://example.com/schema" xmlns:sn2="http://example.com/ns2">
<id>0</id>
<smp:title>string</smp:title>
<ns2:author>string</ns2:author>
</smp:Book> |
Book:
type: object
properties:
id:
type: integer
title:
type: string
xml:
prefix: "smp"
namespace: "http://example.com/schema"
author:
type: string
xml:
prefix: "ns2"
namespace: "http://example.com/ns2"
xml:
prefix: "smp"
namespace: "http://example.com/schema" |
^ on website with typespec highlighting https://tspwebsitepr.z22.web.core.windows.net/prs/2982/docs/next/release-notes/xml-support.html |
Thanks for updating to
An uber comment, I prefer a prefix |
For the prefix I do agree that if you use the |
I also don't support the built-in prefix. With the current design you can use the xml prefix (with or without using) or not use the xml prefix (with using), depending on personal preference. Seems best to me. |
Decision from design meeting
|
Xml Basic Support Design
To get basic support for xml we should get parity with OpenAPI
This means we need to have ways of specifying the following:
Attributes coverage
1.
name
Name is something we can already provide with
@encodedName("application/xml", "newname")
1.b Add
@Xml.name
decoratorAdd an
@Xml.name
decorator that would just call@encodedName("application/xml", "newname")
for you.It should not be saving any extra state. It should really just be a shorthand for
@encodedName("application/xml", "newname")
and in no way using@xml.name("newname")
achieve different functionality from@encodedName("application/xml", "newname")
.2.
attribute
Decorator would specify that this property should be serialized as an attribute instead.
Restrictions:
@attribute
can only be applied to model properties of scalar types3.
wrapped
andx-ms-text
Proposing that when dealing with arrays we always wrap them by default.
We are saying that there is always a node created for a property.
We then have a decorator
@unwrapped
that allows you to not wrap the property content.In the case of an array property this is equivalent to setting
wrapped: false
in OpenAPI.In the case of a scalar property this is equivalent to setting
x-ms-text: true
in OpenAPI with Autorest extensions.4.
namespace
andprefix
Define a new
namespace
decorator that can be used in two ways.You could also use an alias to reuse
4.a Do we need a decorator to annoate the enum?
Default encoding of scalars
As in Json we need to have some default handling of the common scalars like
utcDateTime
utcDateTime
xs:dateTime
TypeSpec.Xml.Encoding.xmlDateTime
offsetDateTime
xs:dateTime
TypeSpec.Xml.Encoding.xmlDateTime
plainDate
xs:date
TypeSpec.Xml.Encoding.xmlDate
plainTime
xs:time
TypeSpec.Xml.Encoding.xmlTim
duration
xs:duration
TypeSpec.Xml.Encoding.xmlDuration
bytes
xs:base64Binary
TypeSpec.Xml.Encoding.xmlBase64Binary
Changes to add
Create new
@typespec/xml
libraryNew decorators
Apis to Add
To figure out if it is better to have those as fully qualifed id to the enum member name or just return the enum member directly.
This most likely need a change in the compiler to
Examples
1. Array of primitive types
Scenario 1.1:
Scenario 1.2:
Scenario 1.3:
Scenario 1.4:
2. Complex array types
Scenario 2.1:
Scenario 2.2:
Scenario 2.3:
Scenario 2.4:
3. Nested models
Scenario 3.1:
No annotations
Scenario 3.2:
Nested model has xml encoded name.
Scenario 3.2:
Property has encoded name
4. Attributes
Scenario 4.1:
Convert a property to an attribute
5. Namespace and prefix (inline form)
Scenario 5.1:
On model
Scenario 5.2:
On model and properties
6. Namespace and prefix (normalized form)
Scenario 6.1:
On model
Scenario 6.2:
On model and properties
6. Property setting the text of the node
Scenario 6.1:
The text was updated successfully, but these errors were encountered: