public IEnumerable <PropertyDeclarationSyntax> GeneratePropertyDeclarations(SourceFileContext ctx) { var propertyTyp = SchemaTypes.GetTypFromSchema(Parent.Package, _schema, Name, ctx.CurrentTyp, inParameter: false); if (propertyTyp.FullName == "System.Nullable<System.DateTime>") { // DateTime values generate two properties: one raw as a string, and one DateTime version. var rawProperty = AutoProperty(Modifier.Public | Modifier.Virtual, ctx.Type <string>(), PropertyName + "Raw", hasSetter: true) .WithAttribute(ctx.Type <JsonPropertyAttribute>())(Name); if (_schema.Description is object) { rawProperty = rawProperty.WithXmlDoc(XmlDoc.Summary(_schema.Description)); } yield return(rawProperty); var valueParameter = Parameter(ctx.Type(propertyTyp), "value"); yield return(Property(Modifier.Public | Modifier.Virtual, ctx.Type(propertyTyp), PropertyName) .WithAttribute(ctx.Type <JsonIgnoreAttribute>())() .WithXmlDoc(XmlDoc.Summary(XmlDoc.SeeAlso(ctx.Type <DateTime>()), " representation of ", rawProperty, ".")) .WithGetBody(Return(ctx.Type(typeof(Utilities)).Call(nameof(Utilities.GetDateTimeFromString))(rawProperty))) .WithSetBody(rawProperty.Assign(ctx.Type(typeof(Utilities)).Call(nameof(Utilities.GetStringFromDateTime))(valueParameter)))); } else { var property = AutoProperty(Modifier.Public | Modifier.Virtual, ctx.Type(propertyTyp), PropertyName, hasSetter: true) .WithAttribute(ctx.Type <JsonPropertyAttribute>())(Name); if (_schema.Description is object) { property = property.WithXmlDoc(XmlDoc.Summary(_schema.Description)); } yield return(property); } }
public ParameterModel(PackageModel package, string name, JsonSchema schema, Typ parentTyp) { Name = name; CodeParameterName = name.ToLocalVariableName(package); // It's unclear why these properties don't get the "__" treatment, but apparently they don't. PropertyName = name.ToMemberName(addUnderscoresToEscape: false); Location = schema.Location switch { "query" => RequestParameterType.Query, "path" => RequestParameterType.Path, _ => throw new InvalidOperationException($"Unhandled parameter location: '{_schema.Location}'") }; EnumModel = schema.Enum__ is object?new EnumModel(name, schema) : null; _schema = schema; Typ = SchemaTypes.GetTypFromSchema(package, schema, name, currentTyp: parentTyp, inParameter: true); }