protected virtual void AttachBasicProps(OpenApiSchema schema, OpenApiObject xProps, OpenApiObject templateOptions, LinkGenerator linkGenerator) { if (ClassName != null) { xProps["className"] = OpenApiExtensions.ToOpenApi(ClassName); } if (DefaultValue != null) { xProps["defaultValue"] = OpenApiExtensions.ToOpenApi(DefaultValue); } if (Wrappers != null) { var arr = new OpenApiArray(); arr.AddRange(from object o in Wrappers select OpenApiExtensions.ToOpenApi(o)); xProps["wrappers"] = arr; } if (Disabled) { templateOptions["disabled"] = OpenApiExtensions.ToOpenApi(true); } }
public void Apply(OpenApiSchema model, SchemaFilterContext context) { // Patch only root level schemas, and not the members(properties) schemas of other schemas if (!context.Type.IsEnum || context.MemberInfo != null) { return; } model.Enum = Enum.GetValues(context.Type).Cast <Enum>() .Select(value => (IOpenApiAny) new OpenApiString(value.GetCustomValue().ToString())) .ToList(); var templateOptions = model.Extensions.GetOrSetDefault("x-templateOptions", new OpenApiObject()); var optionsArray = templateOptions.GetOrSetDefault("options", new OpenApiArray()); optionsArray.AddRange(Enum.GetValues(context.Type).Cast <Enum>() .Select(enumValue => { var option = new OpenApiObject { ["value"] = OpenApiExtensions.ToOpenApi(enumValue.GetCustomValue()), ["label"] = new OpenApiString(enumValue.GetDisplayName()), }; if (enumValue.GetDisplayDescription() is { } s&& !string.IsNullOrEmpty(s)) { option["description"] = new OpenApiString(s); } return(option); })); }
private void ProcessFieldAttributes(OpenApiSchema schema, OpenApiObject templateOptions, PropertyInfo propertyInfo, Type declaringType, List <ValidatorModel> validators, out FormlyFieldAttribute fieldAttr) { fieldAttr = null; var xProps = new OpenApiObject(); foreach (var fieldPropertyAttribute in GetAttributes <FormlyFieldPropAttribute>(propertyInfo, declaringType)) { xProps[fieldPropertyAttribute.FullPath] = OpenApiExtensions.ToOpenApi(fieldPropertyAttribute.Value); } foreach (var patchAttr in GetAttributes <FormlyConfigPatcherAttribute>(propertyInfo, declaringType)) { patchAttr.Patch(schema, xProps, templateOptions, _linkGenerator, validators); if (patchAttr is FormlyFieldAttribute fAttr) { fieldAttr = fAttr; } } if (xProps.Count > 0) { schema.Extensions["x-props"] = xProps; } }
public override void Patch(OpenApiSchema schema, OpenApiObject xProps, OpenApiObject templateOptions, LinkGenerator linkGenerator, List <ValidatorModel> validators) { base.Patch(schema, xProps, templateOptions, linkGenerator, validators); if (!string.IsNullOrEmpty(FieldGroupClassName)) { xProps["fieldGroupClassName"] = OpenApiExtensions.ToOpenApi(FieldGroupClassName); } }
public OpenApiObject ToOpenApiObject() { var oaObject = new OpenApiObject { { "name", new OpenApiString(Name) } }; if (Args?.ToString() != null) { oaObject["args"] = OpenApiExtensions.ToOpenApi(Args); } if (!string.IsNullOrEmpty(Message)) { oaObject["message"] = new OpenApiString(Message); } return(oaObject); }
public override void Patch(OpenApiSchema schema, OpenApiObject xProps, OpenApiObject templateOptions, LinkGenerator linkGenerator, List <ValidatorModel> validators) { base.Patch(schema, xProps, templateOptions, linkGenerator, validators); if (!KeepAllOfSchemes) { schema.AllOf = new List <OpenApiSchema>(); } if (!string.IsNullOrEmpty(Type)) { if (AsOpenApi) { schema.Type = Type; } else { xProps["type"] = OpenApiExtensions.ToOpenApi(Type); } } var customFieldConfig = GetCustomOpenApiConfig(linkGenerator); if (customFieldConfig != null) { templateOptions["customFieldConfig"] = customFieldConfig; } if (Format != null) { if (AsOpenApi) { schema.Format = Format; } else { templateOptions["format"] = OpenApiExtensions.ToOpenApi(Format); } } }