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
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Mark stored procedure parameters without defaults as required in OpenAPI (#3687)
## Why make this change?
- Closes#3498. The generated OpenAPI document for stored procedure
entities omitted the `required` array on the `{entity}_sp_request`
schema, so parameters that must be supplied (e.g. `firstName`,
`lastName`) were not flagged as required.
## What is this change?
- **`CreateSpRequestComponentSchema`** (`OpenApiDocumentor.cs`): a
parameter is now marked required when it is explicitly flagged in config
**or** has no default value. Previously only an explicit config
`required: true` populated the array, which is almost never set, so the
array was always empty.
- Mirrors the existing `IsRequestBodyRequired` logic
(`!HasConfigDefault`), keeping body-level and property-level required
semantics consistent. An explicit config `required: false` is still
honored.
```csharp
if (def.Required ?? !def.HasConfigDefault)
{
required.Add(parameter);
}
```
## How was this tested?
- [x] Integration Tests
- [ ] Unit Tests
Extended `StoredProcedureGeneration.ValidateRequestBodyContents` to
assert the request body schema's `required` set contains the expected
parameters. Verified the assertion fails when the fix is reverted.
## Sample Request(s)
`GET /api/openapi` — request body schema component for a stored
procedure with parameters `title`, `publisher_name` (neither having a
default):
```json
"sp1_sp_request": {
"type": "object",
"properties": {
"title": { "type": "string" },
"publisher_name": { "type": "string" }
},
"required": [ "title", "publisher_name" ]
}
```
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Souvik Ghosh <souvikofficial04@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: RubenCerna2079 <32799214+RubenCerna2079@users.noreply.github.com>
Description:"Stored procedure with all parameters marked required: false");
125
+
66
126
Dictionary<string,Entity>entities=new()
67
127
{
68
-
{"sp1",entity1}
128
+
{"sp1",entity1},
129
+
{"sp2",entity2},
130
+
{"sp3",entity3},
131
+
{"sp4",entity4}
69
132
};
70
133
71
134
_runtimeEntities=new(entities);
@@ -74,13 +137,23 @@ public static void CreateEntities()
74
137
/// <summary>
75
138
/// Validates that the generated request body references stored procedure parameters
76
139
/// and not result set columns.
140
+
/// Also validates that the request body schema component flags the expected parameters
141
+
/// as required: a parameter is required when it has no default value and is not explicitly
142
+
/// marked required: false in the runtime config.
143
+
/// Also validates the body-level required flag on the OpenApiRequestBody object, which
144
+
/// should be true when any parameter is required and false when all parameters are optional.
77
145
/// </summary>
78
146
/// <param name="entityName">Entity name</param>
79
147
/// <param name="expectedParameters">Expected parameters in request body</param>
80
148
/// <param name="expectedParametersJsonTypes">Expected parameter value types in request body.</param>
81
-
[DataRow("sp1",newstring[]{"title","publisher_name"},newstring[]{"string","string"},DisplayName="Validate request body parameters and parameter Json data types.")]
149
+
/// <param name="expectedRequiredParameters">Expected parameters flagged as required in the schema component.</param>
150
+
/// <param name="expectedRequestBodyRequired">Expected value of the body-level required flag.</param>
151
+
[DataRow("sp1",newstring[]{"title","publisher_name"},newstring[]{"string","string"},newstring[]{"title","publisher_name"},true,DisplayName="Parameters without defaults are all required.")]
152
+
[DataRow("sp2",newstring[]{"title","publisher_id"},newstring[]{"string","integer"},newstring[]{"publisher_id"},true,DisplayName="Parameter with a config default is not required.")]
153
+
[DataRow("sp3",newstring[]{"id","title"},newstring[]{"integer","string"},newstring[]{"id"},true,DisplayName="Parameter explicitly marked required: false is not required.")]
154
+
[DataRow("sp4",newstring[]{"id"},newstring[]{"integer"},newstring[]{},false,DisplayName="All parameters marked required: false produces empty required set and optional request body.")]
0 commit comments