nextcloud / openapi-extractor

A tool for extracting OpenAPI specifications from Nextcloud source code
https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-openapi.html
GNU Affero General Public License v3.0
7 stars 2 forks source link

Optimise anyOf<integer|double> to a plain number #122

Closed Leptopoda closed 5 months ago

Leptopoda commented 6 months ago

Currently the generator produces a lot of anyOf<integer|double> that can also be expressed as a plain number.

"schema": {
    "nullable": true,
    "oneOf": [
        {
            "type": "number",
            "format": "float"
        },
        {
            "type": "integer",
            "format": "int64"
        }
    ]
}

which could be the expressed as:

"schema": {
    "nullable": true,
    "type": "number"
}

This both increases the readability of the generated specs and improves compatibility with code generators (out of experience generators often generate broken code for oneOf/anyOf especially when nested).

Potential downsides: AFAICT the specs always make use of float and int64 while a plain number would also allow double precision fractional numbers. I don't know how php handles that.

provokateurin commented 6 months ago

Apparently float and double are the same thing in PHP and internally they are always stored with double precision (https://www.php.net/manual/en/language.types.float.php).

provokateurin commented 6 months ago

Opened https://github.com/nextcloud/openapi-extractor/issues/123 to track that problem.

provokateurin commented 5 months ago

I think I'd rather avoid doing this because it can get complex when you have stuff like min/max values and it would only be allowed to merge if both types have the same constraints or no constraints. It's a lot of work to do it right without that many benefits IMO.