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

Nullable type changes in 3.1 #216

Open
danialb007 opened this issue Mar 21, 2024 · 0 comments
Open

Nullable type changes in 3.1 #216

danialb007 opened this issue Mar 21, 2024 · 0 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@danialb007
Copy link

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"
@Carapacik Carapacik added bug Something isn't working enhancement New feature or request labels Mar 21, 2024
@StarProxima StarProxima self-assigned this May 9, 2024
YaroCabbage added a commit to YaroCabbage/swagger_parser that referenced this issue Aug 8, 2024
- if property is nullable -> it must be required or have default value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants