inaka / cowboy_swagger

Swagger integration for Cowboy (built on trails)
http://inaka.net/blog/2015/08/19/cowboy-swagger/
Apache License 2.0
121 stars 58 forks source link

GlobalSpec not work #132

Closed DDDHuang closed 3 years ago

DDDHuang commented 3 years ago

It is difficult to add .config file in our project, so I set global spec by

GlobalSpec = #{swagger => "2.0" , info => #{title => "minirest example API"}},
application:set_env(cowboy_swagger, global_spec, GlobalSpec).

case i need swagger2.0 to support consumes field, like

"consumes": ["multipart/form-data"]

But it seem not work.

I try to access http://localhost:8088/api-docs/swagger.json and get return:

{
    "info":
    {
        "title": "minirest example API"
    },
    "openapi": "3.0.0",
    "paths":
    {
        "/minirest/file":
        {
            "post":
            {
                "consumes":
                [
                    "multipart/form-data"
                ],
                "description": "echo parameters",
                "operationId": "up_file",
                "parameters":
                [
                    {
                        "in": "formData",
                        "name": "file",
                        "type": "file"
                    }
                ],
                "responses":
                {
                    "200":
                    {
                        "content":
                        {
                            "text/plain":
                            {
                                "schema":
                                {
                                    "type": "string"
                                }
                            }
                        },
                        "description": "echo message"
                    }
                },
                "tags":
                [
                    "example"
                ]
            }
        }
    },
    "swagger": "2.0"
}

the "openapi":"3.0.0" and "swagger":"2.0" both exist.

PS: I hope it to start as a launcher function, maybe as like:

Options = #{global_spec => #{swagger => "2.0", info => "minirest example API"}},
cowboy_swagger:start(Options).
elbrujohalcon commented 3 years ago

It's been a long long time since I delved in this project, but… have you tried with…

GlobalSpec = #{openapi => undefined, swagger => "2.0" , info => #{title => "minirest example API"}},
application:set_env(cowboy_swagger, global_spec, GlobalSpec).

…?

elbrujohalcon commented 3 years ago

Also… what does cowboy_swagger:swagger_version() return after you run that set_env/3 call?

DDDHuang commented 3 years ago

Ues

GlobalSpec = #{openapi => undefined, swagger => "2.0" , info => #{title => "minirest example API"}},
application:set_env(cowboy_swagger, global_spec, GlobalSpec).

successed, Thank you. but cowboy_swagger:swagger_version(), this function not exported.

And I think openapi => undefined should removed, it is puzzling that undefined... So my pr https://github.com/inaka/cowboy_swagger/pull/133

elbrujohalcon commented 3 years ago

Aaaand merged!