Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GlobalSpec not work #132

Closed
DDDHuang opened this issue Jul 1, 2021 · 4 comments
Closed

GlobalSpec not work #132

DDDHuang opened this issue Jul 1, 2021 · 4 comments

Comments

@DDDHuang
Copy link
Collaborator

DDDHuang commented Jul 1, 2021

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
Copy link
Member

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
Copy link
Member

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

@DDDHuang
Copy link
Collaborator Author

DDDHuang commented Jul 1, 2021

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 #133

@elbrujohalcon
Copy link
Member

Aaaand merged!

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

No branches or pull requests

2 participants