public override IModelType BuildServiceType(string serviceTypeName) { var swaggerParameter = Modeler.Unwrap(_swaggerParameter); // create service type var serviceType = swaggerParameter.In == ParameterLocation.Body ? swaggerParameter.Schema.GetBuilder(Modeler).BuildServiceType(serviceTypeName) : swaggerParameter.GetBuilder(Modeler).ParentBuildServiceType(serviceTypeName); return(serviceType); }
public Parameter Build() { string parameterName = _swaggerParameter.Name; SwaggerParameter unwrappedParameter = _swaggerParameter; if (_swaggerParameter.Reference != null) { unwrappedParameter = Modeler.Unwrap(_swaggerParameter); } if (unwrappedParameter.Schema != null && unwrappedParameter.Schema.Reference != null) { parameterName = unwrappedParameter.Schema.Reference.StripComponentsSchemaPath(); } if (parameterName == null) { parameterName = unwrappedParameter.Name; } var isRequired = unwrappedParameter.IsRequired || unwrappedParameter.In == AutoRest.Modeler.Model.ParameterLocation.Path; unwrappedParameter.IsRequired = isRequired; if (unwrappedParameter.Extensions.ContainsKey("x-ms-enum") && !unwrappedParameter.Schema.Extensions.ContainsKey("x-ms-enum")) { unwrappedParameter.Schema.Extensions["x-ms-enum"] = unwrappedParameter.Extensions["x-ms-enum"]; } IModelType parameterType = BuildServiceType(parameterName, isRequired); var parameter = New <Parameter>(new { Name = unwrappedParameter.Name, SerializedName = unwrappedParameter.Name, ModelType = parameterType, Location = (Core.Model.ParameterLocation)Enum.Parse(typeof(Core.Model.ParameterLocation), unwrappedParameter.In.ToString()) }); // translate allowReserved back to what "code-model-v1"-gen generators expect if (unwrappedParameter.AllowReserved.HasValue && !parameter.Extensions.ContainsKey("x-ms-skip-url-encoding")) { parameter.Extensions["x-ms-skip-url-encoding"] = unwrappedParameter.AllowReserved.Value; } PopulateParameter(parameter, unwrappedParameter); parameter.DeprecationMessage = unwrappedParameter.GetDeprecationMessage(EntityType.Parameter); if (_swaggerParameter.Reference != null) { var clientProperty = Modeler.CodeModel.Properties.FirstOrDefault(p => p.SerializedName == unwrappedParameter.Name); parameter.ClientProperty = clientProperty; } return(parameter); }
public override IModelType BuildServiceType(string serviceTypeName, bool required) { var swaggerParameter = Modeler.Unwrap(_swaggerParameter); // create service type if (swaggerParameter.In == ParameterLocation.Body) { if (swaggerParameter.Schema == null) { throw new Exception($"Invalid Swagger: Body parameter{(serviceTypeName == null ? "" : $" '{serviceTypeName}'")} missing 'schema'."); } return(swaggerParameter.Schema.GetBuilder(Modeler).BuildServiceType(serviceTypeName, swaggerParameter.IsRequired)); }
public override IType BuildServiceType(string serviceTypeName) { // Check if already generated if (serviceTypeName != null && Modeler.GeneratedTypes.ContainsKey(serviceTypeName)) { return(Modeler.GeneratedTypes[serviceTypeName]); } var swaggerParameter = Modeler.Unwrap(_swaggerParameter); // Generic type if (swaggerParameter.In != ParameterLocation.Body) { return(swaggerParameter.GetBuilder(Modeler).ParentBuildServiceType(serviceTypeName)); } // Contains a complex type schema return(swaggerParameter.Schema.GetBuilder(Modeler).BuildServiceType(serviceTypeName)); }
public Parameter Build() { string parameterName = _swaggerParameter.Name; SwaggerParameter unwrappedParameter = _swaggerParameter; if (_swaggerParameter.Reference != null) { unwrappedParameter = Modeler.Unwrap(_swaggerParameter); } if (unwrappedParameter.Schema != null && unwrappedParameter.Schema.Reference != null) { parameterName = unwrappedParameter.Schema.Reference.StripDefinitionPath(); } if (parameterName == null) { parameterName = unwrappedParameter.Name; } IModelType parameterType = BuildServiceType(parameterName); var parameter = New <Parameter>(new { Name = unwrappedParameter.Name, SerializedName = unwrappedParameter.Name, ModelType = parameterType, Location = (Core.Model.ParameterLocation)Enum.Parse(typeof(Core.Model.ParameterLocation), unwrappedParameter.In.ToString()) }); parameter.IsRequired = parameter.IsRequired || parameter.Location == Core.Model.ParameterLocation.Path; PopulateParameter(parameter, unwrappedParameter); if (_swaggerParameter.Reference != null) { var clientProperty = Modeler.CodeModel.Properties.FirstOrDefault(p => p.SerializedName.Value == unwrappedParameter.Name); parameter.ClientProperty = clientProperty; } return(parameter); }
public Parameter Build() { string parameterName = _swaggerParameter.Name; SwaggerParameter unwrappedParameter = _swaggerParameter; if (_swaggerParameter.Reference != null) { unwrappedParameter = Modeler.Unwrap(_swaggerParameter); } if (unwrappedParameter.Schema != null && unwrappedParameter.Schema.Reference != null) { parameterName = unwrappedParameter.Schema.Reference.StripDefinitionPath(); } if (parameterName == null) { parameterName = unwrappedParameter.Name; } IType parameterType = BuildServiceType(parameterName); var parameter = new Parameter { Name = unwrappedParameter.Name, SerializedName = unwrappedParameter.Name, Type = parameterType, Location = (Generator.ClientModel.ParameterLocation)Enum.Parse(typeof(Generator.ClientModel.ParameterLocation), unwrappedParameter.In.ToString()) }; parameter.IsRequired = parameter.IsRequired || parameter.Location == Generator.ClientModel.ParameterLocation.Path; PopulateParameter(parameter, unwrappedParameter); if (_swaggerParameter.Reference != null) { var clientProperty = Modeler.ServiceClient.Properties.First(p => p.Name == unwrappedParameter.Name); parameter.ClientProperty = clientProperty; } return(parameter); }
public Parameter Build() { string parameterName = _swaggerParameter.Name; SwaggerParameter unwrappedParameter = _swaggerParameter; if (_swaggerParameter.Reference != null) { unwrappedParameter = Modeler.Unwrap(_swaggerParameter); } if (unwrappedParameter.Schema != null && unwrappedParameter.Schema.Reference != null) { parameterName = unwrappedParameter.Schema.Reference.StripDefinitionPath(); } if (parameterName == null) { parameterName = unwrappedParameter.Name; } IType parameterType = BuildServiceType(parameterName); var parameter = new Parameter { Name = unwrappedParameter.Name, SerializedName = unwrappedParameter.Name, Type = parameterType, IsRequired = unwrappedParameter.IsRequired, DefaultValue = unwrappedParameter.Default, Location = (Generator.ClientModel.ParameterLocation)Enum.Parse(typeof(Generator.ClientModel.ParameterLocation), unwrappedParameter.In.ToString()) }; parameter.IsRequired = parameter.IsRequired || parameter.Location == Generator.ClientModel.ParameterLocation.Path; SetConstraints(parameter.Constraints, unwrappedParameter); parameter.CollectionFormat = unwrappedParameter.CollectionFormat; parameter.Documentation = unwrappedParameter.Description; if (_swaggerParameter.Reference != null) { var clientProperty = Modeler.ServiceClient.Properties.First(p => p.Name == unwrappedParameter.Name); parameter.ClientProperty = clientProperty; } var enumType = parameterType as EnumType; if (enumType != null) { if (parameter.Documentation == null) { parameter.Documentation = string.Empty; } else { parameter.Documentation = parameter.Documentation.TrimEnd('.') + ". "; } parameter.Documentation += "Possible values for this parameter include: " + string.Join(", ", enumType.Values.Select(v => string.Format(CultureInfo.InvariantCulture, "'{0}'", v.Name))); } unwrappedParameter.Extensions.ForEach(e => parameter.Extensions[e.Key] = e.Value); return(parameter); }