-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(generate)!: embedded optional structs changed to pointers (#170)
* #131. fix(generate): now uses pointers for optional fields. update: all types. * #131. refactor(generate): extract the pointer string logic into addPointerIfOptional method in generate_utils * #131. update(generate): Primitives are no longer prefixed as pointers. * chore(generate): #131. Add tests to ensure no additional json fields are being added when marshalling and unmarshalling using the generated types. * docs(adr). #174. instantiated adr directory in docs. Add ADR for using pointers for non-primitive types * docs(readme): update readme w/ pointer example.
- Loading branch information
1 parent
633e9cb
commit 379d90a
Showing
31 changed files
with
865,546 additions
and
4,145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docs/adr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 1. Record architecture decisions | ||
|
||
Date: 2024-03-25 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
We need to record the architectural decisions made on this project. | ||
|
||
## Decision | ||
|
||
We will use Architecture Decision Records, as [described by Michael Nygard](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions). | ||
|
||
## Consequences | ||
|
||
See Michael Nygard's article, linked above. For a lightweight ADR toolset, see Nat Pryce's [adr-tools](https://github.com/npryce/adr-tools). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 2. Use pointers for non-primitive types | ||
|
||
Date: 2024-03-25 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
Initially, types were generated without pointers. When using `encoding/json`'s `json.Marshal` and `json.Unmarshal`, all fields, even those tagged with `omitempty`, were instantiated with empty values. This can cause problems when reading, editing, and writing `json` objects, as they no longer reflect the initial and intended state of the original `json`. This issue was not present in `yaml` documents using `gopkg.in/yaml.v3`. More context is available in this [proposal](https://github.com/golang/go/issues/11939). | ||
|
||
## Decision | ||
|
||
To better support consumers who implement OSCAL and the go-oscal types in `json`, we have decided that embedded `struct` objects and non-primitives in the go-oscal types should be pointers. This is the most conventional solution to prevent the instantiation of unused (`omitempty`) `json` fields. A more in-depth explanation of the `json` `omitempty` tag can be found [here](https://www.sohamkamani.com/golang/omitempty/). | ||
|
||
## Consequences | ||
- **Nil Checks**: Additional `nil` checks are required before accessing methods or fields on embedded structs. | ||
- **Initialization**: Pointers to embedded structs must be properly initialized before use. | ||
- **Interface Compatibility**: Interfaces that expect embedded structs may need to be adjusted to work with pointers. | ||
- **Serialization and Deserialization**: Correct handling of pointers is required to ensure proper serialization and deserialization. | ||
- **Memory Management**: Using pointers may increase memory usage compared to embedded structs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.