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

[Bug]: bytes data type isn't recognized properly #5704

Open
4 tasks done
AnReZa opened this issue Jan 22, 2025 · 2 comments
Open
4 tasks done

[Bug]: bytes data type isn't recognized properly #5704

AnReZa opened this issue Jan 22, 2025 · 2 comments
Assignees
Labels
bug Something isn't working needs-area needs-info Mark an issue that needs reply from the author or it will be closed automatically

Comments

@AnReZa
Copy link

AnReZa commented Jan 22, 2025

Describe the bug

We're using TypeSpec to auto-generate c# classes. However, there is a problem with the auto-generated .Equals method. In the default .mustache file of the openapi generator, there's a check for #isContainer which determins, if a regular == comparison or .SequenceEqual should be used:

/// <summary>
/// Returns true if {{classname}} instances are equal
/// </summary>
/// <param name="other">Instance of {{classname}} to be compared</param>
/// <returns>Boolean</returns>
public bool Equals({{classname}}? other)
{
    if (other is null) return false;
    if (ReferenceEquals(this, other)) return true;

    return {{#vars}}{{^isContainer}}
        (
            {{name}} == other.{{name}} ||
            {{^vendorExtensions.x-is-value-type}}{{name}} != null &&{{/vendorExtensions.x-is-value-type}}
            {{name}}.Equals(other.{{name}})
        ){{^-last}} && {{/-last}}{{/isContainer}}{{#isContainer}}
        (
            {{name}} == other.{{name}} ||
            {{^vendorExtensions.x-is-value-type}}{{name}} != null &&
            other.{{name}} != null &&
            {{/vendorExtensions.x-is-value-type}}{{name}}.SequenceEqual(other.{{name}})
        ){{^-last}} && {{/-last}}{{/isContainer}}{{/vars}}{{^vars}}false{{/vars}};
}

However, contrary to my expectation for the bytes data type, it doesn't use the SequenceEqual comparison, but the regular == one, which doesn't work for byte arrays in c#. Why is that?

bytes gets converted into a type: string, format: byte data type, which seems odd to me. Is that right?

Right now, it correctly generates a property of type byte[] in c#, but the equals method doesn't work, as it uses .Equals instead of the correct SequenceEqual.

Reproduction

model Test {
  test: bytes
}
openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths: {}
components:
  schemas:
    Test:
      type: object
      required:
        - test
      properties:
        test:
          type: string
          format: byte

Checklist

@AnReZa AnReZa added the bug Something isn't working label Jan 22, 2025
@markcowl markcowl self-assigned this Jan 22, 2025
@markcowl markcowl added the needs-info Mark an issue that needs reply from the author or it will be closed automatically label Jan 22, 2025
@markcowl
Copy link
Contributor

@AnReZa Is this about the c-sharp client generator, or something else?

@markcowl markcowl removed their assignment Jan 22, 2025
@AnReZa
Copy link
Author

AnReZa commented Jan 24, 2025

@markcowl Yes and no. I can't tell, if it is an issue of the conversion step between TypeSpec and OpenAPI, or between OpenAPI and c#.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-area needs-info Mark an issue that needs reply from the author or it will be closed automatically
Projects
None yet
Development

No branches or pull requests

2 participants