Skip to content

Commit e2741cf

Browse files
committed
Fix compile error when no features are enabled.
1 parent 7b3fc93 commit e2741cf

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2b9cb12dee9e3b26032c42d074075fe0
1+
9d05f56662ab4fb3602802ce918711b3

imageflow_core/src/json/endpoints/v1.rs

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -522,50 +522,58 @@ fn hash_files_relevant_to_schema_and_compare() -> io::Result<()> {
522522
let schema_name = OPENAPI_SCHEMA_V1_JSON_NAME;
523523

524524
if current_hash.as_str() != embedded_hash {
525-
if cfg!(feature = "schema-export") {
526-
eprintln!("Schema-relevant files changed. Regenerating OpenAPI schema and hash.");
527-
528-
let new_schema_json = generate_openapi_schema_json()
529-
.expect("Failed to generate OpenAPI schema JSON");
530-
531-
532-
let cargo_manifest_dir = env!("CARGO_MANIFEST_DIR");
533-
let current_dir = Path::new(cargo_manifest_dir).join("src/json/endpoints");
534-
535-
let hash_file_path = current_dir.join(OPENAPI_SCHEMA_V1_JSON_HASH_NAME);
536-
let schema_file_path = current_dir.join(OPENAPI_SCHEMA_V1_JSON_NAME);
537-
// if current_dir doesn't exist, fail with a message
538-
if !current_dir.exists() {
539-
panic!("Current directory does not exist: {}", current_dir.display());
540-
}
541-
542-
543-
fs::write(&schema_file_path, &new_schema_json)?;
544-
eprintln!("Wrote updated schema to: {}", schema_file_path.display());
545-
546-
fs::write(&hash_file_path, &current_hash)?;
547-
eprintln!("Wrote updated hash to: {}", hash_file_path.display());
548-
549-
eprintln!(
550-
"OpenAPI schema ({}) and hash ({}) \
551-
were updated because relevant source files changed. Please review and commit \
552-
the changes.",
553-
schema_name, hash_name
554-
);
555-
} else {
556-
panic!(
557-
"OpenAPI schema definition is outdated. Please run `cargo test --features schema-export`
558-
to regenerate the schema and hash file, then commit the changes to both '{}' and '{}'.",
559-
hash_name, schema_name
560-
);
561-
}
525+
schema_update(hash_name, schema_name)?;
562526
} else {
563527
println!("OpenAPI schema hash matches.");
564528
}
565529

566530
Ok(())
567531
}
568532

533+
#[cfg(all(not(feature = "schema-export"), test))]
534+
pub fn schema_update(hash_name: &str, schema_name: &str) -> io::Result<()>{
535+
panic!(
536+
"OpenAPI schema definition is outdated. Please run `cargo test --features schema-export,json-schema`
537+
to regenerate the schema and hash file, then commit the changes to both '{}' and '{}'.",
538+
hash_name, schema_name
539+
);
540+
}
541+
#[cfg(all(feature = "schema-export", test))]
542+
pub fn schema_update(hash_name: &str, schema_name: &str) -> io::Result<()>{
543+
let current_hash = hash_files_relevant_to_schema();
544+
545+
eprintln!("Schema-relevant files changed. Regenerating OpenAPI schema and hash.");
546+
547+
let new_schema_json = generate_openapi_schema_json()
548+
.expect("Failed to generate OpenAPI schema JSON");
549+
550+
551+
let cargo_manifest_dir = env!("CARGO_MANIFEST_DIR");
552+
let current_dir = Path::new(cargo_manifest_dir).join("src/json/endpoints");
553+
554+
let hash_file_path = current_dir.join(OPENAPI_SCHEMA_V1_JSON_HASH_NAME);
555+
let schema_file_path = current_dir.join(OPENAPI_SCHEMA_V1_JSON_NAME);
556+
// if current_dir doesn't exist, fail with a message
557+
if !current_dir.exists() {
558+
panic!("Current directory does not exist: {}", current_dir.display());
559+
}
560+
561+
562+
fs::write(&schema_file_path, &new_schema_json)?;
563+
eprintln!("Wrote updated schema to: {}", schema_file_path.display());
564+
565+
fs::write(&hash_file_path, &current_hash)?;
566+
eprintln!("Wrote updated hash to: {}", hash_file_path.display());
567+
568+
eprintln!(
569+
"OpenAPI schema ({}) and hash ({}) \
570+
were updated because relevant source files changed. Please review and commit \
571+
the changes.",
572+
schema_name, hash_name
573+
);
574+
575+
Ok(())
576+
}
569577

570578
fn get_create_doc_dir() -> std::path::PathBuf {
571579
let path = ::imageflow_types::version::crate_parent_folder().join(Path::new("target/doc"));

0 commit comments

Comments
 (0)