Carapacik / swagger_parser

Dart package that takes an OpenApi definition file and generates REST clients based on retrofit and data classes for your project.
https://pub.dev/packages/swagger_parser
MIT License
87 stars 33 forks source link

Nullable type changes in 3.1 #216

Open danialb007 opened 3 months ago

danialb007 commented 3 months ago

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 ```dart [Paste your code here] ```

Logs

No specific logs.

Dart version and used packages versions

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