mirror of
https://github.com/linabutler/ploidy
synced 2026-08-12 01:43:47 +00:00
chore: Split library target into ploidy-core.
This commit is contained in:
Generated
+13
-48
@@ -128,15 +128,6 @@ dependencies = [
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "castaway"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.49"
|
||||
@@ -213,20 +204,6 @@ version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||
|
||||
[[package]]
|
||||
name = "compact_str"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a"
|
||||
dependencies = [
|
||||
"castaway",
|
||||
"cfg-if",
|
||||
"itoa",
|
||||
"rustversion",
|
||||
"ryu",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
@@ -443,15 +420,6 @@ dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indoc"
|
||||
version = "2.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_ci"
|
||||
version = "1.2.0"
|
||||
@@ -635,20 +603,27 @@ version = "0.2.0"
|
||||
dependencies = [
|
||||
"cargo_toml",
|
||||
"clap",
|
||||
"compact_str",
|
||||
"heck",
|
||||
"indexmap",
|
||||
"indoc",
|
||||
"itertools",
|
||||
"miette",
|
||||
"mimalloc",
|
||||
"ploidy-core",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ploidy-core"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"cargo_toml",
|
||||
"heck",
|
||||
"indexmap",
|
||||
"itertools",
|
||||
"miette",
|
||||
"percent-encoding",
|
||||
"petgraph",
|
||||
"ploidy-pointer",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_path_to_error",
|
||||
@@ -770,10 +745,6 @@ name = "semver"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
@@ -870,12 +841,6 @@ version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
|
||||
+8
-1
@@ -1,5 +1,11 @@
|
||||
[workspace]
|
||||
members = ["ploidy", "ploidy-pointer", "ploidy-pointer-derive", "ploidy-util"]
|
||||
members = [
|
||||
"ploidy",
|
||||
"ploidy-core",
|
||||
"ploidy-pointer",
|
||||
"ploidy-pointer-derive",
|
||||
"ploidy-util",
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
@@ -10,6 +16,7 @@ repository = "https://github.com/linabutler/ploidy"
|
||||
keywords = ["openapi", "swagger"]
|
||||
|
||||
[workspace.dependencies]
|
||||
ploidy-core = { path = "ploidy-core", version = "0.2.0" }
|
||||
ploidy-pointer = { path = "ploidy-pointer", version = "0.2.0" }
|
||||
ploidy-pointer-derive = { path = "ploidy-pointer-derive", version = "0.2.0" }
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
[package]
|
||||
name = "ploidy-core"
|
||||
description = "OpenAPI type definitions and code generators for Ploidy"
|
||||
readme = "README.md"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
repository.workspace = true
|
||||
keywords.workspace = true
|
||||
|
||||
[dependencies]
|
||||
cargo_toml = { version = "0.22", optional = true }
|
||||
heck = "0.5"
|
||||
indexmap = { version = "2", features = ["serde"] }
|
||||
itertools = "0.14"
|
||||
miette = "7"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1", features = ["preserve_order"] }
|
||||
serde_path_to_error = "0.1"
|
||||
serde_yaml = "0.9.34"
|
||||
percent-encoding = "2.3"
|
||||
petgraph = "0.7"
|
||||
ploidy-pointer = { workspace = true, features = ["full"] }
|
||||
prettyplease = { version = "0.2", optional = true }
|
||||
proc-macro2 = { version = "1", default-features = false, optional = true }
|
||||
quote = { version = "1", default-features = false, optional = true }
|
||||
syn = { version = "2", default-features = false, features = [
|
||||
"parsing",
|
||||
"printing",
|
||||
], optional = true }
|
||||
textwrap = { version = "0.16", default-features = false, features = [
|
||||
"unicode-linebreak",
|
||||
"unicode-width",
|
||||
], optional = true }
|
||||
thiserror = "2"
|
||||
toml = { version = "0.9", default-features = false, features = [
|
||||
"display",
|
||||
"parse",
|
||||
"serde",
|
||||
], optional = true }
|
||||
unicase = "2"
|
||||
unicode-ident = { version = "1", optional = true }
|
||||
winnow = "0.7"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
rust = [
|
||||
"cargo_toml",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"textwrap",
|
||||
"toml",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../LICENSE
|
||||
@@ -0,0 +1,5 @@
|
||||
# ploidy-core
|
||||
|
||||
This crate is the core (or nucleus! 🧬) of the [Ploidy](https://crates.io/crates/ploidy) OpenAPI code generator. It exposes structures for parsing OpenAPI types, and code generators for different languages.
|
||||
|
||||
You can use **ploidy-core** as part of a larger project, or from a [build script](https://doc.rust-lang.org/cargo/reference/build-scripts.html) if you're targeting Rust.
|
||||
@@ -1,15 +1,12 @@
|
||||
use std::path::Path;
|
||||
|
||||
use cargo_toml::Manifest;
|
||||
use miette::{Context, IntoDiagnostic};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::ToTokens;
|
||||
|
||||
#[cfg(feature = "rust")]
|
||||
pub mod rust;
|
||||
|
||||
mod unique;
|
||||
|
||||
use serde::Serialize;
|
||||
pub use unique::{UniqueNameSpace, WordSegments};
|
||||
|
||||
pub fn write_to_disk(output: &Path, code: impl IntoCode) -> miette::Result<()> {
|
||||
@@ -32,12 +29,14 @@ pub trait Code {
|
||||
fn into_string(self) -> miette::Result<String>;
|
||||
}
|
||||
|
||||
impl<T: AsRef<str>> Code for (T, TokenStream) {
|
||||
#[cfg(feature = "rust")]
|
||||
impl<T: AsRef<str>> Code for (T, proc_macro2::TokenStream) {
|
||||
fn path(&self) -> &str {
|
||||
self.0.as_ref()
|
||||
}
|
||||
|
||||
fn into_string(self) -> miette::Result<String> {
|
||||
use quote::ToTokens;
|
||||
let file = syn::parse2(self.1.into_token_stream())
|
||||
.into_diagnostic()
|
||||
.with_context(|| format!("Failed to format `{}`", self.0.as_ref()))?;
|
||||
@@ -45,7 +44,8 @@ impl<T: AsRef<str>> Code for (T, TokenStream) {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Serialize> Code for (&'static str, Manifest<T>) {
|
||||
#[cfg(feature = "rust")]
|
||||
impl<T: serde::Serialize> Code for (&'static str, cargo_toml::Manifest<T>) {
|
||||
fn path(&self) -> &str {
|
||||
self.0
|
||||
}
|
||||
@@ -28,7 +28,7 @@ impl<'a> UniqueNameSpace<'a> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # use ploidy::codegen::UniqueNameSpace;
|
||||
/// # use ploidy_core::codegen::UniqueNameSpace;
|
||||
/// # let mut space = UniqueNameSpace::new();
|
||||
/// assert_eq!(space.uniquify("HTTPResponse"), "HTTPResponse");
|
||||
/// assert_eq!(space.uniquify("HTTP_Response"), "HTTP_Response2");
|
||||
@@ -59,7 +59,7 @@ impl<'a> UniqueNameSpace<'a> {
|
||||
///
|
||||
/// ```
|
||||
/// # use itertools::Itertools;
|
||||
/// # use ploidy::codegen::WordSegments;
|
||||
/// # use ploidy_core::codegen::WordSegments;
|
||||
/// assert_eq!(WordSegments::new("HTTPResponse").collect_vec(), vec!["HTTP", "Response"]);
|
||||
/// assert_eq!(WordSegments::new("HTTP_Response").collect_vec(), vec!["HTTP", "Response"]);
|
||||
/// assert_eq!(WordSegments::new("httpResponse").collect_vec(), vec!["http", "Response"]);
|
||||
@@ -1,5 +1,4 @@
|
||||
pub mod codegen;
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
pub mod ir;
|
||||
pub mod parse;
|
||||
+2
-37
@@ -11,45 +11,10 @@ keywords.workspace = true
|
||||
[dependencies]
|
||||
cargo_toml = "0.22"
|
||||
clap = { version = "4", features = ["cargo", "derive"] }
|
||||
compact_str = "0.9"
|
||||
heck = "0.5"
|
||||
indexmap = { version = "2", features = ["serde"] }
|
||||
indoc = "2"
|
||||
itertools = "0.14"
|
||||
miette = { version = "7", features = ["fancy"] }
|
||||
mimalloc = { version = "0.1", optional = true }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1", features = ["preserve_order"] }
|
||||
serde_path_to_error = "0.1"
|
||||
serde_yaml = "0.9.34"
|
||||
percent-encoding = "2.3"
|
||||
petgraph = "0.7"
|
||||
ploidy-pointer = { workspace = true, features = ["full"] }
|
||||
prettyplease = "0.2"
|
||||
proc-macro2 = { version = "1", default-features = false }
|
||||
quote = { version = "1", default-features = false }
|
||||
semver = { version = "1", features = ["serde"] }
|
||||
syn = { version = "2", default-features = false, features = [
|
||||
"parsing",
|
||||
"printing",
|
||||
] }
|
||||
textwrap = { version = "0.16", default-features = false, features = [
|
||||
"unicode-linebreak",
|
||||
"unicode-width",
|
||||
] }
|
||||
thiserror = "2"
|
||||
toml = { version = "0.9", default-features = false, features = [
|
||||
"display",
|
||||
"parse",
|
||||
"serde",
|
||||
] }
|
||||
unicase = "2"
|
||||
unicode-ident = "1"
|
||||
winnow = "0.7"
|
||||
|
||||
[lib]
|
||||
name = "ploidy"
|
||||
path = "src/lib.rs"
|
||||
ploidy-core = { workspace = true, features = ["rust"] }
|
||||
semver = "1"
|
||||
|
||||
[features]
|
||||
mimalloc = ["dep:mimalloc"]
|
||||
|
||||
+3
-11
@@ -6,15 +6,13 @@ use clap::{
|
||||
error::{Error as ClapError, ErrorKind as ClapErrorKind, Result as ClapResult},
|
||||
};
|
||||
use semver::Version;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::codegen::rust::CargoMetadata;
|
||||
use ploidy_core::codegen::rust::CargoMetadata;
|
||||
|
||||
const DEFAULT_VERSION: Version = Version::new(0, 1, 0);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Main {
|
||||
pub verbose: bool,
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
@@ -31,10 +29,7 @@ impl Main {
|
||||
Command::Codegen(args.into_command().map_err(|err| err.format(&mut cmd))?)
|
||||
}
|
||||
};
|
||||
Ok(Main {
|
||||
verbose: args.verbose,
|
||||
command,
|
||||
})
|
||||
Ok(Main { command })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,16 +189,13 @@ struct RustCodegenCommandArgs {
|
||||
check: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, clap::ValueEnum)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, clap::ValueEnum)]
|
||||
enum VersionBump {
|
||||
#[clap(name = "bump-major")]
|
||||
#[serde(rename = "bump-major")]
|
||||
Major,
|
||||
#[clap(name = "bump-minor")]
|
||||
#[serde(rename = "bump-minor")]
|
||||
Minor,
|
||||
#[clap(name = "bump-patch")]
|
||||
#[serde(rename = "bump-patch")]
|
||||
Patch,
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -2,16 +2,16 @@ use std::collections::BTreeMap;
|
||||
|
||||
use miette::{Context, IntoDiagnostic, Result};
|
||||
|
||||
use ploidy::{
|
||||
codegen::{
|
||||
rust::{self},
|
||||
write_to_disk,
|
||||
},
|
||||
config::{CodegenCommand, CodegenCommandLanguage, Command, Main},
|
||||
use ploidy_core::{
|
||||
codegen::{rust, write_to_disk},
|
||||
ir::IrSpec,
|
||||
parse::Document,
|
||||
};
|
||||
|
||||
mod config;
|
||||
|
||||
use self::config::{CodegenCommand, CodegenCommandLanguage, Command, Main};
|
||||
|
||||
#[cfg(feature = "mimalloc")]
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
Reference in New Issue
Block a user