metadevpro / openapi3-ts

TS Model & utils for creating and exposing OpenAPI 3.x contracts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OAS 3.1: Support for const keyword

CameronMackenzie99 opened this issue · comments

OAS 3.1 introduced the const keyword (see discussion), syntactically equivalent to a single value enum, for example:

{
    "components": {
        "schemas": {
            "BingData": {
                "additionalProperties": false,
                "properties": {
                    "bing": {
                        "const": "Anything You Need",
                        "title": "Bing"
                    }
                },
                "required": [
                    "bing"
                ],
                "title": "BingData",
                "type": "object"
            },
            "DingData": {
                "additionalProperties": false,
                "properties": {
                    "anything_you_need": {
                        "const": "Anything You Need",
                        "title": "Anything You Need"
                    }
                },
                "required": [
                    "anything_you_need"
                ],
                "title": "DingData",
                "type": "object"
            }
        },
        "info": {
            "title": "Events",
            "version": "0.1.0"
        },
        "openapi": "3.1.0"
    }
}

Supporting this in the library will be really useful for consumers to be able to account for this keyword when parsing schemas.

I'm not entirely sure how this would be typed as I can see that the enum keyword is currently typed as any[] here