punc request and response moved to punc schemas
This commit is contained in:
57
src/lib.rs
57
src/lib.rs
@ -140,15 +140,24 @@ fn cache_json_schemas(enums: JsonB, types: JsonB, puncs: JsonB) -> JsonB {
|
||||
.unwrap_or(false);
|
||||
let punc_schema_type = if is_public { SchemaType::PublicPunc } else { SchemaType::PrivatePunc };
|
||||
|
||||
// Add punc local schemas as resources (from schemas field) - use $id directly (universal)
|
||||
// Add punc schemas from the 'schemas' array
|
||||
if let Some(schemas_raw) = punc_obj.get("schemas") {
|
||||
if let Some(schemas_array) = schemas_raw.as_array() {
|
||||
for schema_def in schemas_array {
|
||||
if let Some(schema_id) = schema_def.get("$id").and_then(|v| v.as_str()) {
|
||||
if let Err(e) = add_schema_resource(&mut compiler, schema_id, schema_def.clone(), SchemaType::Type, &mut errors) {
|
||||
let request_schema_id = format!("{}.request", punc_name);
|
||||
let response_schema_id = format!("{}.response", punc_name);
|
||||
|
||||
let schema_type_for_def = if schema_id == request_schema_id || schema_id == response_schema_id {
|
||||
punc_schema_type
|
||||
} else {
|
||||
SchemaType::Type // For local/nested schemas
|
||||
};
|
||||
|
||||
if let Err(e) = add_schema_resource(&mut compiler, schema_id, schema_def.clone(), schema_type_for_def, &mut errors) {
|
||||
errors.push(json!({
|
||||
"code": "PUNC_LOCAL_SCHEMA_RESOURCE_FAILED",
|
||||
"message": format!("Failed to add local schema resource '{}' for punc '{}'", schema_id, punc_name),
|
||||
"code": "PUNC_SCHEMA_RESOURCE_FAILED",
|
||||
"message": format!("Failed to add schema resource '{}' for punc '{}'", schema_id, punc_name),
|
||||
"details": {
|
||||
"punc_name": punc_name,
|
||||
"schema_id": schema_id,
|
||||
@ -162,46 +171,6 @@ fn cache_json_schemas(enums: JsonB, types: JsonB, puncs: JsonB) -> JsonB {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add request schema as resource if present - use {punc_name}.request
|
||||
if let Some(request_schema) = punc_obj.get("request") {
|
||||
if !request_schema.is_null() {
|
||||
let request_schema_id = format!("{}.request", punc_name);
|
||||
if let Err(e) = add_schema_resource(&mut compiler, &request_schema_id, request_schema.clone(), punc_schema_type, &mut errors) {
|
||||
errors.push(json!({
|
||||
"code": "PUNC_REQUEST_SCHEMA_RESOURCE_FAILED",
|
||||
"message": format!("Failed to add request schema resource for punc '{}'", punc_name),
|
||||
"details": {
|
||||
"punc_name": punc_name,
|
||||
"schema_id": request_schema_id,
|
||||
"cause": format!("{}", e)
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
all_schema_ids.push(request_schema_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add response schema as resource if present - use {punc_name}.response
|
||||
if let Some(response_schema) = punc_obj.get("response") {
|
||||
if !response_schema.is_null() {
|
||||
let response_schema_id = format!("{}.response", punc_name);
|
||||
if let Err(e) = add_schema_resource(&mut compiler, &response_schema_id, response_schema.clone(), punc_schema_type, &mut errors) {
|
||||
errors.push(json!({
|
||||
"code": "PUNC_RESPONSE_SCHEMA_RESOURCE_FAILED",
|
||||
"message": format!("Failed to add response schema resource for punc '{}'", punc_name),
|
||||
"details": {
|
||||
"punc_name": punc_name,
|
||||
"schema_id": response_schema_id,
|
||||
"cause": format!("{}", e)
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
all_schema_ids.push(response_schema_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user