microsoft / microsoft/typespec

[Bug]: http-client-java, difference on serialization of XML with namespace

Open
#10,208 2 comments 0 reactions 0 assignees View on GitHub
bug emitter:client:java
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

### Describe the bug

test case https://github.com/microsoft/typespec/blob/main/packages/http-client-java/generator/http-client-generator-clientcore-test/src/test/java/payload/xml/XmlTests.java#L310-L334

test scenario https://github.com/microsoft/typespec/blob/main/packages/http-specs/specs/payload/xml/main.tsp#L461-L504

Java SDK serialize XML as e.g.
```xml

123
The Great Gatsby
F. Scott Fitzgerald

```

Validation is
```xml

123
The Great Gatsby
F. Scott Fitzgerald

```

The most disagreement is on the `id` property.

In Java serialization, `id` is in "http://example.com/schema" namespace.

While in test scenario, `id` is in null namespace.

---

code-model.yaml contains the info

```yaml
- &ref_86
language:
default:
name: ModelWithNamespaceOnProperties
description: >-
§6.2, §7.2 — Contains fields with different XML namespaces on
individual properties.
namespace: Payload.Xml
crossLanguageDefinitionId: Payload.Xml.ModelWithNamespaceOnProperties
java:
namespace: payload.xml
protocol: {}
type: object
properties:
- language:
default:
name: id
description: ''
protocol: {}
schema: *ref_3
serializedName: id
required: true
nullable: false
readOnly: false
serialization:
xml:
name: id
attribute: false
wrapped: false
text: false
- language:
default:
name: title
description: ''
protocol: {}
schema: *ref_0
serializedName: title
required: true
nullable: false
readOnly: false
serialization:
xml:
name: title
namespace: http://example.com/schema
prefix: smp
attribute: false
wrapped: false
text: false
- language:
default:
name: author
description: ''
protocol: {}
schema: *ref_0
serializedName: author
required: true
nullable: false
readOnly: false
serialization:
xml:
name: author
namespace: http://example.com/ns2
prefix: ns2
attribute: false
wrapped: false
text: false
serialization:
xml:
name: ModelWithNamespaceOnProperties
namespace: http://example.com/schema
prefix: smp
attribute: false
wrapped: false
text: false
usage:
- output
- public
- input
```

### Reproduction

Start the spector in "/packages/http-client-java/generator/http-client-generator-clientcore-test"
1. Setup.ps1
2. npm run spector-serve

Run the test

### Checklist

- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.