public string GetResponseType(Operation method, EndPoint resource, Payload mimeType, string key, string responseCode, string fullUrl) { string returnType = null; returnType = GetNamedReturnType(method, resource, mimeType, fullUrl); if (!string.IsNullOrWhiteSpace(returnType) && RamlTypesHelper.IsPrimitiveOrSchemaObject(returnType, schemaObjects)) { return(returnType); } if (ResponseHasKey(key)) { return(GetReturnTypeFromResponseByKey(key)); } var responseKey = key + ParserHelpers.GetStatusCode(responseCode) + GeneratorServiceBase.ResponseContentSuffix; if (ResponseHasKey(responseKey)) { return(GetReturnTypeFromResponseByKey(responseKey)); } if (linkKeysWithObjectNames.ContainsKey(key)) { var linkedKey = linkKeysWithObjectNames[key]; if (ResponseHasKey(linkedKey)) { return(GetReturnTypeFromResponseByKey(linkedKey)); } } if (linkKeysWithObjectNames.ContainsKey(responseKey)) { var linkedKey = linkKeysWithObjectNames[responseKey]; if (ResponseHasKey(linkedKey)) { return(GetReturnTypeFromResponseByKey(linkedKey)); } } returnType = DecodeResponseRaml1Type(returnType); return(returnType); }
public GeneratorParameter GetRequestParameter(string key, Operation method, EndPoint resource, string fullUrl, IEnumerable <string> defaultMediaTypes) { if (method.Request == null || !method.Request.Payloads.Any()) { return new GeneratorParameter { Name = "content", Type = "string" } } ; var mimeType = GetMimeType(method.Request.Payloads, defaultMediaTypes); var type = NewNetTypeMapper.GetNetType(mimeType, schemaObjects, null, enums); if (RamlTypesHelper.IsPrimitiveOrSchemaObject(type, schemaObjects)) { return(new GeneratorParameter //TODO: check { Name = string.IsNullOrWhiteSpace(mimeType.Name) ? GetParameterName(type) : GetParameterName(mimeType.Name), Description = mimeType.Description, Type = type }); } var apiObjectByKey = GetRequestApiObjectByKey(key); if (apiObjectByKey != null) { return(CreateGeneratorParameter(apiObjectByKey)); } apiObjectByKey = GetRequestApiObjectByKey(NetNamingMapper.GetObjectName(key)); if (apiObjectByKey != null) { return(CreateGeneratorParameter(apiObjectByKey)); } var requestKey = key + GeneratorServiceBase.RequestContentSuffix; apiObjectByKey = GetRequestApiObjectByKey(requestKey); if (apiObjectByKey != null) { return(CreateGeneratorParameter(apiObjectByKey)); } if (linkKeysWithObjectNames.ContainsKey(key)) { var linkedKey = linkKeysWithObjectNames[key]; apiObjectByKey = GetRequestApiObjectByKey(linkedKey); if (apiObjectByKey != null) { return(CreateGeneratorParameter(apiObjectByKey)); } } if (linkKeysWithObjectNames.ContainsKey(requestKey)) { var linkedKey = linkKeysWithObjectNames[requestKey]; apiObjectByKey = GetRequestApiObjectByKey(linkedKey); if (apiObjectByKey != null) { return(CreateGeneratorParameter(apiObjectByKey)); } } return(new GeneratorParameter { Name = "content", Type = "string" }); //if (mimeType != null) //{ // if (mimeType.Type != "object" && !string.IsNullOrWhiteSpace(mimeType.Type)) // { // var apiObject = GetRequestApiObjectWhenNamed(method, resource, mimeType.Type, fullUrl); // if (apiObject != null) // { // var generatorParameter = new GeneratorParameter // { // Name = apiObject.Name.ToLower(), // Type = GetParamType(mimeType, apiObject), // //Type = DecodeRequestRaml1Type(RamlTypesHelper.GetTypeFromApiObject(apiObject)), // Description = apiObject.Description // }; // return generatorParameter; // } // } // if (!string.IsNullOrWhiteSpace(mimeType.Schema)) // { // var apiObject = GetRequestApiObjectWhenNamed(method, resource, mimeType.Schema, fullUrl); // if (apiObject != null) // return CreateGeneratorParameter(apiObject); // } //} //if (resource.Type != null && resource.Type.Any() && // resourceTypes.Any(rt => rt.ContainsKey(resource.GetSingleType()))) //{ // var verb = RamlTypesHelper.GetResourceTypeVerb(method, resource, resourceTypes); // if (verb != null && verb.Body != null && !string.IsNullOrWhiteSpace(verb.Body.Schema)) // { // var apiObject = GetRequestApiObjectWhenNamed(method, resource, verb.Body.Schema, fullUrl); // if (apiObject != null) // return CreateGeneratorParameter(apiObject); // } // if (verb != null && verb.Body != null && !string.IsNullOrWhiteSpace(verb.Body.Type)) // { // var apiObject = GetRequestApiObjectWhenNamed(method, resource, verb.Body.Type, fullUrl); // if (apiObject != null) // { // var generatorParameter = new GeneratorParameter // { // Name = apiObject.Name.ToLower(), // Type = DecodeRequestRaml1Type(RamlTypesHelper.GetTypeFromApiObject(apiObject)), // Description = apiObject.Description // }; // return generatorParameter; // } // return new GeneratorParameter { Name = "content", Type = DecodeRequestRaml1Type(verb.Body.Type) }; // } //} //if (mimeType != null) //{ // string type; // if(!string.IsNullOrWhiteSpace(mimeType.Type)) // type = mimeType.Type; // else // type = mimeType.Schema; // if (!string.IsNullOrWhiteSpace(type)) // { // var raml1Type = DecodeRequestRaml1Type(type); // if (!string.IsNullOrWhiteSpace(raml1Type)) // return new GeneratorParameter {Name = "content", Type = raml1Type}; // } //} //return new GeneratorParameter { Name = "content", Type = "string" }; }
public GeneratorParameter GetRequestParameter(string key, Operation method, EndPoint resource, string fullUrl, IEnumerable <string> defaultMediaTypes) { if (method.Request == null || !method.Request.Payloads.Any()) { return new GeneratorParameter { Name = "content", Type = "string" } } ; var mimeType = GetMimeType(method.Request.Payloads, defaultMediaTypes); var type = NewNetTypeMapper.GetNetType(mimeType, schemaObjects, schemaRequestObjects, enums); if (RamlTypesHelper.IsPrimitiveOrSchemaObject(type, schemaObjects) || RamlTypesHelper.IsPrimitiveOrSchemaObject(type, schemaRequestObjects)) { return(new GeneratorParameter { Name = string.IsNullOrWhiteSpace(mimeType.Name) ? GetParameterName(type) : GetParameterName(mimeType.Name), Description = mimeType.Description, Type = type }); } //var apiObjectByKey = GetRequestApiObjectByKey(key); //if (apiObjectByKey != null) // return CreateGeneratorParameter(apiObjectByKey); //apiObjectByKey = GetRequestApiObjectByKey(NetNamingMapper.GetObjectName(key)); //if (apiObjectByKey != null) // return CreateGeneratorParameter(apiObjectByKey); var requestKey = key + GeneratorServiceBase.RequestContentSuffix; //apiObjectByKey = GetRequestApiObjectByKey(requestKey); //if (apiObjectByKey != null) // return CreateGeneratorParameter(apiObjectByKey); ApiObject apiObjectByKey; if (linkKeysWithObjectNames.ContainsKey(key)) { var linkedKey = linkKeysWithObjectNames[key]; apiObjectByKey = GetRequestApiObjectByKey(linkedKey); if (apiObjectByKey != null) { return(CreateGeneratorParameter(apiObjectByKey)); } } if (linkKeysWithObjectNames.ContainsKey(requestKey)) { var linkedKey = linkKeysWithObjectNames[requestKey]; apiObjectByKey = GetRequestApiObjectByKey(linkedKey); if (apiObjectByKey != null) { return(CreateGeneratorParameter(apiObjectByKey)); } } return(new GeneratorParameter { Name = "content", Type = "string" }); }