Repository: asyncapi/modelina (ts)

Issue:
AsyncAPIInputProcessor incorrectly stores encountered schemas
#### Describe the bug
When you have a schema that references some other schema more than once `AsyncAPIInputProcessor` fails to correctly convert all but the first property.

#### How to Reproduce
Create AsyncAPI spec with simple schemas:
```yaml
components:
  schemas:
    RootSchema:
      type: object
      properties:
        firstRef:
          $ref: '#/components/schemas/ReferencedSchema'
        secondRef:
          $ref: '#/components/schemas/ReferencedSchema'
    ReferencedSchema:
      type: object
      properties:
        str:
          type: string
```
For simplicity, I'll show the result from JavaGenerator. The resulting java classes contain these properties:
```java
  private ReferencedSchema firstRef;
  private Object secondRef;
  private Map<String, Object> additionalProperties;
```

#### Expected behavior
The correct result would be:
```java
  private ReferencedSchema firstRef;
  private ReferencedSchema secondRef;
  private Map<String, Object> additionalProperties;
```

In the background what is happening is that during processing the schema for `secondRef` is set to `{}` (actually it's `new AsyncapiV2Schema()`).

#### Cause
The issue comes from these lines:
https://github.com/asyncapi/modelina/blob/4ab00523213ae5b01992270cbd05ccc3d0c6ebd6/src/processors/AsyncAPIInputProcessor.ts#L58-L61

As the first thing, we store empty schema object which we want to hydrate in the rest of the method. The issue is that right after we store the object in the `alreadyIteratedSchemas`, we discard it and instead copy json properties to a fresh new object. This means that in the first iteration we get correctly converted schema but all other method calls are simply returning the existing schema which in our case stays empty.

The fix is easy as we only need to change:
```typescript
    convertedSchema = Object.assign({}, schema.json());
```
to
```typescript
    convertedSchema = Object.assign(convertedSchema, schema.json());
```

Without this fix, I'm not able to use modelina. I can provide the PR with a simple test case later on.

Pull request:
fix: correctly store already converted schemas while parsing AsyncApi schema (#548)
**Description**
Simple change - correctly save converted schemas in `alreadyIteratedSchemas`

**Related issue(s)**
Fixes #548 

Patch:
diff --git a/src/processors/AsyncAPIInputProcessor.ts b/src/processors/AsyncAPIInputProcessor.ts
index 00bb813c..78eabd7e 100644
--- a/src/processors/AsyncAPIInputProcessor.ts
+++ b/src/processors/AsyncAPIInputProcessor.ts
@@ -55,10 +55,10 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
     if (alreadyIteratedSchemas.has(schemaUid)) {
       return alreadyIteratedSchemas.get(schemaUid) as AsyncapiV2Schema; 
     }
-    let convertedSchema = new AsyncapiV2Schema();
-    alreadyIteratedSchemas.set(schemaUid, convertedSchema);
-    convertedSchema = Object.assign({}, schema.json());
+
+    const convertedSchema = Object.assign(new AsyncapiV2Schema(), schema.json());
     convertedSchema[this.MODELGEN_INFFERED_NAME] = schemaUid;
+    alreadyIteratedSchemas.set(schemaUid, convertedSchema);
 
     if (schema.allOf() !== null) {
       convertedSchema.allOf = schema.allOf().map((item) => this.convertToInternalSchema(item, alreadyIteratedSchemas));


Test patch:
diff --git a/test/processors/AsyncAPIInputProcessor.spec.ts b/test/processors/AsyncAPIInputProcessor.spec.ts
index d9f4be26..f23001c2 100644
--- a/test/processors/AsyncAPIInputProcessor.spec.ts
+++ b/test/processors/AsyncAPIInputProcessor.spec.ts
@@ -130,5 +130,14 @@ describe('AsyncAPIInputProcessor', () => {
       expect(expected.anyOf[1]['x-modelgen-inferred-name']).toEqual('<anonymous-schema-17>');
       expect(expected.anyOf[1].properties.prop['x-modelgen-inferred-name']).toEqual('<anonymous-schema-18>');
     });
+    test('should correctly convert when schema has more than one properties referencing one other schema', async () => {
+      const basicDocString = fs.readFileSync(path.resolve(__dirname, './AsyncAPIInputProcessor/schema_with_2_properties_referencing_one_schema.json'), 'utf8');
+      const doc = await parse(basicDocString, {} as ParserOptions);
+      const schema = doc.channels()['/user/signedup'].subscribe().message().payload();
+      const result = AsyncAPIInputProcessor.convertToInternalSchema(schema) as any;
+
+      expect(result.properties['lastName']).not.toEqual({});
+      expect(result.properties['firstName']).toEqual(result.properties['lastName']);
+    });
   });
 });
diff --git a/test/processors/AsyncAPIInputProcessor/schema_with_2_properties_referencing_one_schema.json b/test/processors/AsyncAPIInputProcessor/schema_with_2_properties_referencing_one_schema.json
new file mode 100644
index 00000000..00c565f0
--- /dev/null
+++ b/test/processors/AsyncAPIInputProcessor/schema_with_2_properties_referencing_one_schema.json
@@ -0,0 +1,49 @@
+{
+  "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": {
+            "firstName": {
+              "$ref": "#/components/schemas/PersonName"
+            },
+            "lastName": {
+              "$ref": "#/components/schemas/PersonName"
+            },
+            "email": {
+              "type": "string",
+              "format": "email",
+              "description": "Email of the user"
+            }
+          }
+        }
+      }
+    },
+    "schemas": {
+      "PersonName": {
+        "type": "object",
+        "properties": {
+          "value": {
+            "type": "string"
+          }
+        }
+      }
+    }
+  }
+}