asyncapi / modelina

A library for generating typed models based on inputs such as AsyncAPI, OpenAPI, and JSON Schema documents with high customization
https://modelina.org
Apache License 2.0
295 stars 170 forks source link

Messages elements are not generated #1574

Open Tenischev opened 10 months ago

Tenischev commented 10 months ago

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)
}

};


3. 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`.
github-actions[bot] commented 10 months ago

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 commented 10 months ago

@magicmatatjahu @jonaslagoni @kennethaasan ask for comments

jonaslagoni commented 10 months ago

@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 commented 10 months ago

@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 commented 6 months ago

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

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

anton-brass commented 1 month ago

would be still nice that is is added, since header is an essential part of the message