Skip to content

Conversation

@seantleonard
Copy link
Contributor

@seantleonard seantleonard commented Jun 27, 2023

Why make this change?

What is this change?

  • The OpenApiDocumentor service now correctly distinguishes between input parameters and result set columns when documenting a stored procedures REST endpoint. Previously, only the result set columns were resolved. As a result, the OpenApi document that is generated now shows input parameters as fields to be used in the request bodies of POST, PUT, and PATCH. (GET and DELETE have no request bodies).

How was this tested?

  • Integration Tests - Added tests with additional stored procedures in our sql deployment script which demonstrates how parameters and output result set columns (and their JSON data types) are resolved and included in the open api doc.

OpenAPI document example

An example OpenAPI document which helps visualize how the parsing works. Irrelevant fields were removed.

{
    "openapi": "3.0.1",
    "paths": {
        "/sp1": {
            "get": {"..."},
            "post": {
                "tags": [
                    "sp1"
                ],
                "description": "Executes a stored procedure.",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/sp1_sp_request"
                            }
                        }
                    },
                    "required": true
                },
                "responses": {
                    "201": {
                        "description": "Created",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "properties": {
                                        "value": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/sp1_sp_response"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "BadRequest"
                    }
                }
            }
		}
    },
    "components": {
        "schemas": {
            "sp1_sp_request": {
                "type": "object",
                "properties": {
                    "inputName": {
                        "type": "string",
                        "format": ""
                    }
                }
            },
            "sp1_sp_response": {
                "type": "object",
                "properties": {
                    "outputName": {
                        "type": "string",
                        "format": ""
                    }
                }
            }
        }
    }
}

…arameters and result set columns for the request and response payloads.
Copy link
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Left few minor suggestions.

@abhishekkumams
Copy link
Contributor

you mentioned in PR description that GET and DELETE won't have request bodies, but they can have input params, right? So, why not request bodies?

…sserts the necessary characteristics of a request and response body .

updates comments.
@seantleonard
Copy link
Contributor Author

you mentioned in PR description that GET and DELETE won't have request bodies, but they can have input params, right? So, why not request bodies?

Request bodies in those two request types are not convention per HTTP spec:

  1. GET https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.1-6
  2. DELETE https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.5-6

Relevant text with my annotation in square brackets:

A client SHOULD NOT generate content in a [GET/DELETE] request unless it is made directly to an origin server that has previously indicated, in or out of band, that such a request has a purpose and will be adequately supported.

…cenarios under test: validating input parameters and json data types and output result set columns and their json data types. Removes new SP's added from the .sql deploy file.
Copy link
Contributor

@severussundar severussundar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ayush3797
Copy link
Contributor

Nit: The comment here:

// Entities which disable their REST endpoint must not be included in
is repeated at line 178.

@ayush3797
Copy link
Contributor

It might not be relevant for this PR but I think we default stored procedures to atleast support POST operation if no method is defined. This doesn't seem to be the case here:

@seantleonard
Copy link
Contributor Author

It might not be relevant for this PR but I think we default stored procedures to atleast support POST operation if no method is defined. This doesn't seem to be the case here:

Good catch. The sp default methods are added (POST) when RuntimeEntities is created and ProcessRestDefaults() is executed. This also looks to be artifacts of old config system where the collection may be null. The nullable annotation and null check are not necessary.

@seantleonard seantleonard enabled auto-merge (squash) July 12, 2023 19:08
@seantleonard seantleonard merged commit bda0d65 into main Jul 12, 2023
@seantleonard seantleonard deleted the dev/seantleonard/openapi_sp_params branch July 12, 2023 20:08
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]: Inconsistent Example Schema for Request Body of Stored-Procedure in Swagger UI

6 participants