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>)
| 592 | /// |
| 593 | /// Error if schema is not available or if there is an error getting the schema |
| 594 | pub 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 | /// |
no test coverage detected