Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 463 forks source link

Swagger warnings for optional parameters even when using `property` #888

Closed davidwessman closed 1 year ago

davidwessman commented 1 year ago

Hello!

When I specify my return values like this:

          api(
            :POST,
            "/v2/namespace/credentials",
            "Generate new credentials"
          )
          returns(code: 200) do
            property(:username, String)
            property(:password, String)
          end
          def create
          end

and generate swagger, I still get warnings:

The parameter :username is optional but default value is not specified (use :default_value => ...)
The parameter :password is optional but default value is not specified (use :default_value => ...)

even though property are required by default. I also tried adding required: true but still get the errors.

It does generate the correct swagger file as far as I understand:

"responses": {
          "200": {
            "description": "OK",
            "schema": {
              "type": "object",
              "properties": {
                "username": {
                  "type": "string"
                },
                "password": {
                  "type": "string"
                }
              },
              "additionalProperties": false,
              "required": [
                "username",
                "password"
              ]
            }
          }
        },
davidwessman commented 1 year ago

The @in_schema seems to be true and then it wont consider @param_description.required which would have returned true: https://github.com/Apipie/apipie-rails/blob/61ae61d1247543dcb17ebb58267dc5ca0e987c7f/lib/apipie/generator/swagger/param_description/builder.rb#L82

davidwessman commented 1 year ago

Fixed in 1.2.2, thank you @shev-vadim-net 🎉