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
322 stars 184 forks source link

Add helper functions to un/marshal data models for JS #490

Closed jonaslagoni closed 2 years ago

jonaslagoni commented 3 years ago

Reason/Context

We need some helper functions to be able to marshal the data model instances to JSON and unmarshal JSON to instances of the data model.

Description

The reason we need to write this our self is that we add properties to data models which are technically not properties directly, an example here is additionalProperties, as it is rendered as a property in the data model, but when you want to convert an instance of the data model to bytes or JSON for a payload, it should not be used as is but unwrapped.

Samridhi-98 commented 2 years ago

@jonaslagoni I would like to work on this issue.

jonaslagoni commented 2 years ago

@Samridhi-98 feel free to ping me if you need starting points 👍

Samridhi-98 commented 2 years ago

@Samridhi-98 feel free to ping me if you need starting points 👍

export interface TypeScriptCommonPresetOptions {
  marshalling: boolean;
  example: boolean;
}

Like typescript, do I need to add an interface or class for JS?

I have implemented the part un/marshaling for JS and I ran the npm run test, it passed all test suits. Let me know if I need some other command to test the implementation?

jonaslagoni commented 2 years ago

Hey @Samridhi-98 do you mind adding a draft PR? 🙂 That way it is easier to see what has been done.

However, a test such as this one would be necessary: https://github.com/asyncapi/modelina/blob/5622923731bab2f45c4ede416761227bd4557ce3/test/generators/typescript/preset/MarshallingPreset.spec.ts#L27

Samridhi-98 commented 2 years ago

Yeah, sure I will draft a PR.

asyncapi-bot commented 2 years ago

:tada: This issue has been resolved in version 0.45.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

asyncapi-bot commented 2 years ago

:tada: This issue has been resolved in version 1.0.0-next.23 :tada:

The release is available on:

Your semantic-release bot :package::rocket: