Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ ENV PATH="${PATH}:/usr/local/go/bin"

# Install dotnet SDK
RUN apt install apt-transport-https dirmngr gnupg ca-certificates -yq \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
&& echo "deb https://download.mono-project.com/repo/ubuntu stable-jammy main"| tee /etc/apt/sources.list.d/mono-official-stable.list \
&& apt update -yq \
&& apt install mono-devel -yq

Expand Down
14 changes: 9 additions & 5 deletions src/generators/rust/RustRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { FormatHelpers } from '../../helpers/FormatHelpers';
import {
deriveCopy,
deriveHash,
derivePartialEq,
deriveEq,
derivePartialOrd,
deriveOrd
Expand Down Expand Up @@ -37,16 +36,20 @@ export abstract class RustRenderer<
}

renderMacro(model: ConstrainedMetaModel): string {
const derive: string[] = ['Serialize', 'Deserialize', 'Clone', 'Debug'];
const derive: string[] = [
'Serialize',
'Deserialize',
'Clone',
'Debug',
'PartialEq'
];

if (deriveHash(model)) {
derive.push('Hash');
}
if (deriveCopy(model)) {
derive.push('Copy');
}
if (derivePartialEq(model)) {
derive.push('PartialEq');
}
if (deriveEq(model)) {
derive.push('Eq');
}
Expand All @@ -56,6 +59,7 @@ export abstract class RustRenderer<
if (deriveOrd(model)) {
derive.push('Ord');
}

derive.sort();
return `#[derive(${derive.join(', ')})]`;
}
Expand Down
5 changes: 4 additions & 1 deletion src/generators/scala/ScalaConstrainer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Constraints } from '../../helpers';
import { ConstrainedEnumValueModel } from '../../models';
import { ConstrainedEnumValueModel, ConstrainedEnumModel } from '../../models';
import {
defaultEnumKeyConstraints,
defaultEnumValueConstraints
Expand Down Expand Up @@ -78,6 +78,9 @@ export const ScalaDefaultTypeMapping: ScalaTypeMapping = {
return constrainedModel.name;
},
Reference({ constrainedModel }): string {
if (constrainedModel.ref instanceof ConstrainedEnumModel) {
return `${constrainedModel.name}.Value`;
}
return constrainedModel.name;
},
Any(): string {
Expand Down
6 changes: 3 additions & 3 deletions test/generators/rust/RustRenderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,13 @@ describe('RustRenderer', () => {
);

expect(renderer.renderMacro(arrayModel)).toEqual(
'#[derive(Clone, Debug, Deserialize, Serialize)]'
'#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]'
);
expect(renderer.renderMacro(enumModel)).toEqual(
'#[derive(Clone, Debug, Deserialize, Serialize)]'
'#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]'
);
expect(renderer.renderMacro(objectModel)).toEqual(
'#[derive(Clone, Debug, Deserialize, Serialize)]'
'#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]'
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Default for CustomEnum {

exports[`RUST_COMMON_PRESET Enum should render reserved union for dict array 1`] = `
"// Class represents a Class model.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Class {
#[serde(rename=\\"students\\")]
pub students: Vec<crate::Student>,
Expand All @@ -215,7 +215,7 @@ impl Class {

exports[`RUST_COMMON_PRESET Enum should render reserved union for dict array 2`] = `
"// Student represents a Student model.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Student {
#[serde(rename=\\"name\\")]
pub name: String,
Expand Down
8 changes: 5 additions & 3 deletions test/runtime/runtime-kotlin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { execCommand } from '../TestUtils/GeneralUtils';
import path from 'path';

jest.setTimeout(50000);
jest.setTimeout(500000);

test('Kotlin runtime testing', async () => {
const generateCommand = 'npm run generate:runtime:kotlin';
await execCommand(generateCommand, true);
//The 'build' command here
const buildCommand = `cd ${path.resolve(
__dirname,
'./runtime-kotlin'
)} && ./gradlew build`;
await execCommand(buildCommand);
await execCommand(buildCommand, true);
//The 'test' command here
const testCommand = `cd ${path.resolve(
__dirname,
'./runtime-kotlin'
)} && ./gradlew test`;
await execCommand(testCommand);
await execCommand(testCommand, true);
});
2 changes: 1 addition & 1 deletion test/runtime/runtime-kotlin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KOTLIN_DEFAULT_PRESET, KotlinFileGenerator } from '../../';
import { KOTLIN_DEFAULT_PRESET, KotlinFileGenerator } from '../../src';
import path from 'path';
import input from './generic-input.json';

Expand Down
2 changes: 2 additions & 0 deletions test/runtime/runtime-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.1")
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2'
testImplementation 'org.hamcrest:hamcrest:2.2'
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.not
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.BeforeEach
Expand All @@ -18,11 +19,11 @@ class AddressTest {
fun setup() {
address = Address(
streetName = "Test address 2",
houseNumber = 2,
houseNumber = 2.0,
marriage = true,
members = 2,
arrayType = listOf(2, "test"),
nestedObject = Address.NestedObject(test = "test")
nestedObject = NestedObject(test = "test")
)
}

Expand Down
7 changes: 5 additions & 2 deletions test/runtime/runtime-rust.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { execCommand } from '../TestUtils/GeneralUtils';
jest.setTimeout(500000);

test('Rust runtime testing', async () => {
const cargoPath = process.env.CARGO || 'cargo';

const compileCommand = `cd ${path.resolve(
__dirname,
'./runtime-rust'
)} && cargo test`;
await execCommand(compileCommand);
)} && ${cargoPath} test`;

await execCommand(compileCommand, true);
});
6 changes: 0 additions & 6 deletions test/runtime/runtime-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,4 @@ 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"
10 changes: 6 additions & 4 deletions test/runtime/runtime-scala.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { execCommand } from '../TestUtils/GeneralUtils';
import path from 'path';

jest.setTimeout(50000);
jest.setTimeout(500000);

test('Scala runtime testing', async () => {
const generateCommand = 'npm run generate:runtime:scala';
await execCommand(generateCommand, true);
//The 'build' command here
const buildCommand = `cd ${path.resolve(
__dirname,
'./runtime-scala'
)} && ./gradlew build`;
await execCommand(buildCommand);
)} && ./gradlew clean build`;
await execCommand(buildCommand, true);
//The 'test' command here
const testCommand = `cd ${path.resolve(
__dirname,
'./runtime-scala'
)} && ./gradlew test`;
await execCommand(testCommand);
await execCommand(testCommand, true);
});
2 changes: 1 addition & 1 deletion test/runtime/runtime-scala.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SCALA_DEFAULT_PRESET, ScalaFileGenerator } from '../..';
import { SCALA_DEFAULT_PRESET, ScalaFileGenerator } from '../../src';
import path from 'path';
import input from './generic-input.json';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import org.scalatest.matchers.should.Matchers
class AddressSpec extends AnyFlatSpec with Matchers {
it should "generate model with the right fields" in {
val address = Address(
streetName = "Test address 2",
houseNumber = 2,
streetName = Some("Test address 2"),
houseNumber = 2.0,
marriage = Some(true),
members = Some(2),
arrayType = List(2, "test"),
nestedObject = Some(NestedObject(Some("test"), None)),
enumTest = None,
houseType = None,
roofType = None,
additionalProperties = None
)

Expand Down
Loading