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

Issue with: exclusiveMaximum/exclusiveMinimum #9013

Closed
zbuh opened this issue Jul 13, 2023 · 16 comments
Closed

Issue with: exclusiveMaximum/exclusiveMinimum #9013

zbuh opened this issue Jul 13, 2023 · 16 comments

Comments

@zbuh
Copy link

zbuh commented Jul 13, 2023

  • OS: macOS
  • Browser: FireFox
  • Method of installation: fastapi 0.100
  • Swagger/OpenAPI version: OpenAPI 3.1]

example schema:

{
    "components": {
        "schemas": {
            "HTTPValidationError": {
                "properties": {
                    "detail": {
                        "items": {
                            "$ref": "#/components/schemas/ValidationError"
                        },
                        "title": "Detail",
                        "type": "array"
                    }
                },
                "title": "HTTPValidationError",
                "type": "object"
            },
            "Location": {
                "properties": {
                    "lat": {
                        "exclusiveMaximum": 90.0,
                        "exclusiveMinimum": -90.0,
                        "title": "Lat",
                        "type": "number"
                    },
                    "lng": {
                        "maximum": 180.0,
                        "minimum": -180.0,
                        "title": "Lng",
                        "type": "number"
                    }
                },
                "required": [
                    "lat",
                    "lng"
                ],
                "title": "Location",
                "type": "object"
            },
            "ValidationError": {
                "properties": {
                    "loc": {
                        "items": {
                            "anyOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "integer"
                                }
                            ]
                        },
                        "title": "Location",
                        "type": "array"
                    },
                    "msg": {
                        "title": "Message",
                        "type": "string"
                    },
                    "type": {
                        "title": "Error Type",
                        "type": "string"
                    }
                },
                "required": [
                    "loc",
                    "msg",
                    "type"
                ],
                "title": "ValidationError",
                "type": "object"
            }
        }
    },
    "info": {
        "title": "FastAPI",
        "version": "0.1.0"
    },
    "openapi": "3.1.0",
    "paths": {
        "/location": {
            "post": {
                "operationId": "create_location_location_post",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/Location"
                            }
                        }
                    },
                    "required": true
                },
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {}
                            }
                        },
                        "description": "Successful Response"
                    },
                    "422": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/HTTPValidationError"
                                }
                            }
                        },
                        "description": "Validation Error"
                    }
                },
                "summary": "Create Location"
            }
        }
    }
}

Generated:

image

Originally reported in: fastapi/fastapi#9709 (comment)

@char0n
Copy link
Member

char0n commented Jul 17, 2023

Hi @zbuh,

Looks legit, investigating...

@char0n
Copy link
Member

char0n commented Jul 17, 2023

@zbuh,

What actually seems to be the issue?

maximum and minimum keywords have following definition in JSON Schema 2020-12:

image

image

So the visual representation of the following keywords is correctly [-180, 180] which represents fully inclusive range.

"maximum": 180.0,
"minimum": -180.0,
"title": "Lng",
"type": "number"

More info in: https://json-schema.org/draft/2020-12/json-schema-validation.html#section-6.2

@Kludex
Copy link

Kludex commented Jul 17, 2023

The issue is on exclusiveMaximum and exclusiveMinimum, not on minimum and maximum (as the title mentions).

It should show (-90, 90) for exclusive*, and [-180, 180] for the non-exclusive ones (the latter is fine).

You can check the same link you provided, it's on the same section. You can also check how ReDoc renders it. 👀

@zbuh
Copy link
Author

zbuh commented Jul 17, 2023

Yes, the issue is with exclusive*, seems that schema validation and documentation are not coherent.

@char0n
Copy link
Member

char0n commented Jul 17, 2023

Ahh OK, because the image in issue description and the fastapi/fastapi#9709 (comment) deals with lng.

@Kludex
Copy link

Kludex commented Jul 17, 2023

Ahh OK, because the image in issue description and the tiangolo/fastapi#9709 (comment) deals with lng.

@zbuh mentions that there's an inconsistency. They don't say anything about lng...

Anyway, do you need anything else from us here?

@char0n
Copy link
Member

char0n commented Jul 17, 2023

Nope, thanks! I identified the bug and working on the bugfix

@Kludex
Copy link

Kludex commented Jul 17, 2023

Nope, thanks! I identified the bug and working on the bugfix

Thanks! 🙏

@char0n
Copy link
Member

char0n commented Jul 17, 2023

Addressed in #9030. Will be part of next SwaggerUI release.

@char0n char0n closed this as completed Jul 17, 2023
@Kludex
Copy link

Kludex commented Jul 17, 2023

@char0n It will render the above as (-90, 90), and not [-90, 90], right?

@zbuh
Copy link
Author

zbuh commented Jul 17, 2023

shouldnt it be rendered as ]-90, 90[ ?

@Kludex
Copy link

Kludex commented Jul 17, 2023

]-90, 90[

Both notations are equivalent: https://en.wikipedia.org/wiki/Interval_(mathematics)

Either () or ][ are fine.

@char0n
Copy link
Member

char0n commented Jul 17, 2023

@Kludex

image


@zhub - could be but we use the more generally recognized notations:

image

@zbuh
Copy link
Author

zbuh commented Jul 17, 2023

got it. thanks!

@Kludex
Copy link

Kludex commented Jul 17, 2023

Cute! Thanks! 🙏

@char0n
Copy link
Member

char0n commented Jul 17, 2023

Another thing I've notice is that I forgot to handle integer type:

openapi: 3.1.0
info:
  version: 1.2.3
  title: title
components: 
  schemas:
    Location:
      properties:
        lat:
          type: integer

results in

image


Addressed in #9031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants