Skip to content

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

@weidongxu-microsoft

Description

@weidongxu-microsoft

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.

<ModelWithNamespaceOnProperties xmlns="http://example.com/schema" xmlns:smp="http://example.com/schema" xmlns:ns2="http://example.com/ns2">
  <id>123</id>
  <title>The Great Gatsby</title>
  <ns2:author>F. Scott Fitzgerald</ns2:author>
</ModelWithNamespaceOnProperties>

Validation is

<smp:ModelWithNamespaceOnProperties xmlns:smp="http://example.com/schema" xmlns:ns2="http://example.com/ns2">
  <id>123</id>
  <smp:title>The Great Gatsby</smp:title>
  <ns2:author>F. Scott Fitzgerald</ns2:author>
</smp:ModelWithNamespaceOnProperties>

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingemitter:client:javaIssue for the Java client emitter: @typespec/http-client-java

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions