Skip to content

Commit

Permalink
Merge pull request #3 from igtm/feature/case
Browse files Browse the repository at this point in the history
[fix] default behavior doesn't change props case. you can change it from config
  • Loading branch information
igtm committed Jun 21, 2023
2 parents 155d116 + 44185c0 commit 65c49b2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "openapi-yup-generator"
version = "0.0.7"
version = "0.0.8"
edition = "2021"
authors = ["igtm"]
description = "CLI tool for generating yup definitions from openapi3.yaml"
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -48,6 +48,7 @@ place `openapi-yup-generator-config.jsonc` on your working directory
// "description_as_label": false,
// "file": "openapi3.yaml",
// "out": "yup-defs.js",
// "case": "snake" // or "camel"
}
```

Expand Down
3 changes: 2 additions & 1 deletion examples/openapi-yup-generator-config.jsonc
@@ -1,5 +1,6 @@
{
"description_as_label": true,
// "input": "openapi3.yaml",
// "output": "yup-defs.js"
// "output": "yup-defs.js",
// "case": "snake" // or "camel"
}
19 changes: 15 additions & 4 deletions src/main.rs
Expand Up @@ -168,11 +168,22 @@ fn get_str_from_schema(
for (prop_name, p) in x.properties.iter() {
let nested_indent_str = &indent_str_curry(indent_str(FIELD_INDENTS.to_owned()));

// [optional] case
let mut cased_prop_name = prop_name.to_owned();
if let Some(i) = config.get_string("case") {
match i.to_string().as_str() {
"camel" => {
cased_prop_name = prop_name.to_case(Case::Camel);
}
"snake" => {
cased_prop_name = prop_name.to_case(Case::Snake);
}
_ => {}
}
}

// prop
str.push_str(&nested_indent_str(format!(
"{}: ",
prop_name.to_case(Case::Camel)
)));
str.push_str(&nested_indent_str(format!("{}: ", cased_prop_name)));

if let Some(any_schema_type2_item) = resolve(s, &p.to_owned().unbox()) {
str.push_str(&get_str_from_schema(
Expand Down

0 comments on commit 65c49b2

Please sign in to comment.