oliyh / martian

The HTTP abstraction library for Clojure/script, supporting OpenAPI, Swagger, Schema, re-frame and more
MIT License
525 stars 42 forks source link

Issue with required parameters #111

Closed evilsneer closed 2 years ago

evilsneer commented 3 years ago

Hi!

I use swagger as below, and schema, which martian generates contains keys of data dict as required, but it is not. So queries "fails" on client side.

Swagger-ui handles this case (no red stars above fields in model view).


{
    "swagger": "2.0",
    "x-id": [
        "mango.routes.services/api"
    ],
    "info": {
        "title": "my-api",
        "description": "https://cljdoc.org/d/metosin/reitit"
    },
    "paths": {
        "/api/datasets/phones": {
            "post": {
                "responses": {
                    "default": {
                        "description": ""
                    }
                },
                "produces": [
                    "application/json",
                    "application/transit+msgpack",
                    "application/transit+json",
                    "application/edn"
                ],
                "consumes": [
                    "application/json",
                    "application/transit+msgpack",
                    "application/transit+json",
                    "application/edn"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "body",
                        "description": "",
                        "required": true,
                        "schema": {
                            "type": "object",
                            "properties": {
                                "phone": {
                                    "type": "object",
                                    "properties": {
                                        "operation": {
                                            "title": "Operation",
                                            "description": "operations on field",
                                            "enum": [
                                                "=",
                                                "contains",
                                                "startswith",
                                                "like"
                                            ],
                                            "default": "=",
                                            "type": "string"
                                        },
                                        "value": {
                                            "type": "string",
                                            "x-nullable": true
                                        }
                                    },
                                    "required": [
                                        "operation",
                                        "value"
                                    ]
                                },
                                "gender": {
                                    "type": "object",
                                    "properties": {
                                        "operation": {
                                            "title": "Operation",
                                            "description": "operations on field",
                                            "enum": [
                                                "=",
                                                "startswith",
                                                "like",
                                                "contains"
                                            ],
                                            "default": "=",
                                            "type": "string"
                                        },
                                        "value": {
                                            "type": "string",
                                            "x-nullable": true
                                        }
                                    },
                                    "required": [
                                        "operation",
                                        "value"
                                    ]
                                },
                                "age": {
                                    "type": "object",
                                    "properties": {
                                        "operation": {
                                            "title": "Operation",
                                            "description": "operations on field",
                                            "enum": [
                                                "=",
                                                "contains",
                                                "startswith",
                                                "like"
                                            ],
                                            "default": "=",
                                            "type": "string"
                                        },
                                        "value": {
                                            "type": "string",
                                            "x-nullable": true
                                        }
                                    },
                                    "required": [
                                        "operation",
                                        "value"
                                    ]
                                }
                            },
                            "required": []   <<---  empty !
                        }
                    }
                ],
                "summary": "select from table `phones`",
                "operationId": "phones"
            }
        }
    }
}
oliyh commented 3 years ago

Hi,

Thanks for reporting. So the top level keys should be optional, but martian thinks they are required?

Cheers

evilsneer commented 3 years ago

Yes, that's right!

oliyh commented 2 years ago

This is available now in 0.1.21-SNAPSHOT