Skip to main content

Adding Format Annotations for String Formats in C# v4 SDKs (Beta)

· One min read

C# v4 SDKs now carry the format of every string property onto the generated model as a declarative [Format] attribute, so the validation you already run for schema constraints covers formats as well.

Details​

Previously every string format other than email collapsed to a plain string in the generated model. The generator now recognizes email, hostname, ipv4, ipv6, uri, uri-reference and json-pointer, and emits [Format(FormatKind.X)] on the property. Length and pattern constraints declared beside the format are preserved.

The attribute is declarative, like the schema constraint attributes: the SDK decorates the model and you decide when to validate, using Validator.TryValidateObject or Validator.ValidateObject.

Learn more in the Schema Constraints feature guide.

This feature is available in the C# v4 SDK (beta). Generate it from the APIMatic CLI:

apimatic sdk generate --language=csharp --codegen-version=v4 --stability=beta

For the full set of flags and options, see the APIMatic CLI documentation.