forked from asyncapi/modelina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/add_next_example
- Loading branch information
Showing
12 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target/ | ||
src/ | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |