You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: opt-in non-nullable required properties for TypeScript and Python
Adds a `MakeRequiredPropertiesNonNullable` generation flag (CLI:
`--make-required-properties-non-nullable` / `--mrpnn`) that honors the
OpenAPI `required` array and `nullable`/`type:[...,"null"]` markers when
generating models. A property that is required and not explicitly
nullable is generated as non-optional and non-nullable.
The flag defaults to false to preserve the historical all-nullable
behavior for existing clients; no existing generation output changes
unless it is explicitly enabled.
Shared groundwork:
- CodeProperty.IsRequired, populated from the parent schema's required array
- GenerationConfiguration.MakeRequiredPropertiesNonNullable (default false)
- OpenApiSchemaExtensions.IsExplicitlyNullable() (OAS 3.0 + 3.1)
- KiotaBuilder flips Type.IsNullable=false for required, non-explicitly-nullable,
non-collection custom properties when the flag is on
TypeScript: the interface writer now drops `?` for required properties and
drops `| null` unless the schema is explicitly nullable.
Python: no writer change is required. The dataclass field writer already
gates Optional[...] on IsNullable and retains the `= None` default, so a
required non-nullable property renders as `name: T = None` -- non-Optional
while keeping the default that allows no-arg construction
(create_from_discriminator_value) and valid dataclass field ordering.
Tests: full flag on/off matrix at the builder level (scalar/int/enum/object
ref/collection), TypeScript interface rendering, and Python dataclass field
rendering. Refs #3911.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
privatereadonlyDictionary<Type,object>Writers=[];// we have to type as object because dotnet doesn't have type capture i.e eq for `? extends CodeElement`
Description="When enabled, properties marked as required in the OpenAPI description and not explicitly nullable are generated as non-nullable (and non-optional, for languages that distinguish the two). Disabled by default to preserve the previous behavior where all properties are nullable.",
0 commit comments