RapiDoc icon indicating copy to clipboard operation
RapiDoc copied to clipboard

`schema-style` should also apply to JSON params of API with `application/x-www-form-urlencoded` content type

Open ilPittiz opened this issue 2 years ago • 0 comments

Imagine having a POST/PUT API whose requestBody has application/x-www-form-urlencoded content type, and having a parameter admitting a JSON as value. Defining schema-style="table" doesn't affect the rendering of the parameter's schema, which complies instead to tree schema style. Unless this is an intended design choice, I'd say a consistent rendering of all schemas would be preferable.

Full HTML example code:

<!doctype html>
<html>
<head>
    <script type="text/javascript" src="https://unpkg.com/[email protected]/dist/rapidoc-min.js" charset="UTF-8"></script>
</head>
<body>
<rapi-doc render-style="read" schema-style="table" default-schema-tab="schema"></rapi-doc>
<script>
    document.addEventListener('DOMContentLoaded', (event) => {
        let docEl = document.querySelector('rapi-doc');
        let objSpec = {
            "openapi": "3.0.3",
            "info": {
                "title": "",
                "version": "0.0.1"
            },
            "servers": [{
                "url": "https://localhost:8080"
            }],
            "tags": [{
                "name": "test"
            }],
            "paths": {
                "/test": {
                    "post": {
                        "tags": [
                            "test"
                        ],
                        "summary": "Test",
                        "description": "",
                        "operationId": "test",
                        "requestBody": {
                            "content": {
                                "application/x-www-form-urlencoded": {
                                    "schema": { "$ref": "#/components/schemas/obj" }
                                },
                                "application/json": {
                                    "schema": { "$ref": "#/components/schemas/obj" }
                                }
                            }
                        },
                        "responses": {
                            "200": {
                                "description": "",
                                "content": {
                                    "application/json": {
                                        "schema": { "$ref": "#/components/schemas/obj" },
                                        "example": {}
                                    }
                                }
                            }
                        }
                    }

                }
            },
            "components": {
                "schemas": {
                    "obj": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "super": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "stuff": {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    }
                                },
                                "required": [ "id" ],
                                "additionalProperties": false
                            }
                        },
                        "required": [ "id", "super" ],
                        "additionalProperties": false
                    }
                },
                "responses": {},
                "parameters": {}
            }
        };
        docEl.loadSpec(objSpec);
    });
</script>
</body>

ilPittiz avatar Jan 27 '23 17:01 ilPittiz