Skip to content
Draft
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
21 changes: 21 additions & 0 deletions .github/workflows/test-cargo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,24 @@ jobs:
--type cargo
--specifications-directory fixtures/specifications
--output-directory .generated

test-cases:
runs-on: ubuntu-latest
container: rust:1.87.0
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: rustup component add rustfmt
- run: >
cargo run
--package jns42-tester
--
cases
--type cargo
--cases-directory fixtures/cases
--output-directory .generated
5 changes: 5 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions JsonSchema42.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"name": "cargo/jns42-generator",
"path": "packages/cargo/jns42-generator",
},
{
"name": "cargo/jns42-lib",
"path": "packages/cargo/jns42-lib",
},
{
"name": "cargo/jns42-core",
"path": "packages/cargo/jns42-core",
Expand Down
3 changes: 0 additions & 3 deletions fixtures/specifications/nullable-draft-04.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ $schema: "http://json-schema.org/draft-04/schema#"
type:
- "string"
- "null"
examples:
- "hi!"
- null
3 changes: 3 additions & 0 deletions fixtures/specifications/nullable-draft_2020-12.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ $schema: "https://json-schema.org/draft/2020-12/schema"
type:
- "string"
- "null"
examples:
- "hi!"
- null
3 changes: 0 additions & 3 deletions fixtures/specifications/string-or-boolean-draft-04.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ $schema: "http://json-schema.org/draft-04/schema#"
type:
- "string"
- "boolean"
examples:
- "hi!"
- false
3 changes: 3 additions & 0 deletions fixtures/specifications/string-or-boolean-draft_2020-12.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ $schema: "https://json-schema.org/draft/2020-12/schema"
type:
- "string"
- "boolean"
examples:
- "hi!"
- false
2 changes: 1 addition & 1 deletion packages/cargo/jns42-core/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# jns42-core

This package hold the core functionality for the @jns42/generator.
This package hold the core functionality for jns42-generator.
1 change: 1 addition & 0 deletions packages/cargo/jns42-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ toml = "^0.8.10"
url = "^2.3.1"
urlencoding = "^2.1.2"
jns42-core = { path = "../jns42-core" }
jns42-lib = { path = "../jns42-lib" }

[lib]
path = "src/lib.rs"
Expand Down
16 changes: 16 additions & 0 deletions packages/cargo/jns42-generator/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::fmt::Display;

#[derive(Debug)]
pub enum Error {
ExpectedSome,
}

impl std::error::Error for Error {}

impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::ExpectedSome => write!(f, "ExpectedSome"),
}
}
}
1 change: 0 additions & 1 deletion packages/cargo/jns42-generator/src/generators.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod cargo_toml;
pub mod errors_rs;
pub mod examples_test_rs;
pub mod file;
pub mod interiors_rs;
Expand Down
16 changes: 4 additions & 12 deletions packages/cargo/jns42-generator/src/generators/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub fn generate_file_content(
edition = "2024"

[dependencies]
jns42-lib = "0.1"
clap = { version = "^4.1", features = ["derive"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = "1.0"

[lib]
path = "src/lib.rs"
Expand All @@ -20,21 +24,9 @@ pub fn generate_file_content(
name = package_name
path = "src/main.rs"


[features]
default = []
deref = []

[dependencies.clap]
features = ["derive"]
version = "4.1"

[dependencies.serde]
features = ["derive"]
version = "1.0"

[dependencies.serde_json]
version = "1.0"
};

let content = toml::ser::to_string_pretty(&manifest)?;
Expand Down
36 changes: 0 additions & 36 deletions packages/cargo/jns42-generator/src/generators/errors_rs.rs

This file was deleted.

1 change: 0 additions & 1 deletion packages/cargo/jns42-generator/src/generators/lib_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn generate_file_token_stream(
let mut tokens = quote! {};

tokens.append_all(quote! {
pub mod errors;
pub mod interiors;
pub mod types;
#[cfg(test)]
Expand Down
1 change: 0 additions & 1 deletion packages/cargo/jns42-generator/src/generators/main_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn generate_file_token_stream(
};

tokens.append_all(quote! {
mod errors;
mod interiors;
mod types;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ fn generate_test_token_stream(
};

tokens.append_all(quote! {
// #[test]
#[test]
fn #identifier() {

//
}
});

Expand Down
4 changes: 0 additions & 4 deletions packages/cargo/jns42-generator/src/generators/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ pub async fn generate_package(
let content = super::file::generate_file_content(tokens)?;
fs::write(src_path.join("main.rs"), content).await?;

let tokens = super::errors_rs::generate_file_token_stream(specification)?;
let content = super::file::generate_file_content(tokens)?;
fs::write(src_path.join("errors.rs"), content).await?;

let tokens = super::types_rs::generate_file_token_stream(specification)?;
let content = super::file::generate_file_content(tokens)?;
fs::write(src_path.join("types.rs"), content).await?;
Expand Down
Loading
Loading