package postmangeneratorattributes /** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/apicollective/postman-generator-attributes/0.0.1-dev/go_1_5_client */ import ( "bytes" "encoding/json" "io" "io/apibuilder/spec" "strings" ) const UserAgent = "apibuilder app.apibuilder.io/apicollective/postman-generator-attributes/0.0.1-dev/go_1_5_client" const Version = "0.0.1-dev" const VersionMajor = 0 /** * A set of attribute names, that are recognized by Postman Generator */ type AttributeName string const ( AttributeNamePostmanBasicAuth AttributeName = "postman-basic-auth" AttributeNameObjectReference = "object-reference" AttributeNameValueSubstitute = "value-substitute" AttributeNameUNDEFINED = "UNDEFINED" ) func AttributeNameFromString(value string) AttributeName { switch strings.TrimSpace(strings.ToLower(value)) { case "postman-basic-auth": return AttributeNamePostmanBasicAuth case "object-reference": return AttributeNameObjectReference case "value-substitute": return AttributeNameValueSubstitute default: return AttributeNameUNDEFINED } } /** * Attribute instructs the generator to add Basic Auth info to the whole Postman * collection. Attribute should be defined on the root level of the ApiBuilder * specification */ type BasicAuth struct { Username string `json:"username"` Password string `json:"password"` } func BasicAuthFromMap(data interface{}) BasicAuth { b, err := json.Marshal(data) if err == nil { return BasicAuthFromJson(bytes.NewReader(b)) } else { panic(err) } } func BasicAuthFromJson(bytes io.Reader) BasicAuth { var basicAuth BasicAuth json.NewDecoder(bytes).Decode(&basicAuth) return basicAuth } /** * Attribute instructs the generator to add a setup step with the referenced entity * creation. This attribute should be attached to the field (that holds an * identifier) inside model or to the resource object (that holds operations and a * path with an identifier param). */ type ObjectReference struct { RelatedServiceNamespace string `json:"related_service_namespace"` ResourceType string `json:"resource_type"` OperationMethod spec.Method `json:"operation_method"` OperationPath string `json:"operation_path"` IdentifierField string `json:"identifier_field"` QueryParams map[string]string `json:"query_params,omitempty"` DeleteOperationPath string `json:"delete_operation_path,omitempty"` } func ObjectReferenceFromMap(data interface{}) ObjectReference { b, err := json.Marshal(data) if err == nil { return ObjectReferenceFromJson(bytes.NewReader(b)) } else { panic(err) } } func ObjectReferenceFromJson(bytes io.Reader) ObjectReference { var objectReference ObjectReference json.NewDecoder(bytes).Decode(&objectReference) return objectReference } /** * Attribute instructs the generator to substitute a field value (when generating * examples) with specified value or variable reference. Attribute should be * attached to a field inside model. */ type ValueSubstitute struct { Substitute string `json:"substitute"` } func ValueSubstituteFromMap(data interface{}) ValueSubstitute { b, err := json.Marshal(data) if err == nil { return ValueSubstituteFromJson(bytes.NewReader(b)) } else { panic(err) } } func ValueSubstituteFromJson(bytes io.Reader) ValueSubstitute { var valueSubstitute ValueSubstitute json.NewDecoder(bytes).Decode(&valueSubstitute) return valueSubstitute }