Skip to content
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

Always serialize discriminator as the first property #4863

Closed
ahusseini opened this issue Jun 20, 2024 · 2 comments
Closed

Always serialize discriminator as the first property #4863

ahusseini opened this issue Jun 20, 2024 · 2 comments
Labels
generator Issues or improvements relater to generation capabilities. Needs: Attention 👋 type:feature New experience request

Comments

@ahusseini
Copy link

ahusseini commented Jun 20, 2024

Is your feature request related to a problem? Please describe the problem.

An unhandled exception has occurred while executing the request.
      Microsoft.AspNetCore.Http.BadHttpRequestException: Failed to read parameter "List<ResolveThingRequest> requests" from the request body as JSON.
       ---> System.Text.Json.JsonException: The metadata property is either not supported by the type or is not the first property in the deserialized JSON object. Path: $[0].$type | LineNumber: 0 | BytePositionInLine: 44.

related to:

CleanShot 2024-06-19 at 20 53 49@2x

ResolveThingRequest:
  type: object
  discriminator:
    propertyName: $type
    mapping:
      ResolveThingARequest: '#/components/schemas/ResolveThingARequest'
      ResolveThingBRequest: '#/components/schemas/ResolveThingBRequest'
  additionalProperties: false
  required:
  - $type
  properties:
    $type:
      type: string
    contextId:
      type: integer
      format: int32
    name:
      type: string
      nullable: true

Client library/SDK language

Csharp

Describe the solution you'd like

Kiota should not include the discriminator property when reordering alphabetically.

Additional context

Although this will be fixed in .net 9, this seems counter intuitive and breaking.

@ahusseini ahusseini added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request labels Jun 20, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Jun 20, 2024
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code label Jun 20, 2024
@baywet baywet added generator Issues or improvements relater to generation capabilities. and removed Csharp Pull requests that update .net code status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jun 20, 2024
@baywet baywet moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Jun 20, 2024
@baywet baywet added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Jun 20, 2024
@baywet
Copy link
Member

baywet commented Jun 20, 2024

Hi @ahusseini
Thanks for using kiota and for reaching out.
This is something we're unlikely to do, or even accept.
As stated in #4680 the JSON spec explicitly calls out that objects with unordered properties. And you can see that in this issue, the requested order was different from this one here.
Digging into the discriminator issue from STJ, it seems this is something they've fixed for .NET 9. And if the higher compatibility/preview state is a blocker for you, there are multiple workarounds from the community on the thread.

@ahusseini
Copy link
Author

Hey @baywet, that's understandable, although a bit strange to take this position when:

  • Kiota is generating incompatible client code for standard .net servers, and anyone who is not able to upgrade to .net 9 is stuck with a workaround
  • System.Text.Json and JSON.Net both provide property order attributes which are written out to the OpenAPI spec
  • although you say the JSON spec says there should be no defined order, you are choosing a defined order by reordering things alphabetically

IMO this is unneeded friction, I just want to generate compliant code for minimal APIs. I've worked around this by creating an empty base class for all objects, so that $type is the first and only property. Anyways, I don't want to rehash the reordering thread so I'll close this.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jun 20, 2024
@ahusseini ahusseini closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2024
@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities. Needs: Attention 👋 type:feature New experience request
Projects
Archived in project
Development

No branches or pull requests

2 participants