modelina
modelina copied to clipboard
Add json tags to Go generated struct
Reason/Context
Current generated Go structs does not have json tags. Those are useful for encoding/decoding JSON.
Description
Currently, for a given doc like:
const doc = {
$id: "Address",
type: "object",
properties: {
street_name: { type: "string" },
city: { type: "string", description: "City description" },
house_number: { type: "number" },
marriage: { type: "boolean", description: "Status if marriage live in given house" },
pet_names: { type: "array", items: { type: "string" } },
state: { type: "string", enum: ["Texas", "Alabama", "California", "other"] },
},
required: ["street_name", "city", "state", "house_number", "state"],
};
The generator generates the following struct:
// Address represents a Address model.
type Address struct {
StreetName string
City string
HouseNumber float64
Marriage bool
PetNames []string
State *State
}
// State represents an enum of string.
type State string
After adding Json tags would look like:
// Address represents a Address model.
type Address struct {
StreetName string `json:"street_name"`
City string `json:"city"`
HouseNumber float64 `json:"house_number"`
Marriage bool `json:"marriage"`
PetNames []string `json:"pet_names"`
State *State `json:"state"`
}
// State represents an enum of string.
type State string
Related issue
https://github.com/asyncapi/modelina/issues/262
This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
I think that it's still important? @smoya :)
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
@jonaslagoni I think this is still relevant.
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
Any progress on this? Without this, it renders the code generation for different languages kind of useless as for example the current GOLANG structs are not in sync with their TS counterparts
For ref: Tackled again by https://github.com/asyncapi/modelina/pull/867, but stale?
Its still definitely needed... I just dont have the bandwidth to finish the PR, feel free to take it over, happy to help facilitate this 👍
It just looks like a lot to me, judging from the amount of code (changes) and I am not sure exactly where to start with it. As far as a (my) simple use case goes it would be a sufficient start to have the json tags simply be the lowerCamelCase variant of the field name in the struct to give us compability to other generated sources
@H3rby7 you can always change the naming rules: https://github.com/asyncapi/modelina/blob/master/docs/advanced.md#changing-the-constrain-rules
const generator = new GoGenerator({
constraints: {
propertyKey: ({objectPropertyModel}) => {return objectPropertyModel.propertyName;}
}
});
This means that it takes the input property names directly as is, without making sure any arbitrary input property name is valid in Go.
@jonaslagoni do you think someone without any prior idea of code generation will be able to take this up ?
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
still valid? @jonaslagoni @smoya