What happened?
I am trying to expose a simple table from SQL server and use the openapi definition to import a service reference into a C# project using Visual Studio to generate a C# client.
The Id column is generated as "type": "number", which means client code generated from the openapi document is using a floating point field. When the client posts data, the floating point value is serialized with a decimal point and that is rejected by the dab server.
The Id column should be generated as "type: "integer", "format": "int32" to allow generated client code to interact with the dab server.
TABLE schema
CREATE TABLE MyTable
(
Id INT PRIMARY KEY,
Name NVARCHAR(50) NOT NULL
);
dab-config.json
"entities": {
"MyTable": {
"source": {
"object": "dbo.MyTable",
"type": "table"
},
"rest": {
"enabled": true
},
"permissions": [
{
"role": "authenticated",
"actions": [
{
"action": "*"
}
]
}
]
},
Current behaviour
Generated openapi document
The generated schema in the swagger page shows "number":
The openapi json document types "Id" as "number":
"MyTable": {
"type": "object",
"properties": {
"Id": {
"type": "number",
"format": ""
},
"Name": {
"type": "string",
"format": ""
}
}
},
"MyTable_NoAutoPK": {
"type": "object",
"properties": {
"Id": {
"type": "number",
"format": ""
},
"Name": {
"type": "string",
"format": ""
}
}
},
"MyTable_NoPK": {
"type": "object",
"properties": {
"Name": {
"type": "string",
"format": ""
}
}
}
C# client Id typed as double
Impact
C# service reference importer generates double instead of int, which serializes a POST request for example to "Id": 1.0 and that is rejected by the dab server.
{
"error": {
"code": "BadRequest",
"message": "Parameter \"1.0\" cannot be resolved as column \"Id\" with type \"Int32\".",
"status": 400
}
}
Expected behaviour
The "Id" field should be exposed in the openapi document with
{ "type": "integer", "format": "int32" }
See https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers
Version
1.7.92+a9d84942cd1a1accdbb9089b720ba61074e6f051
What database are you using?
Azure SQL
What hosting model are you using?
Local (including CLI)
Which API approach are you accessing DAB through?
REST
Relevant log output
fail: Azure.DataApiBuilder.Service.Controllers.RestController[0]
dc44f31b-0856-480d-9dbb-5a33b1ccb23b Error handling REST request.
Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: Parameter "1.0" cannot be resolved as column "Id" with type "Int32".
---> System.FormatException: The input string '1.0' was not in a correct format.
at System.Number.ThrowFormatException[TChar](ReadOnlySpan`1 value)
at System.Int32.Parse(String s)
at Azure.DataApiBuilder.Core.Resolvers.BaseSqlQueryStructure.ParseParamAsSystemType(String param, Type systemType) in /_/src/Core/Resolvers/Sql Query Structures/BaseSqlQueryStructure.cs:line 436
at Azure.DataApiBuilder.Core.Resolvers.BaseSqlQueryStructure.GetParamAsSystemType(String fieldValue, String fieldName, Type systemType) in /_/src/Core/Resolvers/Sql Query Structures/BaseSqlQueryStructure.cs:line 619
--- End of inner exception stack trace ---
at Azure.DataApiBuilder.Core.Resolvers.BaseSqlQueryStructure.GetParamAsSystemType(String fieldValue, String fieldName, Type systemType) in /_/src/Core/Resolvers/Sql Query Structures/BaseSqlQueryStructure.cs:line 653
at Azure.DataApiBuilder.Core.Resolvers.SqlInsertStructure.PopulateColumnsAndParams(String columnName, Object value) in /_/src/Core/Resolvers/Sql Query Structures/SqlInsertQueryStructure.cs:line 114
at Azure.DataApiBuilder.Core.Resolvers.SqlInsertStructure..ctor(String entityName, ISqlMetadataProvider sqlMetadataProvider, IAuthorizationResolver authorizationResolver, GQLFilterParser gQLFilterParser, IDictionary`2 mutationParams, HttpContext httpContext, Boolean isLinkingEntity) in /_/src/Core/Resolvers/Sql Query Structures/SqlInsertQueryStructure.cs:line 80
at Azure.DataApiBuilder.Core.Resolvers.SqlMutationEngine.PerformMutationOperation(String entityName, EntityActionOperation operationType, IDictionary`2 parameters, ISqlMetadataProvider sqlMetadataProvider, IMiddlewareContext context) in /_/src/Core/Resolvers/SqlMutationEngine.cs:line 849
at Azure.DataApiBuilder.Core.Resolvers.SqlMutationEngine.ExecuteAsync(RestRequestContext context) in /_/src/Core/Resolvers/SqlMutationEngine.cs:line 653
at Azure.DataApiBuilder.Core.Services.RestService.ExecuteAsync(String entityName, EntityActionOperation operationType, String primaryKeyRoute) in /_/src/Core/Services/RestService.cs:line 202
at Azure.DataApiBuilder.Service.Controllers.RestController.HandleOperation(String route, EntityActionOperation operationType) in /_/src/Service/Controllers/RestController.cs:line 239
Code of Conduct
What happened?
I am trying to expose a simple table from SQL server and use the openapi definition to import a service reference into a C# project using Visual Studio to generate a C# client.
The Id column is generated as
"type": "number", which means client code generated from the openapi document is using a floating point field. When the client posts data, the floating point value is serialized with a decimal point and that is rejected by the dab server.The Id column should be generated as
"type: "integer", "format": "int32"to allow generated client code to interact with the dab server.TABLE schema
dab-config.json
Current behaviour
Generated openapi document
The generated schema in the swagger page shows "number":
The openapi json document types "Id" as "number":
C# client
Idtyped asdoubleImpact
C# service reference importer generates double instead of int, which serializes a POST request for example to
"Id": 1.0and that is rejected by the dab server.{ "error": { "code": "BadRequest", "message": "Parameter \"1.0\" cannot be resolved as column \"Id\" with type \"Int32\".", "status": 400 } }Expected behaviour
The "Id" field should be exposed in the openapi document with
{ "type": "integer", "format": "int32" }See https://swagger.io/docs/specification/v3_0/data-models/data-types/#numbers
Version
1.7.92+a9d84942cd1a1accdbb9089b720ba61074e6f051
What database are you using?
Azure SQL
What hosting model are you using?
Local (including CLI)
Which API approach are you accessing DAB through?
REST
Relevant log output
Code of Conduct