Skip to content

Fix OpenAPI format for date/datetime/time/uuid/byte types across all data sources#3706

Draft
JerryNixon with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-openapi-date-filter-issue
Draft

Fix OpenAPI format for date/datetime/time/uuid/byte types across all data sources#3706
JerryNixon with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-openapi-date-filter-issue

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Why make this change?

  • Closes [Bug]: OpenAPI and $filter for dates #2783
  • DAB's generated OpenAPI document exposed all date, datetime2, datetimeoffset, uniqueidentifier, and binary columns as type: "string" with format: "" (empty). Clients dynamically building $filter expressions had no machine-readable signal to distinguish a date field from a plain string, forcing fragile heuristics.

What is this change?

New TypeHelper.GetOpenApiFormatFromSystemType(Type, DbType?)

Maps each supported CLR type + DbType to the correct OAS 3.0 format:

CLR type DbType OpenAPI format Example DB types
DateTime DbType.Date date MSSQL date
DateTime anything else / null date-time MSSQL datetime/datetime2/smalldatetime, PostgreSQL timestamp, MySQL datetime
DateOnly date PostgreSQL date (Npgsql 8), MySQL DATE (MySqlConnector 2+)
DateTimeOffset date-time MSSQL datetimeoffset, PostgreSQL timestamptz
TimeOnly / TimeSpan time All databases' time columns
Guid uuid MSSQL uniqueidentifier, PostgreSQL uuid
byte[] byte binary/bytea columns
all other types (null — field omitted) int, string, bool, …

OpenApiDocumentor — both CreateComponentSchema (entity columns) and CreateSpRequestComponentSchema (stored procedure parameters) now call GetOpenApiFormatFromSystemType to populate the format field. format is null (omitted) when no standard format applies, eliminating the spurious format: "" shown in the bug report.

DateOnly cross-database support

Npgsql 8 and MySqlConnector 2+ report System.DateOnly as the CLR type for date columns. Without explicit entries in DAB's type maps this caused JsonDataType.Undefined in the OpenAPI path and would throw in the GraphQL/OData paths:

  • Added typeof(DateOnly)JsonDataType.String to _systemTypeToJsonDataTypeMap
  • Added typeof(DateOnly)DbType.Date to _systemTypeToDbTypeMap
  • Added "DateOnly" => EdmPrimitiveTypeKind.Date to GetEdmPrimitiveTypeFromSystemType (OData $filter on date columns)
  • Added "DateOnly" => DATETIME_TYPE to SchemaConverter.GetGraphQLTypeFromSystemType (prevents GraphQL startup failure)

How was this tested?

  • Integration Tests
  • Unit Tests — GetOpenApiFormatFromSystemType_ReturnsExpectedFormat: 13 data-driven cases covering every database / CLR-type / DbType combination; ResolveUnderlyingTypeForNullableValueType extended with DateOnly?

Sample Request(s)

After this fix, a datetime2 column like START_DATE_INCIDENT is described in the OpenAPI document as:

START_DATE_INCIDENT:
  type: string
  format: date-time   # was: format: ""

Clients can now detect date fields via format and correctly omit quotes in $filter:

GET /api/Incidents?$filter=START_DATE_INCIDENT ge 2025-01-01T00:00:00Z

Copilot AI linked an issue Jul 7, 2026 that may be closed by this pull request
1 task
Copilot AI added 2 commits July 7, 2026 23:32
…data sources

- Add GetOpenApiFormatFromSystemType() to TypeHelper: maps CLR types + DbType to
  OpenAPI format strings (date-time, date, time, uuid, byte) per OAS 3.0 spec
- Update CreateComponentSchema and CreateSpRequestComponentSchema in OpenApiDocumentor
  to populate the 'format' field using the new helper
- Add DateOnly to _systemTypeToJsonDataTypeMap and _systemTypeToDbTypeMap so that
  PostgreSQL (Npgsql 8) and MySQL (MySqlConnector 2+) date columns work correctly
- Add DateOnly to GetEdmPrimitiveTypeFromSystemType for OData $filter support
- Add DateOnly to SchemaConverter.GetGraphQLTypeFromSystemType to prevent startup
  failures when GraphQL is enabled and date columns are present
- Add unit tests covering all per-database CLR type / DbType combinations
Copilot AI changed the title [WIP] Fix OpenAPI specification for datetime filtering Fix OpenAPI format for date/datetime/time/uuid/byte types across all data sources Jul 7, 2026
Copilot AI requested a review from JerryNixon July 7, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenAPI and $filter for dates

2 participants