Skip to content

Conversation

@michaeltlombardi
Copy link
Collaborator

PR Summary

This change defines two new types:

  • ExitCode as a lightweight wrapper around i32 where we can control serialization and deserialization with strings as the serialized format instead of an integer.

  • ExitCodesMap as a lightweight wrapper for HashMap<ExitCode, String>. It implements a helper function for determining whether the map is empty or default and defines the default map for exit 0 (success) and 1 (error).

    The ExitCodesMap includes a hand-implementation of JsonSchema to match the canonical JSON Schema, which schemars won't generate from the struct definition.

This change not only enables us to provide the canonical JSON Schema for exit code fields in a reusable way, it also removes the need to maintain a converter function for transforming the exit codes map from HashMap<String, String> to HashMap<i32, String>.

This change also:

  • Updates the ResourceManifest and ExtensionManifest structs to use the ExitCodesMap for the exit_codes field.
  • Updates the implementations of run_process_async() and invoke_command() to use the new type.
  • Removes the now-erroneous convert_hashmap_string_keys_to_i32() function, since the exit codes are correctly typed from deserialization/instance creation.

Note

Leaving this in draft until #1350 is merged, as it includes new development dependencies useful for quickly defining test cases for the newtypes.

PR Context

Prior to this change, the exit_codes fields for the resource and extension manifests defined the map of exit codes to their semantic meanings as Option<HashMap<String, String>>.

As part of schema canonicalization, we need to provide a canonical JSON Schema for that object. Unfortunately, because we don't own either the JsonSchema trait or HashMap<T> type, we need to use a newtype wrapper.

Prior to this change, the `exit_codes` fields for the resource and
extension manifests defined the map of exit codes to their semantic
meanings as `Option<HashMap<String, String>>`.

As part of schema canonicalization, we need to provide a canonical
JSON Schema for that object. Unfortunately, because we don't own either
the `JsonSchema` trait or `HashMap<T>` type, we need to use a newtype
wrapper.

This change defines two new types:

- `ExitCode` as a lightweight wrapper around `i32` where we can control
  serialization and deserialization with strings as the serialized
  format instead of an integer.
- `ExitCodeMap` as a lightweight wrapper for `HashMap<ExitCode, String>`.
  It implements a helper function for determining whether the map is
  empty or default and defines the default map for exit `0` (success)
  and `1` (error).

  The `ExitCodeMap` includes a hand-implementation of `JsonSchema` to
  match the canonical JSON Schema, which `schemars` won't generate from
  the struct definition.

This change not only enables us to provide the canonical JSON Schema
for exit code fields in a reusable way, it also removes the need to
maintain a converter function for transforming the exit codes map from
`HashMap<String, String>` to `HashMap<i32, String>`.
This change updates the `exit_codes` fields for the `ResourceManifest`
and `ExtensionManifest` structs to use the new `ExitCodesMap` type
instead of `Option<HashMap<String, String>>`.

It also updates the `run_process_async()` and `invoke_command()`
functions to work with references to `ExitCodesMap` and removes the
now-extraneous `fn convert_hashmap_string_keys_to_i32()` function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant