MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / GenStructFromSchema

Function GenStructFromSchema

pkg/codegen/schema.go:878–894  ·  view source on GitHub ↗
(schema Schema)

Source from the content-addressed store, hash-verified

876}
877
878func 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

Callers 3

GenerateGoSchemaFunction · 0.85
GenerateBodyDefinitionsFunction · 0.85
GenerateParamsTypesFunction · 0.85

Calls 2

GenFieldsFromPropertiesFunction · 0.85
additionalPropertiesTypeFunction · 0.85

Tested by

no test coverage detected