private ParameterSpec CreateParameterSpec(ApiParameterDescription apiParamDesc, string apiPath, ModelSpecRegistrar modelSpecRegistrar) { var paramType = ""; switch (apiParamDesc.Source) { case ApiParameterSource.FromBody: paramType = "body"; break; case ApiParameterSource.FromUri: paramType = apiPath.Contains(String.Format("{{{0}}}", apiParamDesc.Name)) ? "path" : "query"; break; } var paramSpec = new ParameterSpec { ParamType = paramType, Name = apiParamDesc.Name, Description = apiParamDesc.Documentation, Required = !apiParamDesc.ParameterDescriptor.IsOptional }; IEnumerable <ModelSpec> complexSpecs; var modelSpec = _modelSpecGenerator.TypeToModelSpec(apiParamDesc.ParameterDescriptor.ParameterType, out complexSpecs); modelSpecRegistrar.RegisterMany(complexSpecs); if (modelSpec.Type == "object") { paramSpec.Type = modelSpec.Id; } else { paramSpec.Type = modelSpec.Type; paramSpec.Format = modelSpec.Format; paramSpec.Items = modelSpec.Items; paramSpec.Enum = modelSpec.Enum; } return(paramSpec); }
private ParameterSpec CreateParameterSpec(ApiParameterDescription apiParamDesc, string apiPath, ModelSpecRegistrar modelSpecRegistrar) { var paramType = ""; switch (apiParamDesc.Source) { case ApiParameterSource.FromBody: paramType = "body"; break; case ApiParameterSource.FromUri: paramType = apiPath.Contains(String.Format("{{{0}}}", apiParamDesc.Name)) ? "path" : "query"; break; } var paramSpec = new ParameterSpec { ParamType = paramType, Name = apiParamDesc.Name, Description = apiParamDesc.Documentation, Required = !apiParamDesc.ParameterDescriptor.IsOptional }; IEnumerable<ModelSpec> complexSpecs; var modelSpec = _modelSpecGenerator.TypeToModelSpec(apiParamDesc.ParameterDescriptor.ParameterType, out complexSpecs); modelSpecRegistrar.RegisterMany(complexSpecs); if (modelSpec.Type == "object") { paramSpec.Type = modelSpec.Id; } else { paramSpec.Type = modelSpec.Type; paramSpec.Format = modelSpec.Format; paramSpec.Items = modelSpec.Items; paramSpec.Enum = modelSpec.Enum; } return paramSpec; }
private ParameterSpec GenerateParameterSpec(ApiParameterDescription parameterDescription, string apiPath, ModelSpecMap modelSpecMap) { var paramType = ""; switch (parameterDescription.Source) { case ApiParameterSource.FromBody: paramType = "body"; break; case ApiParameterSource.FromUri: paramType = apiPath.Contains(parameterDescription.Name) ? "path" : "query"; break; } var paramSpec = new ParameterSpec { ParamType = paramType, Name = parameterDescription.Name, Description = parameterDescription.Documentation, Required = !parameterDescription.ParameterDescriptor.IsOptional }; var modelSpec = modelSpecMap.FindOrCreateFor(parameterDescription.ParameterDescriptor.ParameterType); if (modelSpec.Type == "object") { paramSpec.Type = modelSpec.Id; } else { paramSpec.Type = modelSpec.Type; paramSpec.Format = modelSpec.Format; paramSpec.Items = modelSpec.Items; paramSpec.Enum = modelSpec.Enum; } return paramSpec; }