oliyh / martian

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

Does not see body-schema which is not $ref to definitions #100

Closed evilsneer closed 3 years ago

evilsneer commented 3 years ago

If parameters schema for point in swagger.json described without $ref, but like

{
    "operationId": "codes_create",
    "summary": "codes create",
    "description": "API endpoint that allows code_models to be viewed or edited.",
    "parameters": [
        {
            "name": "data",
            "in": "body",
            "required": true,
            "schema": {
                "type": "object",
                "properties": {
                    "dataset": {
                        "type": "integer"
                    },
                    "description": {
                        "type": "string"
                    },
                    "goal": {
                        "type": "integer"
                    },
                    "name": {
                        "type": "string"
                    },
                    "state": {
                        "type": "integer"
                    },
                    "systems": {
                        "type": "array",
                        "items": {
                            "type": "integer"
                        }
                    }
                }
            }
        }
    ],
    "responses": {
        "201": {
            "description": "Create success response",
            "schema": {
                "$ref": "#/definitions/serialiser-Code"
            }
        }
    },
    "tags": [
        "code"
    ]
}

then Martian method schema seems like {:data s/Any}

It is still valid swagger, I assume. It perfectly works with swagger-ui.

I guess I could dig somewhere around martian.swagger/body(?)-schema to fix it?

oliyh commented 3 years ago

Hi,

Thanks for reporting this. Could you show the output of (martian.core/explore martian :codes_create) and indicate what you would expect it to look like instead?

Cheers

evilsneer commented 3 years ago

It looks like

{:summary "Create Code object",
 :parameters {:data {:_ nil}},
 :returns
 {201 RETURN-PARAMS-IS-OK}}

as you see, :parameters is {:data s/ANY}, аt fact.

I expect some kind of

{:summary "Create Code object",
 :parameters {:data {
    {:k :dataset} {:schema {:p? #obj :pred-name integer?}}
    {:k :description} {:schema {:p? #obj :pred-name string?}}
    {:k :goal} {:schema {:p? #obj :pred-name integer?}}
    {:k :name} {:schema {:p? #obj :pred-name string?}}
    {:k :state} {:schema {:p? #obj :pred-name integer?}}
    {:k :systems} [{:p? #obj, :pred-name integer?}]}},
 :returns
 {201 RETURN-PARAMS-IS-OK}}
oliyh commented 3 years ago

Hi @evilsneer

Thanks, I will look into this

oliyh commented 3 years ago

Hi @evilsneer

This should be fixed in the latest 0.1.15-SNAPSHOT which is now on clojars, could you try it and let me know?

Thanks

evilsneer commented 3 years ago

Yes, it works perfectly. Thanks!