Skip to content

Commit

Permalink
Merge branch 'master' into feature/add_next_example
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Aug 22, 2023
2 parents 7511fa9 + 627ed97 commit 51266d9
Show file tree
Hide file tree
Showing 16 changed files with 604 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,15 @@
"contributions": [
"bug"
]
},
{
"login": "Ksisa",
"name": "Kristupas",
"avatar_url": "https://avatars.githubusercontent.com/u/53404771?v=4",
"profile": "https://github.com/Ksisa",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/runtime-csharp-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Runtime Testing C# Models
on:
push:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'src/generators/csharp/**'
- 'test/runtime/runtime-csharp/**'
- 'test/runtime/**csharp**'

jobs:
test:
name: Runtime Testing C# Models
if: "github.event.pull_request.draft == false &&!((github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'ci: update global workflows')) || (github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'chore(release):')) || (github.actor == 'allcontributors' && startsWith(github.event.pull_request.title, 'docs: add')))"
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Check package-lock version
uses: asyncapi/.github/.github/actions/get-node-version-from-package-lock@master
id: lockversion
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "${{ steps.lockversion.outputs.version }}"
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- if: matrix.os != 'windows-latest'
name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- if: matrix.os == 'windows-latest'
name: Setup csc.exe
uses: yoavain/Setup-CSC@v7
- name: Build library
run: npm install && npm run build:prod
- name: Generate C# models
run: npm run generate:runtime:csharp
- name: Run runtime tests
run: npm run test:runtime:csharp


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-62-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-63-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 @@ -404,6 +404,7 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
<td align="center" valign="top" width="14.28%"><a href="http://markus.poerschke.nrw"><img src="https://avatars.githubusercontent.com/u/1222377?v=4?s=100" width="100px;" alt="Markus Poerschke"/><br /><sub><b>Markus Poerschke</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=markuspoerschke" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=markuspoerschke" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jamesmoey"><img src="https://avatars.githubusercontent.com/u/457472?v=4?s=100" width="100px;" alt="James Moey"/><br /><sub><b>James Moey</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=jamesmoey" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=jamesmoey" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tomwolanski"><img src="https://avatars.githubusercontent.com/u/68085653?v=4?s=100" width="100px;" alt="tomwolanski"/><br /><sub><b>tomwolanski</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/issues?q=author%3Atomwolanski" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Ksisa"><img src="https://avatars.githubusercontent.com/u/53404771?v=4?s=100" width="100px;" alt="Kristupas"/><br /><sub><b>Kristupas</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=Ksisa" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal class RootConverter : JsonConverter<Root>
writer.WriteStartObject();
if(value.Email != null) {
if(value.Email != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"email\\");
JsonSerializer.Serialize(writer, value.Email, options);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@asyncapi/modelina",
"version": "1.8.10",
"version": "1.8.11",
"description": "Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents",
"license": "Apache-2.0",
"homepage": "https://www.modelina.org",
Expand Down Expand Up @@ -113,6 +113,8 @@
"generate:runtime:php": "cross-env CI=true ts-node ./test/runtime/runtime-php.ts",
"test:runtime:typescript": "cd ./test/runtime/runtime-typescript && npm i && npm run test",
"generate:runtime:typescript": "cross-env CI=true ts-node ./test/runtime/runtime-typescript.ts",
"test:runtime:csharp": "cross-env CI=true jest ./test/runtime/runtime-csharp.spec.ts",
"generate:runtime:csharp": "cross-env CI=true ts-node ./test/runtime/runtime-csharp.ts",
"test:watch": "jest --watch",
"docs": "npm run docs:api",
"docs:api": "typedoc src/index.ts --out ./modelina-website/public/docs/api/generated --name Modelina",
Expand Down
6 changes: 3 additions & 3 deletions src/generators/csharp/presets/JsonSerializerPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function renderSerializeProperty(
model.property instanceof ConstrainedReferenceModel &&
model.property.ref instanceof ConstrainedEnumModel
) {
value = `${model.property.type}.GetValue()`;
value = `value.${model.property.type}.GetValue()`;
}
return `JsonSerializer.Serialize(writer, ${value}, options);`;
}
Expand Down Expand Up @@ -51,7 +51,7 @@ if (${modelInstanceVariable} != null) {
}
}`;
}
serializeProperties += `if(${modelInstanceVariable} != null) {
serializeProperties += `if(${modelInstanceVariable} != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName("${propertyModel.unconstrainedPropertyName}");
${renderSerializeProperty(modelInstanceVariable, propertyModel)}
Expand Down Expand Up @@ -123,7 +123,7 @@ function renderDeserializeProperty(model: ConstrainedObjectPropertyModel) {
model.property instanceof ConstrainedReferenceModel &&
model.property.ref instanceof ConstrainedEnumModel
) {
return `${model.property.name}Extension.To${model.property.name}(JsonSerializer.Deserialize<dynamic>(ref reader, options))`;
return `${model.property.name}Extensions.To${model.property.name}(JsonSerializer.Deserialize<dynamic>(ref reader, options))`;
}
return `JsonSerializer.Deserialize<${model.property.type}>(ref reader, options)`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal class TestConverter : JsonConverter<Test>
}
if (propertyName == \\"enumProp\\")
{
var value = EnumTestExtension.ToEnumTest(JsonSerializer.Deserialize<dynamic>(ref reader, options));
var value = EnumTestExtensions.ToEnumTest(JsonSerializer.Deserialize<dynamic>(ref reader, options));
instance.EnumProp = value;
continue;
}
Expand Down Expand Up @@ -114,22 +114,22 @@ internal class TestConverter : JsonConverter<Test>
writer.WriteStartObject();
if(value.StringProp != null) {
if(value.StringProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"string prop\\");
JsonSerializer.Serialize(writer, value.StringProp, options);
}
if(value.NumberProp != null) {
if(value.NumberProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"numberProp\\");
JsonSerializer.Serialize(writer, value.NumberProp, options);
}
if(value.EnumProp != null) {
if(value.EnumProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"enumProp\\");
JsonSerializer.Serialize(writer, EnumTest?.GetValue(), options);
JsonSerializer.Serialize(writer, value.EnumTest?.GetValue(), options);
}
if(value.ObjectProp != null) {
if(value.ObjectProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"objectProp\\");
JsonSerializer.Serialize(writer, value.ObjectProp, options);
Expand All @@ -147,7 +147,7 @@ internal class TestConverter : JsonConverter<Test>
writer.WritePropertyName(unwrappedProperty.Key);
JsonSerializer.Serialize(writer, unwrappedProperty.Value, options);
}
}if(value.AdditionalProperties != null) {
}if(value.AdditionalProperties != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"additionalProperties\\");
JsonSerializer.Serialize(writer, value.AdditionalProperties, options);
Expand Down Expand Up @@ -274,7 +274,7 @@ internal class NestedTestConverter : JsonConverter<NestedTest>
writer.WriteStartObject();
if(value.StringProp != null) {
if(value.StringProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"stringProp\\");
JsonSerializer.Serialize(writer, value.StringProp, options);
Expand All @@ -292,7 +292,7 @@ internal class NestedTestConverter : JsonConverter<NestedTest>
writer.WritePropertyName(unwrappedProperty.Key);
JsonSerializer.Serialize(writer, unwrappedProperty.Value, options);
}
}if(value.AdditionalProperties != null) {
}if(value.AdditionalProperties != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"additionalProperties\\");
JsonSerializer.Serialize(writer, value.AdditionalProperties, options);
Expand Down
12 changes: 12 additions & 0 deletions test/runtime/runtime-csharp.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { execCommand } from '../blackbox/utils/Utils';
import path from 'path';

jest.setTimeout(50000);

test('C# runtime testing', async () => {
const compileCommand = `cd ${path.resolve(
__dirname,
'./runtime-csharp'
)} && dotnet test runtime-csharp`;
await execCommand(compileCommand);
});
17 changes: 17 additions & 0 deletions test/runtime/runtime-csharp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CSHARP_JSON_SERIALIZER_PRESET, CSharpFileGenerator } from '../../';
import path from 'path';
import input from './generic-input.json';

const generator = new CSharpFileGenerator({
presets: [CSHARP_JSON_SERIALIZER_PRESET]
});

generator.generateToFiles(
input,
path.resolve(
// eslint-disable-next-line no-undef
__dirname,
'./runtime-csharp/runtime-csharp/src/models/json_serializer'
),
{ namespace: 'com.mycompany.app.generic' }
);
Loading

0 comments on commit 51266d9

Please sign in to comment.