MCPcopy Create free account
hub / github.com/PowerShell/DSC / get_schema

Function get_schema

lib/dsc-lib/src/dscresources/command_resource.rs:594–617  ·  view source on GitHub ↗

Get the JSON schema for a resource # Arguments `resource` - The resource manifest # Errors Error if schema is not available or if there is an error getting the schema

(resource: &DscResource, target_resource: Option<&DscResource>)

Source from the content-addressed store, hash-verified

592///
593/// Error if schema is not available or if there is an error getting the schema
594pub fn get_schema(resource: &DscResource, target_resource: Option<&DscResource>) -> Result<String, DscError> {
595 let Some(manifest) = &resource.manifest else {
596 return Err(DscError::MissingManifest(resource.type_name.to_string()));
597 };
598 let Some(schema_kind) = manifest.schema.as_ref() else {
599 return Err(DscError::SchemaNotAvailable(resource.type_name.to_string()));
600 };
601
602 match schema_kind {
603 SchemaKind::Command(command) => {
604 let resource_type = match target_resource {
605 Some(r) => r.type_name.clone(),
606 None => resource.type_name.clone(),
607 };
608 let args = process_schema_args(command.args.as_ref(), &CommandResourceInfo { type_name: resource_type, path: None });
609 let (_exit_code, stdout, _stderr) = invoke_command(&command.executable, args, None, Some(&resource.directory), None, manifest.exit_codes.as_ref())?;
610 Ok(stdout)
611 },
612 SchemaKind::Embedded(schema) => {
613 let json = serde_json::to_string(schema)?;
614 Ok(json)
615 },
616 }
617}
618
619/// Invoke the export operation on a resource
620///

Callers 2

schemaMethod · 0.70

Calls 4

process_schema_argsFunction · 0.85
invoke_commandFunction · 0.70
to_stringFunction · 0.50
as_refMethod · 0.45

Tested by

no test coverage detected