swagger_parser icon indicating copy to clipboard operation
swagger_parser copied to clipboard

Nullable type changes in 3.1

Open danialb007 opened this issue 11 months ago • 0 comments

Steps to reproduce

  1. Use the provided schema file and run the swagger_parser cli command.
  2. Examine the output :)

Expected results

final String? fieldName;

Actual results

final [string, null]? fieldName;

openapi specification changed from 3.0 to 3.1.

nullable parameter is removed and instead if a field is nullable, it now has an array of types, usually the first type in the array is the type it should be and the second one in 'null' indicating that this is a nullable field.

you can read more about the 3.1 changes here. migrating from openapi 3.0 to 3.1.

Your OpenApi snippet

{
    "openapi": "3.1.0",
    "info": {
        "title": "Your Project API",
        "version": "1.0.0 (v1)",
        "description": "Your project description"
    },
    "paths": {
        "/api/v1/auth/user/{id}/info/": {
            "patch": {
                "operationId": "auth_user_info_partial_update",
                "parameters": [
                    {
                        "in": "path",
                        "name": "id",
                        "schema": {
                            "type": "string"
                        },
                        "required": true
                    }
                ],
                "tags": [
                    "auth"
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/UserInfo"
                            }
                        },
                        "application/x-www-form-urlencoded": {
                            "schema": {
                                "$ref": "#/components/schemas/UserInfo"
                            }
                        },
                        "multipart/form-data": {
                            "schema": {
                                "$ref": "#/components/schemas/UserInfo"
                            }
                        }
                    }
                },
                "security": [
                    {
                        "cookieAuth": []
                    },
                    {
                        "basicAuth": []
                    },
                    {}
                ],
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/User"
                                }
                            }
                        },
                        "description": ""
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "UserInfo": {
                "type": "object",
                "properties": {
                    "birthday": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time"
                    }
                }
            },
            "User": {
                "type": "object",
                "properties": {
                    "birthday": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time"
                    }
                }
            }
        },
        "securitySchemes": {
            "basicAuth": {
                "type": "http",
                "scheme": "basic"
            },
            "cookieAuth": {
                "type": "apiKey",
                "in": "cookie",
                "name": "sessionid"
            }
        }
    }
}

Code sample

Code sample
[Paste your code here]

Logs

No specific logs.

Dart version and used packages versions

Dart version
Dart SDK version: 3.3.1 (stable) (Wed Mar 6 13:09:19 2024 +0000) on "macos_arm64"

danialb007 avatar Mar 21 '24 09:03 danialb007