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

[FEATURE] Change the name of the generated model class withe name of message name. #1996

Open
2 tasks done
AayushSaini101 opened this issue May 11, 2024 · 7 comments
Open
2 tasks done
Labels
enhancement New feature or request

Comments

@AayushSaini101
Copy link

Why do we need this improvement?

Asyncapi.yml:

asyncapi: '2.2.0'
info:
  title: Account Service
  version: 1.0.0
  description: This service is in charge of processing user signups
channels:
  user/signedup:
    subscribe:
      message:
        $ref: '#/components/messages/UserSignedUp'
components:
  messages:
    UserSignedUp:
      payload:
        type: object
        properties:
          displayName:
            type: string
            description: Name of the user
          email:
            type: string
            format: email
            description: Email of the user

Output:

asyncapi generate models java ./asyncapi.yml --packageName=src

Successfully generated the following models: 
## Model name: AnonymousSchema_1 // Name should be change to userSignedUp
package src;

import java.util.Map;
public class AnonymousSchema_1 {
  private String displayName;
  private String email;
  private Map<String, Object> additionalProperties;

  public String getDisplayName() { return this.displayName; }
  public void setDisplayName(String displayName) { this.displayName = displayName; }

  public String getEmail() { return this.email; }
  public void setEmail(String email) { this.email = email; }

  public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; }
  public void setAdditionalProperties(Map<String, Object> additionalProperties) { this.additionalProperties = additionalProperties; }
}

How will this change help?

This change will help to adhere proper naming of the project, lets suppose if we want to call the model class we need to call the AnonymousSchema_1 which seems to be not valid.

Screenshots

No response

How could it be implemented/designed?

  • Use the name of the message as the class name

🚧 Breaking changes

No

👀 Have you checked for similar open issues?

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue?

Yes I am willing to submit a PR!

@AayushSaini101 AayushSaini101 added the enhancement New feature or request label May 11, 2024
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

Makes sense, taget next @AayushSaini101 ✌️

@black-snow
Copy link

I just stumbled over this. I ran asyncapi generate models and end up with:

Successfully generated the following models: AnonymousSchema1, AnonymousSchema25, AnonymousSchema28, AnonymousSchema31, AnonymousSchema38, AnonymousSchema41, AnonymousSchema44

I would've expected that the file name as well as the class name do use the actual name of the component / message / whatevs. Is there currently no way or do I have to set some extra annotation somewhere?

@jonaslagoni
Copy link
Member

jonaslagoni commented Jul 24, 2024

Happy to accept and help guide a PR 🙂 Otherwise, yes, explicit annotations is the workaround

@black-snow
Copy link

What annotation would that be?

@black-snow
Copy link

This would be a breaking change, right?

Any idea where to start? I imagined this to be an easy change but grepping for anonymous yields only CommonModel and AsyncAPIInputProcessor apart from the tests / examples. It's not apparent to me where AnonymousSchema_N gets generated.

@jonaslagoni
Copy link
Member

What annotation would that be?

You would have to explicitly define the message payload as the name of the message.

This would be a breaking change, right?

Yes, just target the next branch 🙂 Unless you want to hide it behind an option.

Any idea where to start? I imagined this to be an easy change but grepping for anonymous yields only CommonModel and AsyncAPIInputProcessor apart from the tests / examples. It's not apparent to me where AnonymousSchema_N gets generated.

All this logic happens in the input processor for AsyncAPI:

if (messages.length > 1) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants