feat(import): preserve supported HTTP contracts
This commit is contained in:
1 parent
083974c27f
commit
f8ee7c9bfe
87 files changed
+7496
-534
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use crank_mapping::{MappingRule, MappingSet};
|
||||
use crank_schema::{Schema, SchemaKind};
|
||||
|
||||
use crate::rest::model::{RestImportParameter, RestParameterLocation};
|
||||
use crate::rest::model::RestParameterLocation;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct BodyFieldMapping {
|
||||
@@ -10,8 +10,17 @@ pub struct BodyFieldMapping {
|
||||
pub required: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ParameterFieldMapping {
|
||||
pub input_name: String,
|
||||
pub wire_name: String,
|
||||
pub location: RestParameterLocation,
|
||||
pub required: bool,
|
||||
pub default_value: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
pub fn input_mapping(
|
||||
parameters: &[RestImportParameter],
|
||||
parameters: &[ParameterFieldMapping],
|
||||
body_fields: &[BodyFieldMapping],
|
||||
) -> MappingSet {
|
||||
let mut rules = Vec::new();
|
||||
@@ -20,19 +29,25 @@ pub fn input_mapping(
|
||||
RestParameterLocation::Path => "$.request.path",
|
||||
RestParameterLocation::Query => "$.request.query",
|
||||
RestParameterLocation::Header => "$.request.headers",
|
||||
// Cookies travel through a distinct mapping root. Runtime turns
|
||||
// this object into the single wire `Cookie` header at the adapter
|
||||
// boundary; source values cannot inject an arbitrary header.
|
||||
RestParameterLocation::Cookie => "$.request.cookies",
|
||||
};
|
||||
rules.push(MappingRule {
|
||||
source: format!("$.mcp.{}", parameter.name),
|
||||
target: format!("{target_root}.{}", parameter.name),
|
||||
source: format!("$.mcp.{}", parameter.input_name),
|
||||
target: format!("{target_root}.{}", parameter.wire_name),
|
||||
required: parameter.required,
|
||||
default_value: None,
|
||||
default_value: parameter.default_value.clone(),
|
||||
transform: None,
|
||||
condition: None,
|
||||
notes: None,
|
||||
});
|
||||
}
|
||||
for field in body_fields {
|
||||
let target = if field.body_path.is_empty() {
|
||||
let target = if field.body_path == "__content_type" {
|
||||
"$.request.body_content_type".to_owned()
|
||||
} else if field.body_path.is_empty() || field.body_path == "__body" {
|
||||
"$.request.body".to_owned()
|
||||
} else {
|
||||
format!("$.request.body.{}", field.body_path)
|
||||
|
||||
Reference in new issue
Block a user