Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Nov 29, 2023
1 parent c9ef2a2 commit 8b80d3f
Show file tree
Hide file tree
Showing 28 changed files with 63 additions and 62 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [
"libninja",
"macro",
"core",
"hir",
"mir",
]
exclude = [
"commercial",
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc-macro2 = "1.0.63"
tracing-ez = "0.3.0"
indexmap = "2.0"
syn = "2.0"
libninja_hir = { path = "../hir" }
libninja_mir = { path = "../mir" }
include_dir = "0.7.3"
tera = "1.19.0"

Expand Down
2 changes: 1 addition & 1 deletion core/src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use openapiv3::{APIKeyLocation, OpenAPI, Operation, PathItem, ReferenceOr, Schem
use openapiv3 as oa;
use tracing_ez::{span, warn};

use hir::{Doc, Name, NewType};
use mir::{Doc, Name, NewType};
pub use record::*;
pub use resolution::{schema_to_ty, schema_ref_to_ty, schema_ref_to_ty_already_resolved};
pub use resolution::*;
Expand Down
2 changes: 1 addition & 1 deletion core/src/extractor/record.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Records are the "model"s of the MIR world. model is a crazy overloaded word though.
use openapiv3::{ObjectType, OpenAPI, ReferenceOr, Schema, SchemaData, SchemaKind, SchemaReference, StatusCode, StringType, Type};
use hir::{Doc, Name};
use mir::{Doc, Name};
use std::collections::{BTreeMap, HashMap};
use tracing_ez::warn;
use crate::{extractor, mir2};
Expand Down
2 changes: 1 addition & 1 deletion core/src/mir2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::Result;
use convert_case::{Case, Casing};

use crate::{LibraryOptions, Language};
pub use hir::{Doc, Name};
pub use mir::{Doc, Name};
use openapiv3 as oa;

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion core/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;
use convert_case::{Case, Casing};
use hir::{literal, Name, Literal};
use mir::{literal, Name, Literal};
use crate::Language;

#[derive(Debug, Clone, Default)]
Expand Down
2 changes: 1 addition & 1 deletion libninja/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ semver = "1.0.17"
indexmap = "2.0"
ln-macro = { path = "../macro" }
ln-core = { path = "../core" }
libninja_hir = { path = "../hir" }
libninja_mir = { path = "../mir" }

[dev-dependencies]
env_logger = "0.10.0"
Expand Down
12 changes: 6 additions & 6 deletions libninja/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ use codegen::ToRustIdent;
use codegen::ToRustType;
use format::format_code;
use ln_core::{copy_files, copy_templates, create_context, get_template_file, prepare_templates};
use hir::{Visibility, Import, File};
use ::mir::{Visibility, Import, File};
use ln_core::fs;

use crate::{add_operation_models, extract_spec, LibraryOptions, MirSpec, OutputOptions, util};
pub use crate::rust::codegen::generate_example;
use crate::rust::codegen::ToRustCode;
use crate::rust::io::write_rust_file_to_path;
use crate::rust::mir::{generate_model_rs, generate_single_model_file};
use crate::rust::lower_mir::{generate_model_rs, generate_single_model_file};
use crate::rust::request::{build_request_struct, generate_request_model_rs};

pub mod client;
pub mod codegen;
pub mod format;
pub mod mir;
pub mod lower_mir;
pub mod request;
mod io;
mod serde;
Expand Down Expand Up @@ -158,11 +158,11 @@ fn write_lib_rs(mir_spec: &MirSpec, extras: &Extras, spec: &OpenAPI, opts: &Outp
};

let client_name = struct_Client.name.to_string();
let template_path = opts.dest_path.join("template").join("src").join("hir");
let template_path = opts.dest_path.join("template").join("src").join("../../mir");
let lib_rs_template = if template_path.exists() {
fs::read_to_string(template_path)?
} else {
let s = get_template_file("rust/src/hir");
let s = get_template_file("rust/src/mir");
formatdoc!(
r#"
//! [`{client}`](struct.{client}.html) is the main entry point for this library.
Expand Down Expand Up @@ -192,7 +192,7 @@ fn write_lib_rs(mir_spec: &MirSpec, extras: &Extras, spec: &OpenAPI, opts: &Outp
#security
};

io::write_rust_to_path(&src_path.join("hir"), code, &lib_rs_template)?;
io::write_rust_to_path(&src_path.join("../../mir"), code, &lib_rs_template)?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions libninja/src/rust/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use ln_core::extractor::{extract_response_success, extract_security_strategies,
use crate::rust::codegen::{ToRustCode};
use ln_core::{extractor, Language, LibraryOptions, MirSpec, mir2};
use convert_case::{Case, Casing};
use hir::{Doc, field, Function, Ident, Name};
use hir::{Class, Field, FnArg, Visibility};
use mir::{Doc, field, Function, Ident, Name};
use mir::{Class, Field, FnArg, Visibility};
use openapiv3::{
APIKeyLocation, OpenAPI, Operation, ReferenceOr, RequestBody, Schema, SchemaKind,
SecurityRequirement, SecurityScheme, StatusCode,
Expand Down
4 changes: 2 additions & 2 deletions libninja/src/rust/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use quote::{quote, TokenStreamExt};
use regex::{Captures, Regex};
use syn::Path;

use hir::{ArgIdent, Class, Doc, Field, File, Function, Ident, Import, ImportItem, Literal, Visibility};
use mir::{ArgIdent, Class, Doc, Field, File, Function, Ident, Import, ImportItem, Literal, Visibility};
pub use typ::*;
pub use example::*;
pub use ident::*;
Expand Down Expand Up @@ -425,7 +425,7 @@ pub fn formatted_code(code: impl ToRustCode) -> String {

#[cfg(test)]
mod tests {
use hir::{Ident, import, Import, Name};
use mir::{Ident, import, Import, Name};

use crate::rust::codegen::{ToRustCode, ToRustIdent};

Expand Down
2 changes: 1 addition & 1 deletion libninja/src/rust/codegen/example.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use proc_macro2::TokenStream;
use quote::quote;
use ln_macro::rfunction;
use hir::{File, Import};
use mir::{File, Import};
use crate::{Language, LibraryOptions, };
use ln_core::{mir2, mir2::{MirSpec, Parameter}};
use crate::rust::codegen;
Expand Down
2 changes: 1 addition & 1 deletion libninja/src/rust/codegen/ident.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use convert_case::{Case, Casing};
use hir::{Ident, Name};
use mir::{Ident, Name};
use crate::rust::codegen;

pub trait ToRustIdent {
Expand Down
2 changes: 1 addition & 1 deletion libninja/src/rust/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::rust::codegen::ToRustCode;
use crate::rust::format::format_code;
use crate::util;

pub fn write_rust_file_to_path(path: &Path, file: ::hir::File<TokenStream>) -> anyhow::Result<()> {
pub fn write_rust_file_to_path(path: &Path, file: ::mir::File<TokenStream>) -> anyhow::Result<()> {
let code = file.to_rust_code();
write_rust_code_to_path(path, code)
}
Expand Down
4 changes: 2 additions & 2 deletions libninja/src/rust/mir.rs → libninja/src/rust/lower_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use tracing_ez::{info, span};

use hir::{Field, File, Ident, Import, import, Name, Visibility};
use hir as model;
use ::mir::{Field, File, Ident, Import, import, Name, Visibility};
use ::mir as model;

use ln_core::{extractor, mir2, MirSpec};
use ln_core::mir2::{DateSerialization, IntegerSerialization, MirField, NewType, Record, StrEnum, Struct, Ty, TypeAlias};
Expand Down
4 changes: 2 additions & 2 deletions libninja/src/rust/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use ln_core::extractor::{extract_response_success, schema_ref_to_ty, spec_define
use ln_core::mir2;
use ln_core::LibraryOptions;
use ln_core::OutputOptions;
use hir::{Doc, doc, Ident, Name};
use hir::{Class, Field, FnArg, Function, Visibility};
use mir::{Doc, doc, Ident, Name};
use mir::{Class, Field, FnArg, Function, Visibility};

use crate::rust::codegen::ToRustCode;
use crate::rust::codegen::ToRustIdent;
Expand Down
2 changes: 1 addition & 1 deletion libninja/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use url::Host;

use ln_core::fs;
use ln_core::OutputOptions;
pub use hir::build_struct;
pub use mir::build_struct;

use crate::{MirSpec, };

Expand Down
2 changes: 1 addition & 1 deletion libninja/tests/all_of/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn record_for_schema(name: &str, schema: &str, spec: &OpenAPI) -> mir2::Record {

fn formatted_code(record: mir2::Record) -> String {
let config = LibraryConfig::default();
let code = libninja::rust::mir::create_struct(&record, &config);
let code = libninja::rust::lower_mir::create_struct(&record, &config);
libninja::rust::format::format_code(code).unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion libninja/tests/regression/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use openapiv3::{OpenAPI, ReferenceOr, Schema};
use ln_core::{mir2, mir2::Record};
use libninja::rust::mir::StructExt;
use libninja::rust::lower_mir::StructExt;

const LINK_TOKEN_CREATE: &str = include_str!("link_token_create.yaml");

Expand Down
2 changes: 1 addition & 1 deletion macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ proc_macro = true
[dependencies]
proc-macro2 = { version = "1.0", features = ["span-locations"] }
quote = "1.0.29"
libninja_hir = { path = "../hir" }
libninja_mir = { path = "../mir" }

[dev-dependencies]
pretty_assertions = "1.3.0"
4 changes: 2 additions & 2 deletions macro/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ pub fn parse_intro(toks: &mut impl Iterator<Item=TokenTree>) -> Tags {
}
};
let fn_name = if captured.is_empty() {
quote!( ::hir::Ident(#fn_name.to_string()) )
quote!( ::mir::Ident(#fn_name.to_string()) )
} else {
let captured = captured
.into_iter()
.map(|name| Ident2::new(&name, proc_macro2::Span::call_site()));

quote!( ::hir::Ident(format!("{}", #( #captured ),*)) )
quote!( ::mir::Ident(format!("{}", #( #captured ),*)) )
};
Tags {
asyn,
Expand Down
12 changes: 6 additions & 6 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn function(item: TokenStream) -> TokenStream {
let args = parse_args(arg_toks.stream()).into_iter().map(|arg| {
let Arg { name, arg_type, default } = arg;
quote! {
::hir::FnArg {
::mir::FnArg {
name: #name.into(),
ty: #arg_type,
default: #default,
Expand All @@ -44,14 +44,14 @@ pub fn function(item: TokenStream) -> TokenStream {
};

quote! {
::hir::Function {
::mir::Function {
name: #fn_name,
async_: #asyn,
public: #public,
args: vec![#(#args),*],
ret: #ret,
body: #body,
..::hir::Function::default()
..::mir::Function::default()
}
}.into()
}
Expand All @@ -70,7 +70,7 @@ pub fn rfunction(item: TokenStream) -> TokenStream {
let args = rfunction::parse_args2(arg_toks.stream()).into_iter().map(|arg| {
let Arg { name, arg_type, default } = arg;
quote! {
::hir::FnArg {
::mir::FnArg {
name: #name.into(),
ty: #arg_type,
default: #default,
Expand All @@ -93,14 +93,14 @@ pub fn rfunction(item: TokenStream) -> TokenStream {
};

quote! {
::hir::Function {
::mir::Function {
name: #fn_name,
async_: #asyn,
public: #public,
args: vec![#(#args),*],
ret: #ret,
body: #body,
..::hir::Function::default()
..::mir::Function::default()
}
}.into()
}
Expand Down
2 changes: 1 addition & 1 deletion macro/tests/function.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ln_macro::function;
use hir::{Function, ArgIdent};
use mir::{Function, ArgIdent};
use pretty_assertions::assert_eq;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion macro/tests/rfunction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use proc_macro2::TokenStream;
use ln_macro::rfunction;

use hir::Function;
use mir::Function;
use quote::quote;

#[test]
Expand Down
6 changes: 3 additions & 3 deletions hir/Cargo.toml → mir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "libninja_hir"
name = "libninja_mir"
version = "0.1.0"
edition = "2021"

[lib]
name = "hir"
name = "mir"
path = "src/lib.rs"

[dependencies]
quote = "1.0.29"
proc-macro2 = "1.0.63"
proc-macro2 = "1.0.63"
File renamed without changes.
1 change: 1 addition & 0 deletions hir/src/lib.rs → mir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Models that represent code
/// Things like, Parameters, Functions, Fields, Class, etc.
///
use core::default::Default;
use core::fmt::{Debug, Formatter};
Expand Down
Loading

0 comments on commit 8b80d3f

Please sign in to comment.