Skip to content

Fix documentation of additionalProperties field when used with array parameters #840

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

Merged
merged 10 commits into from
Oct 21, 2021

Conversation

magni-
Copy link
Contributor

@magni- magni- commented Oct 20, 2021

This currently produces invalid Swagger:

params do
  optional :array_param, type: Array, documentation: { additional_properties: true } do
    requires :nested_param
  end
end

I took the liberty of renaming additionalProperties to additional_properties (and deprecating the former) to have consistent casing.

Copy link
Member

@LeFnord LeFnord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for it @magni-

but please, can you add a note to the UPGRADE.md and add documentation of it to the README.md

@magni-
Copy link
Contributor Author

magni- commented Oct 21, 2021

@LeFnord While working on adding documentation for this, I realized this will need more changes: OAS 2.0 does not support additionalProperties: true. Is there a helper in the specs to ensure the generated JSON is valid OAS 2.0? I couldn't find one.

edit: Or maybe it's fine? Testing at https://apitools.dev/swagger-parser/online/, the following is supposedly valid

{
  "info": {
    "title": "title",
    "version": "1"
  },
  "swagger": "2.0",
  "paths": {
    "/foos": {
      "post": {
        "parameters": [
          {
            "in": "body",
            "name": "foo",
            "schema": {
              "$ref": "#/definitions/Foo"
            },
            "required": true
          }
        ],
        "responses": {
          "201": {
            "description": "desc"
          }
        },
        "operationId": "post-foos"
      }
    }
  },
  "definitions": {
    "Foo": {
      "type": "object",
      "additionalProperties": true
    }
  }
}

@magni- magni- force-pushed the pp/additional_properties branch from a04edc6 to 5ef43e2 Compare October 21, 2021 02:41
@magni-
Copy link
Contributor Author

magni- commented Oct 21, 2021

I've added documentation to the README and instructions regarding the deprecation to UPGRADING. I assumed the next version would be 1.4.1 because these are just fixes and the deprecation isn't a breaking change (yet).

I also updated the logic so that it behaves more like the rest of grape/grape-swagger: you can now pass in classes such as String, Integer, etc, or entity classes, and it will set the appropriate additionalProperties hash for you. If you pass in anything else, it'll get passed through as-is, (this is the current behavior).

@LeFnord
Copy link
Member

LeFnord commented Oct 21, 2021

wow, great work, thank you @magni- … will release it in the next days

@LeFnord LeFnord merged commit 1fea1f8 into ruby-grape:master Oct 21, 2021
@magni- magni- deleted the pp/additional_properties branch October 22, 2021 02:04
@magni-
Copy link
Contributor Author

magni- commented Oct 22, 2021

I just noticed 1.4.1 is already out, UPGRADING should mention 1.4.2 instead 🤦🏼

Thanks for getting those fixes out @LeFnord ! Could you also release a new version of grape-entity while you're at it? 🙏🏼

@LeFnord
Copy link
Member

LeFnord commented Oct 22, 2021

done

aka-momo pushed a commit to aka-momo/grape-swagger that referenced this pull request Feb 8, 2023
…y parameters (ruby-grape#840)

* Fix typo in CHANGELOG

* Allow usage of additional_properties, deprecate additionalProperties

All other options are snake-cased rather than camel-cased, so this keeps things consistent.

* Ignore .byebug_history

* Add test covering additional_properties

* Fix additionalProperties for arrays of objects

* Fix settings additional_properties to false

* Handle receiving types and entities in additional_properties

This includes a fix to MoveParams.document_as_property for an issue found while testing these changes.

* Refactor to use Enumerable#any?

* Document additional_properties

* Update CHANGELOG
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

Successfully merging this pull request may close these issues.

2 participants