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 Jun 2, 2023
2 parents 5178935 + c0e0268 commit c8517b4
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@
"code",
"design"
]
},
{
"login": "Shurtu-gal",
"name": "Ashish Padhy",
"avatar_url": "https://avatars.githubusercontent.com/u/100484401?v=4",
"profile": "http://ashishpadhy.live",
"contributions": [
"code",
"test",
"infra"
]
}
],
"contributorsPerLine": 7,
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/runtime-rust-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Runtime Testing Rust Models
on:
push:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'src/generators/rust/**'
- 'test/runtime/runtime-rust/**'
- 'test/runtime/**rust**'

jobs:
test:
name: Runtime Testing Rust 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@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: Build library
run: npm install && npm run build:prod
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy, rust-src
- name: Generate Rust models
run: npm run generate:runtime:rust
- name: Run runtime tests
run: npm run test:runtime:rust


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-55-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-56-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 @@ -395,6 +395,7 @@ Thanks go out to these wonderful people ([emoji key](https://allcontributors.org
<td align="center" valign="top" width="14.28%"><a href="https://codeyt.com/"><img src="https://avatars.githubusercontent.com/u/73033511?v=4?s=100" width="100px;" alt="Bhavik Agarwal"/><br /><sub><b>Bhavik Agarwal</b></sub></a><br /><a href="#design-Bhavik-ag" title="Design">🎨</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kaushik-rishi"><img src="https://avatars.githubusercontent.com/u/52498617?v=4?s=100" width="100px;" alt="Rishi"/><br /><sub><b>Rishi</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=kaushik-rishi" title="Code">💻</a> <a href="#design-kaushik-rishi" title="Design">🎨</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://rohithboppey.netlify.app"><img src="https://avatars.githubusercontent.com/u/73538974?v=4?s=100" width="100px;" alt="Rohith Boppey"/><br /><sub><b>Rohith Boppey</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=RohithBoppey" title="Code">💻</a> <a href="#design-RohithBoppey" title="Design">🎨</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://ashishpadhy.live"><img src="https://avatars.githubusercontent.com/u/100484401?v=4?s=100" width="100px;" alt="Ashish Padhy"/><br /><sub><b>Ashish Padhy</b></sub></a><br /><a href="https://github.com/asyncapi/modelina/commits?author=Shurtu-gal" title="Code">💻</a> <a href="https://github.com/asyncapi/modelina/commits?author=Shurtu-gal" title="Tests">⚠️</a> <a href="#infra-Shurtu-gal" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 2 additions & 2 deletions modelina-website/src/components/icons/ModelinaLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default function ModelinaLogo({
className = 'h-10 w-auto mt-0.5'
className = ''
}: any) {
return (
<svg width="140" height="45" viewBox="0 0 495 195" fill="none" xmlns="http://www.w3.org/2000/svg">
<svg className={className} width="140" height="45" viewBox="0 0 495 195" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="500" height="195" fill=""/>
<path d="M64.363 62.8374H30.637C21.134 62.8374 13.5 70.6891 13.5 80.2879V114.712C13.5 124.311 21.134 132.163 30.637 132.163H64.363C73.866 132.163 81.5 124.311 81.5 114.712V80.2879C81.5 70.6891 73.866 62.8374 64.363 62.8374Z" stroke="url(#paint1_linear_1553_359)" strokeWidth="6"/>
<mask id="path-2-inside-1_1553_359" fill="white">
Expand Down
22 changes: 22 additions & 0 deletions modelina-website/src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Button from "@/components/buttons/Button";
import GithubButton from "@/components/buttons/GithubButton";
import ModelinaLogo from "@/components/icons/ModelinaLogo";
import IconRocket from "@/components/icons/Rocket";

const Custom404 = () => {
return (
<div className="h-screen w-screen flex justify-center items-center">
<div className="flex flex-col items-center p-8">
<ModelinaLogo className="h-24 w-auto" />
<h2 className="text-3xl font-bold mt-2">Page Not Found</h2>
<p className="text-2xl text-center mt-2">The page you are looking for does not exist.</p>
<div className="flex flex-col md:flex-row mt-4 gap-10">
<GithubButton className="mt-4" href="https://github.com/asyncapi/modelina/issues/new/choose" text="Create an issue"/>
<Button className="mt-4 font-semibold" href="/" text="Go to Home Page" icon={<IconRocket height='15px' width='15px'/>}/>
</div>
</div>
</div>
);
};

export default Custom404;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
"test:blackbox:java": "cross-env CI=true jest ./test/blackbox/blackbox-java.spec.ts",
"test:runtime:java": "cross-env CI=true jest ./test/runtime/runtime-java.spec.ts",
"generate:runtime:java": "cross-env CI=true ts-node ./test/runtime/runtime-java.ts",
"test:runtime:rust": "cross-env CI=true jest ./test/runtime/runtime-rust.spec.ts",
"generate:runtime:rust": "cross-env CI=true ts-node ./test/runtime/runtime-rust.ts",
"test:watch": "jest --watch",
"docs": "npm run docs:markdown",
"docs:markdown": "jsdoc2md lib/cjs/index.js -f lib/cjs/**/*.js > API.md",
Expand Down
12 changes: 12 additions & 0 deletions test/runtime/runtime-rust.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import path from 'path';
import { execCommand } from '../blackbox/utils/Utils';

jest.setTimeout(500000);

test('Rust runtime testing', async () => {
const compileCommand = `cd ${path.resolve(
__dirname,
'./runtime-rust'
)} && cargo test`;
await execCommand(compileCommand);
});
36 changes: 36 additions & 0 deletions test/runtime/runtime-rust.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
RUST_DEFAULT_PRESET,
RustFileGenerator,
RustPackageFeatures,
defaultRustRenderCompleteModelOptions
} from '../../';
import path from 'path';
import input from './generic-input.json';

const generator = new RustFileGenerator({
presets: [RUST_DEFAULT_PRESET]
});

generator.generateToPackage(
input,
// eslint-disable-next-line no-undef
path.resolve(__dirname, './runtime-rust'),
{
...defaultRustRenderCompleteModelOptions,
supportFiles: true, // generate Cargo.toml and lib.rs
package: {
packageName: 'asyncapi-rs-example',
packageVersion: '1.0.0',
// set authors, homepage, repository, and license
authors: ['AsyncAPI Rust Champions'],
homepage: 'https://www.asyncapi.com/tools/modelina',
repository: 'https://github.com/asyncapi/modelina',
license: 'Apache-2.0',
description: 'Rust models generated by AsyncAPI Modelina',
// support 2018 editions and up
edition: '2018',
// enable serde_json
packageFeatures: [RustPackageFeatures.json] as RustPackageFeatures[]
}
}
);
3 changes: 3 additions & 0 deletions test/runtime/runtime-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
src/
Cargo.lock
30 changes: 30 additions & 0 deletions test/runtime/runtime-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "asyncapi-rs-example"
version = "1.0.0"
authors = ["AsyncAPI Rust Champions"]
homepage = "https://www.asyncapi.com/tools/modelina"
repository = "https://github.com/asyncapi/modelina"
license = "Apache-2.0"
description = "Rust models generated by AsyncAPI Modelina"
edition = "2018"

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = { version="1", optional = true }

[dev-dependencies]

[features]
default = ["json"]
json = ["dep:serde_json"]

[lib]
path = "src/lib.rs"

[[bin]]
name = "asyncapi-rs-example"
path = "src/lib.rs"

[[test]]
name = "asyncapi-rs-test"
path = "test/addressTest.rs"
8 changes: 8 additions & 0 deletions test/runtime/runtime-rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Modelina Rust Runtime project

This is the Modelina Rust runtime project that is used to test the Rust-generated code from Modelina at runtime to ensure that everything works as expected.

Here is how it works:
- The models are first generated during the build phase of the project, by running the root npm script `npm run generate:runtime:rust`. These models are pre-defined with the [generic input](../generic-input.json).
- The tests are manually added and changed.
- When the project is tested, it tests the generated models at runtime for semantic errors.
37 changes: 37 additions & 0 deletions test/runtime/runtime-rust/test/addressTest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#[cfg(test)]
mod address_test {
use super::*;
use serde_json::json;

#[test]
fn should_be_able_to_serialize_model() {
let address = Address {
street_name: String::from("Test address 2"),
house_number: 2.0,
marriage: None,
members: None,
array_type: vec![],
nested_object: None,
additional_properties: None,
};

let json = serde_json::to_string(&address).unwrap();
assert_ne!(json, "");
}

#[test]
fn should_not_contain_additional_properties_when_serialized() {
let address = Address {
street_name: String::from("Test address 2"),
house_number: 2.0,
marriage: None,
members: None,
array_type: vec![],
nested_object: None,
additional_properties: None,
};

let json = serde_json::to_value(&address).unwrap();
assert!(!json.as_object().unwrap().contains_key("additionalProperties"));
}
}

0 comments on commit c8517b4

Please sign in to comment.