Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Dec 27, 2023
2 parents cf0ee08 + ee34ae2 commit 6684c77
Show file tree
Hide file tree
Showing 40 changed files with 258 additions and 35 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Your one-stop tool for generating accurate and well-tested models for representi
- [Installing Modelina](#installing-modelina)
- [AsyncAPI CLI](#asyncapi-cli)
- [Features](#features)
- [Roadmap](#roadmap)
- [Requirements](#requirements)
- [Documentation](#documentation)
- [Examples](#examples)
Expand Down Expand Up @@ -266,13 +265,12 @@ The following table provides a short summary of available features for supported
<td><a href="./docs/usage.md#generate-php-models">PHP</a></td>
<td>Class and enum generation: <em>custom indentation type and size, descriptions, etc </em></td>
</tr>
<tr>
<td><a href="./docs/usage.md#generate-scala-models">Scala</a></td>
<td>Class and enum generation: <em>custom indentation type and size, descriptions, etc </em></td>
</tr>
</table>

## Roadmap
This is the roadmap that is currently in focus by the [CODEOWNERS](./CODEOWNERS)

- [1 year roadmap](https://github.com/asyncapi/modelina/milestone/4)

## Requirements
The following are a requirement in order to use Modelina.

Expand Down
2 changes: 1 addition & 1 deletion docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ There are at least two ways you can integrate Modelina into your build process f
- DO work with other inputs then AsyncAPI
- DO work when needing extensive build options and configurations

Checkout the Maven example here: [Integrate Modelina into Maven](../examples/integrate-modelina-into-maven)
Checkout the Maven example here: [Integrate Modelina into Maven](../examples/integrate-with-maven)

**AsyncAPI CLI**

Expand Down
2 changes: 1 addition & 1 deletion docs/languages/Java.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ Currently not supported, [let everyone know you need it](https://github.com/asyn
Currently not supported, [let everyone know you need it](https://github.com/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

## Integrate Modelina into Maven
We have created an example Maven project to show you how to generate AsyncAPI payload models from your AsyncAPI file and integrate it into the build process. [You can find the integration example here](../integration.md#integrate-modelina-into-maven).
We have created an example Maven project to show you how to generate AsyncAPI payload models from your AsyncAPI file and integrate it into the build process. [You can find the integration example here](../integration.md#integrate-with-maven).
36 changes: 36 additions & 0 deletions docs/languages/Scala.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Scala

There are special use-cases that each language supports; this document pertains to **Scala models**.

<!-- toc is generated with GitHub Actions do not remove toc markers -->

<!-- toc -->

- [Description Present](#description-present)
- [Generate serializer and deserializer functionality](#generate-serializer-and-deserializer-functionality)
* [To and from JSON](#to-and-from-json)
* [To and from XML](#to-and-from-xml)
* [To and from binary](#to-and-from-binary)

<!-- tocstop -->

## Description Present

By default, descriptions are not rendered for the model; you can change that by applying `SCALA_DESCRIPTION_PRESET`.

Check out this [example for a live demonstration](../../examples/php-generate-documentation-preset).

## Generate serializer and deserializer functionality

The most widely used usecase for Modelina is to generate models that include serilization and deserialization functionality to convert the models into payload data. This payload data can of course be many different kinds, JSON, XML, raw binary, you name it.

As you normally only need one library to do this, we developers can never get enough with creating new stuff, therefore there might be one specific library you need or want to integrate with. Therefore there is not one specific preset that offers everything. Below is a list of all the supported serialization presets.

### To and from JSON
Currently not supported, [let everyone know you need it](https://github.com/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

### To and from XML
Currently not supported, [let everyone know you need it](https://github.com/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!

### To and from binary
Currently not supported, [let everyone know you need it](https://github.com/asyncapi/modelina/issues/new?assignees=&labels=enhancement&template=enhancement.md)!
7 changes: 6 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ For more specific integration options, please check out the [integration documen
- [Generate Kotlin models](#generate-kotlin-models)
- [Generate C++ (cplusplus) models](#generate-c-cplusplus-models)
- [Generate PHP models](#generate-php-models)
- [Generate Scala models](#generate-scala-models)

<!-- tocstop -->

Expand Down Expand Up @@ -201,4 +202,8 @@ C++ is one of the many output languages we support. Check out this [basic exampl

## Generate PHP models

PHP is one of the many output languages we support. Check out this [basic example for a live demonstration](../examples/php-generate-models/) and the following [PHP documentation for more advanced use-cases](./languages/Php.md).
PHP is one of the many output languages we support. Check out this [basic example for a live demonstration](../examples/generate-php-models/) and the following [PHP documentation for more advanced use-cases](./languages/Php.md).

## Generate Scala models

Scala is one of the many output languages we support. Check out this [basic example for a live demonstration](../examples/generate-scala-models/) and the following [Scala documentation for more advanced use-cases](./languages/Scala.md).
81 changes: 64 additions & 17 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ We love contributions and new examples that does not already exist, you can foll
- [General examples](#general-examples)
- [Simple generator examples](#simple-generator-examples)
- [Integrations](#integrations)
- [Python](#python)
- [JavaScript](#javascript)
- [Java](#java)
- [C#](#c%23)
- [TypeScript](#typescript)
- [Kotlin](#kotlin)
- [PHP](#php)
- [Language examples](#language-examples)
* [Python](#python)
* [JavaScript](#javascript)
* [Java](#java)
* [C#](#c%23)
* [TypeScript](#typescript)
* [Kotlin](#kotlin)
* [PHP](#php)
* [Scala](#scala)
* [Rust](#rust)
* [Dart](#dart)
* [Go](#go)
* [C++](#c)
- [Other examples](#other-examples)

<!-- tocstop -->
Expand Down Expand Up @@ -65,27 +71,37 @@ These are all the basic generator examples that shows a bare minimal example of
- [generate-javascript-models](./generate-javascript-models) - A basic example to generate JavaScript data models
- [generate-kotlin-models](./generate-kotlin-models) - A basic example to generate Kotlin data models
- [generate-cplusplus-models](./generate-cplusplus-models) - A basic example to generate C++ data models
- [generate-php-models](./generate-cplusplus-models) - A basic example to generate PHP data models
- [generate-scala-models](./generate-cplusplus-models) - A basic example to generate Scala data models

## Integrations
These are examples of how you can integrate Modelina into a specific scenario:
- [integrate-with-react](./integrate-with-react) - A basic example that shows how you can integrate Modelina with React.
- [integrate-with-next](./integrate-with-next) - A basic example that shows how you can integrate Modelina with Next.
- [integrate-modelina-into-maven](./integrate-modelina-into-maven) - A basic example that shows how you can integrate Modelina into the Java Maven build process.
- [integrate-with-maven](./integrate-with-maven) - A basic example that shows how you can integrate Modelina into the Java Maven build process.

## Python
## Language examples
These are all the examples for each language;

### Python
These are all specific examples only relevant to the Python generator:
- [generate-python-models](./generate-python-models) - A basic example showing how to generate Python models.
- [generate-python-complete-models](./generate-python-complete-models) - A basic example showing how to generate complete Python models.
- [generate-python-pydantic-models](./generate-python-pydantic-models) - An example showing how to generate Python pydantic models.
- [python-generate-json-serializer-and-deseriazlier](./python-generate-json-serializer-and-deserializer) - An example that shows how to generate the models with JSON serializer and deserializer.

## JavaScript
### JavaScript
These are all specific examples only relevant to the JavaScript generator:
- [generate-javascript-models](./generate-javascript-models) - A basic example to generate JavaScript data models
- [javascript-use-esm](./javascript-use-esm) - A basic example that generate the models to use ESM module system.
- [javascript-use-cjs](./javascript-use-cjs) - A basic example that generate the models to use CJS module system.
- [javascript-generate-marshalling](./javascript-generate-marshalling) - A basic example of how to use the un/marshalling functionality of the javascript class.
- [javascript-generate-example](./javascript-generate-example) - A basic example of how to use Modelina and output a JavaScript class with an example function.

## Java
### Java
These are all specific examples only relevant to the Java generator:

- [generate-java-models](./generate-java-models) - A basic example to generate Java data models.
- [java-generate-tostring](./java-generate-tostring) - A basic example that shows how to generate models that overwrite the `toString` method
- [java-change-collection-type](./java-change-collection-type) - An example to render collections as List in Java.
- [java-generate-hashcode](./java-generate-hashcode) - A basic example that shows how to generate models that overwrite the `hashCode` method
Expand All @@ -95,10 +111,12 @@ These are all specific examples only relevant to the Java generator:
- [java-generate-equals](./java-generate-equals) - A basic example that shows how to generate models that overwrite the `equal` method
- [java-generate-javax-constraint-annotation](./java-generate-javax-constraint-annotation) - A basic example that shows how Java data models having `javax.validation.constraints` annotations can be generated.
- [java-generate-javadoc](./java-generate-javadoc) - A basic example of how to generate Java models including JavaDocs.
- [integrate-modelina-into-maven](./integrate-modelina-into-maven/) - A basic example that shows how you can integrate Modelina into the Java Maven build process.
- [integrate-into-maven](./integrate-with-maven/) - A basic example that shows how you can integrate Modelina into the Java Maven build process.

## C#
### C#
These are all specific examples only relevant to the C# generator:

- [generate-csharp-models](./generate-csharp-models) - A basic example to generate C# data models
- [csharp-generate-equals-and-hashcode](./csharp-generate-equals-and-hashcode) - A basic example on how to generate models that overwrite the `Equal` and `GetHashCode` methods
- [csharp-generate-json-serializer](./csharp-generate-json-serializer) - A basic example on how to generate models that include function to serialize the data models to and from JSON with System.Text.Json.
- [csharp-generate-newtonsoft-serializer](./csharp-generate-newtonsoft-serializer) - A basic example on how to generate models that include function to serialize the data models to and form JSON with Newtonsoft.
Expand All @@ -107,8 +125,10 @@ These are all specific examples only relevant to the C# generator:
- [csharp-generate-records](./csharp-generate-records) - A basic example that shows how to change C# model type from class to record.
- [csharp-generate-handle-nullable](./csharp-generate-handle-nullable) - A basic example that shows how generate code than handles nullable mode and prevent warnings.

## TypeScript
### TypeScript
These are all specific examples only relevant to the TypeScript generator:

- [generate-typescript-models](./generate-typescript-models) - A basic example to generate TypeScript data models
- [typescript-interface](./typescript-interface) - A basic TypeScript generator that outputs interfaces.
- [typescript-enum-type](./typescript-enum-type) - A basic example of how to use Modelina can output different types of enums in TypeScript.
- [typescript-generate-example](./typescript-generate-example) - A basic example of how to use Modelina and output a TypeScript class with an example function.
Expand All @@ -118,19 +138,46 @@ These are all specific examples only relevant to the TypeScript generator:
- [typescript-use-cjs](./typescript-use-cjs) - A basic example that generate the models to use CJS module system.
- [typescript-generate-jsonbinpack](./typescript-generate-jsonbinpack) - A basic example showing how to generate models that include [jsonbinpack](https://github.com/sourcemeta/jsonbinpack) functionality.

## Kotlin
### Kotlin
These are all specific examples only relevant to the Kotlin generator:

- [generate-kotlin-models](./generate-kotlin-models) - A basic example to generate Kotlin data models
- [generate-kotlin-enums](./generate-kotlin-enums)
- [kotlin-generate-kdoc](./kotlin-generate-kdoc)
- [kotlin-generate-javax-constraint-annotations](./kotlin-generate-javax-constraint-annotation)
- [kotlin-change-collection-type](./kotlin-change-collection-type)

## PHP
### PHP
These are all specific examples only relevant to the PHP generator:
- [php-generate-models](./php-generate-models) - A basic example of how to use Modelina and output a PHP class.

- [generate-php-models](./generate-cplusplus-models) - A basic example to generate PHP data models
- [php-generate-complete-models](./php-generate-complete-models) - An example that will output PHP complete class with dependencies and headers.
- [php-generate-documentation-preset](./php-generate-documentation-preset) - An example that will output PHP complete class with documentation.

### Scala
These are all specific examples only relevant to the Scala generator:
- [generate-scala-models](./generate-scala-models) - A basic example to generate Scala data models
- [generate-scala-enums](./generate-scala-enums) - A basic example of how to use Modelina and output a Scala enums.
- [scala-generate-documentation](./scala-generate-documentation) - A basic example of how to use Modelina and output a Scala models that include descriptions.

### Rust
These are all specific examples only relevant to the Rust generator;
- [rust-generate-crate](./rust-generate-crate) - A basic example showing how to generate a Rust package.

### Dart
These are all specific examples only relevant to the Dart generator:
- [generate-dart-models](./generate-dart-models) - A basic example showing how to generate Python models.
- [dart-generate-json-annotation](./dart-generate-json-annotation) - A basic example of how to use Modelina and output Dart models that include JSON annotations.

### Go
These are all specific examples only relevant to the Go generator;
- [generate-go-enums](./generate-go-enums) - A basic example showing how to generate a Go enums.
- [generate-go-models](./generate-go-models) - A basic example showing how to generate a Go models.

### C++
These are all specific examples only relevant to the C++ generator;
- [generate-cplusplus-models](./generate-cplusplus-models) - A basic example showing how to generate a C++ models.

## Other examples
Miscellaneous examples that do not fit into the otherwise grouping.
- [TEMPLATE](./TEMPLATE) - A basic template used to create new examples.
2 changes: 1 addition & 1 deletion examples/dart-generate-json-annotation/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dart Data Models with json_annotation

A basic example of how to use Modelina and output a Go data model.
A basic example of how to use Modelina and output Dart models that include JSON annotations.

## How to run this example

Expand Down
10 changes: 10 additions & 0 deletions examples/dart-generate-json-annotation/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions examples/dart-generate-json-annotation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"config" : { "example_name" : "dart-generate-json-annotation" }, "scripts": {
"install": "cd ../.. && npm i",
"start": "../../node_modules/.bin/ts-node --cwd ../../ ./examples/$npm_package_config_example_name/index.ts",
"start:windows": "..\\..\\node_modules\\.bin\\ts-node --cwd ..\\..\\ .\\examples\\%npm_package_config_example_name%\\index.ts",
"test": "../../node_modules/.bin/jest --config=../../jest.config.js ./examples/$npm_package_config_example_name/index.spec.ts",
"test:windows": "..\\..\\node_modules\\.bin\\jest --config=..\\..\\jest.config.js examples/%npm_package_config_example_name%/index.spec.ts"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/generate-scala-enums/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Should be able to render Kotlin Enums and should log expected output to console 1`] = `
Array [
"object Protocol extends Enumeration {
type Protocol = Value
val Http: Protocol.Value = Value(\\"HTTP\\")
val Number_1: Protocol.Value = Value(1)
val Https: Protocol.Value = Value(\\"HTTPS\\")
val ReservedTrue: Protocol.Value = Value(\\"true\\")
}",
]
`;
2 changes: 1 addition & 1 deletion examples/generate-scala-enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScalaGenerator } from '../../src/generators/scala';
import { ScalaGenerator } from '../../src';

const generator = new ScalaGenerator();
const jsonSchemaDraft7 = {
Expand Down
11 changes: 11 additions & 0 deletions examples/generate-scala-models/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Should be able to render Kotlin Models and should log expected output to console 1`] = `
Array [
"case class Root(
email: Option[String],
cache: Option[Int],
website: Option[Website],
)",
]
`;
2 changes: 1 addition & 1 deletion examples/generate-scala-models/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScalaGenerator } from '../../src/generators/scala';
import { ScalaGenerator } from '../../src';

const generator = new ScalaGenerator();
const jsonSchemaDraft7 = {
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"config": {
"example_name": "integrate-modelina-into-maven"
"example_name": "integrate-with-maven"
},
"scripts": {
"install": "(cd ../.. && npm i) && cd maven-project/scripts/modelina && npm i",
Expand Down
15 changes: 15 additions & 0 deletions examples/scala-generate-documentation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Scala Generate Models With Documentation Preset

## How to run this example

Run this example using:

```sh
npm i && npm run start
```

If you are on Windows, use the `start:windows` script instead:

```sh
npm i && npm run start:windows
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Should be able to render Scala models that include documentation and should log expected output to console 1`] = `
Array [
"/**
* Description for class
*
* @property email Description for the email property
*/
case class Root(
email: Option[String],
)",
]
`;
15 changes: 15 additions & 0 deletions examples/scala-generate-documentation/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const spy = jest.spyOn(global.console, 'log').mockImplementation(() => {
return;
});
import { generate } from './index';

describe('Should be able to render Scala models that include documentation', () => {
afterAll(() => {
jest.restoreAllMocks();
});
test('and should log expected output to console', async () => {
await generate();
expect(spy.mock.calls.length).toEqual(1);
expect(spy.mock.calls[0]).toMatchSnapshot();
});
});
Loading

0 comments on commit 6684c77

Please sign in to comment.