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

Messages elements are not generated #1574

Open
Tenischev opened this issue Oct 18, 2023 · 5 comments
Open

Messages elements are not generated #1574

Tenischev opened this issue Oct 18, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@Tenischev
Copy link
Member

Describe the bug

Modelina generates only components.schemas elements, the components.messages elements are not generated.
Issue found during exploration of possibility to use Modelina for model generation in Java spring template, see #asyncapi/java-spring-template/pull/342
Issue is valid for both JavaFileGenerator and JavaGenerator generators.

How to Reproduce

  1. Use following API
  2. Generate model files as:
const modelina = require('@asyncapi/modelina')
const path = require("path");

module.exports = {
    'generate:before': generator => {
        const javaGenerator = new modelina.JavaFileGenerator();

        javaGenerator.generateToFiles(generator.asyncapi, path.resolve(generator.targetDir, 'src/main/java/com/asyncapi/modelina/'), {
            collectionType: "List",
            presets: [
                {
                    preset: modelina.JAVA_COMMON_PRESET,
                    options: {
                        equal: true,
                        hashCode: true,
                        classToString: true
                    }
                }
            ]
        }, true)
    }
};
  1. In target folder only three files could be found - LightMeasuredPayload, TurnOnOffPayload, AnonymousSchema_2 which are corresponds to components.schemas elements and Enum element, the lightMeasured and turnOnOff from components.messages are not generated.

Expected behavior

lightMeasured and turnOnOff from components.messages are generated by generateToFiles or generate function of JavaFileGenerator and JavaGenerator.

@Tenischev Tenischev added the bug Something isn't working label Oct 18, 2023
@github-actions
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.

@Tenischev
Copy link
Member Author

@magicmatatjahu @jonaslagoni @kennethaasan ask for comments

@jonaslagoni
Copy link
Sponsor Member

@Tenischev yep Modelina only generate payloads right now.

What would you like the class for the message object to contain? Can you give an expected input with expected output?

@Tenischev
Copy link
Member Author

@jonaslagoni Message Object contain a lot of information. First of all it's payload which should be a ref to Schema object already generated by Modelina.
Then it's contentType constant which should be used to correct serialization-deserialization object.
Also it's headers which is an object, implementation could vary here from map to dedicated object.
The title, summary and description could be used in a comment.
Finally bindings which are protocol specific.
Example input:

    turnOnOff:
      name: turnOnOff
      title: Turn on/off
      summary: Command a particular streetlight to turn the lights on or off.
      schemaFormat: application/json
      headers:
        type: object
        properties:
          correlationId:
            description: Correlation ID set by application
            type: string
          applicationInstanceId:
            description: Unique identifier for a given instance of the publishing application
            type: string
      payload:
        $ref: "#/components/schemas/turnOnOffPayload"

Example Java out with Map for headers:

/**
 * Turn on/off
 * Command a particular streetlight to turn the lights on or off
 */
public class TurnOnOff {
  public static final String SCHEMA_FORMAT = "application/json";
  private TurnOnOffPayload payload;
  private Map<String, String> headers;
  
  // getter, hashCode, equals, toString here
}

@bacebu4
Copy link

bacebu4 commented Feb 12, 2024

Having somewhat similar issue but with headers

Would be amazing if all schemas which are present in .components.schemas would be converted, not only ones from payloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants