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

Show minProperties/maxProperties constraints for additionalProperties #1343

Closed
codyaray opened this issue Aug 6, 2020 · 2 comments · Fixed by lob/lob-openapi#147 or #2015
Closed
Assignees

Comments

@codyaray
Copy link

codyaray commented Aug 6, 2020

It seems like a bug or missing feature that Redoc-powered API docs don't show constraints for additionalProperties.

For example, when we indicate minItems: 1 on an array, it shows the non-empty flag:

Screen Shot 2020-08-06 at 2 13 28 PM

But there's no such equivalent indicator on the nested additionalProperties field below, which uses minProperties: 1. Likewise, there's no indicator that it should be exactly 1 in this case, because there's also maxProperties: 1 as well.

Here's a snippet of the OpenAPI that produced the above screenshot

  SubscriptionRule:
    type: object
    required:
    - clauses
    properties:
      clauses:
        type: array
        minItems: 1
        description: |
          A rule can have multiple clauses, all of which must match for the rule to match.
          In other words, multiples clauses are `AND`'d together for evaluation.
        items:
          '$ref': '#/components/schemas/SubscriptionClause'

  SubscriptionClause:
    oneOf:
      ...
      - type: object
        description: Filter for alerts with properties that match the given name and value (exact string match)
        additionalProperties:
          type: string
          description: The name and value of the alert attribute to match
        minProperties: 1
        maxProperties: 1
        example:
          severity: info

Note: I'm sure there are complications, e.g., OpenAPI supports minProperties/maxProperties on objects with existing properties, not just the free-form additionalProperties field. So some design decisions will need to be made here. 😬

@freddrake
Copy link

minProperties / maxProperties definitely need to be indicated somehow, and they aren't restricted to when additionalProperties is true.

This is something I've run into as well.

@runeksvendsen
Copy link

I'm experiencing this issue as well. The spec looks like this:

"CreateBookingResponse": {
    "required": ["booking_id", "booking_status"],
    "properties": {
        "booking_id": {
            "type": "integer"
        },
        "booking_status": {
            "$ref": "#/definitions/BookingStatus"
        }
    },
    "type": "object"
},
"BookingStatus": {
    "properties": {
        "table_ready": {
            "required": ["seats"],
            "type": "object",
            "properties": {
                "seats": {
                    "items": {
                        "type": "integer"
                    },
                    "type": "array"
                }
            }
        },
        "waiting_list": {
            "required": ["duration_seconds"],
            "type": "object",
            "properties": {
                "duration_seconds": {
                    "type": "integer"
                }
            }
        }
    },
    "maxProperties": 1,
    "minProperties": 1,
    "type": "object"
},

which is rendered by ReDoc like so:

Screenshot 2020-09-16 at 15 40 46

In other words, for the booking_status object, ReDoc makes it look like both the table_ready and waiting_list properties may be present in the response, when in fact only one of them are allowed to be there.

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 a pull request may close this issue.

5 participants