(schema Schema)
| 876 | } |
| 877 | |
| 878 | func GenStructFromSchema(schema Schema) string { |
| 879 | // Start out with struct { |
| 880 | objectParts := []string{"struct {"} |
| 881 | // Append all the field definitions |
| 882 | objectParts = append(objectParts, GenFieldsFromProperties(schema.Properties)...) |
| 883 | // Close the struct |
| 884 | if schema.HasAdditionalProperties { |
| 885 | objectParts = append(objectParts, |
| 886 | fmt.Sprintf("AdditionalProperties map[string]%s `json:\"-\"`", |
| 887 | additionalPropertiesType(schema))) |
| 888 | } |
| 889 | if len(schema.UnionElements) != 0 { |
| 890 | objectParts = append(objectParts, "union json.RawMessage") |
| 891 | } |
| 892 | objectParts = append(objectParts, "}") |
| 893 | return strings.Join(objectParts, "\n") |
| 894 | } |
| 895 | |
| 896 | // This constructs a Go type for a parameter, looking at either the schema or |
| 897 | // the content, whichever is available |
no test coverage detected