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

CSharp generator does not generate DateTime properties #1607

Closed
jano-petras opened this issue Nov 14, 2023 · 6 comments
Closed

CSharp generator does not generate DateTime properties #1607

jano-petras opened this issue Nov 14, 2023 · 6 comments
Labels
area/typescript Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. bug Something isn't working good first issue Good for newcomers released on @next

Comments

@jano-petras
Copy link
Contributor

Describe the bug

CSharp code generation is not respecting 'format' hints when generating C# code, specifically date-time format. On the other hand, java generation does.

How to Reproduce

npm install @asyncapi/modelina
npm install @asyncapi/cli

Versions installed were:

  • @asyncapi/modelina@2.0.2
  • @asyncapi/cli@0.60.1

Yaml file with AsyncAPI:

asyncapi: 2.5.0
info:
  title: Streetlights API
  version: 1.0.0
  description: |
    The Smartylighting Streetlights API allows you
    to remotely manage the city lights.
  license:
    name: Apache 2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0'
channels:
  light/measured:
    publish:
      message:
        $ref: '#/components/messages/LightMeasuredMessage'
components:
  messages:
    LightMeasuredMessage:
      title: "LightMeasured"
      messageId: "LightMeasured"
      payload:
        $ref: '#/components/schemas/LightMeasured'    
  schemas:
    LightMeasured:
      additionalProperties: false
      type: object
      properties:
        id:
          type: integer
          minimum: 0
          description: Id of the streetlight.
        lumens:
          type: integer
          minimum: 0
          description: Light intensity measured in lumens.
        sentAt:
          type: string
          format: date-time
          description: Date and time when the message was sent.

Execute:
npx asyncapi generate models csharp ./sample1.yml --namespace=Test

Output:

## Model name: LightMeasured
namespace Test
{
  public class LightMeasured
  {
    private int? id;
    private int? lumens;
    private string? sentAt;

    public int? Id
    {
      get { return id; }
      set { id = value; }
    }

    public int? Lumens
    {
      get { return lumens; }
      set { lumens = value; }
    }

    public string? SentAt
    {
      get { return sentAt; }
      set { sentAt = value; }
    }
  }
}

Execute:
npx asyncapi generate models java ./sample1.yml --packageName=Test

Output:

public class LightMeasured {
  private Integer id;
  private Integer lumens;
  private java.time.OffsetDateTime sentAt;

  public Integer getId() { return this.id; }
  public void setId(Integer id) { this.id = id; }

  public Integer getLumens() { return this.lumens; }
  public void setLumens(Integer lumens) { this.lumens = lumens; }

  public java.time.OffsetDateTime getSentAt() { return this.sentAt; }
  public void setSentAt(java.time.OffsetDateTime sentAt) { this.sentAt = sentAt; }
}

Expected behavior

sentAt should be rendered with DateTime .net type, similar to how java renders OffsetDateTime

@jano-petras jano-petras added the bug Something isn't working label Nov 14, 2023
Copy link
Contributor

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@jonaslagoni
Copy link
Member

Hey @jano-petras, thanks for the issue!

Here is where the type is being determined for C#:

return getFullTypeDefinition('string', partOfProperty);

So we just have to do something similar as we do in Java:

switch (constrainedModel.options.format) {

Would be awesome if you would help contribute this ✌️

Make sure to base the changes on the next branch as this will be a breaking change 🙂

@jonaslagoni
Copy link
Member

/gfi typescript

@asyncapi-bot asyncapi-bot added area/typescript Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. good first issue Good for newcomers labels Nov 15, 2023
@jano-petras
Copy link
Contributor Author

Sounds all right, will see what I can come up with

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 3.0.0-next.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 4.0.0-next.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/typescript Specify what technical area given issue relates to. Its goal is to ease filtering good first issues. bug Something isn't working good first issue Good for newcomers released on @next
Projects
None yet
Development

No branches or pull requests

3 participants