swagger_parser icon indicating copy to clipboard operation
swagger_parser copied to clipboard

Type 'bool' is not a subtype of type 'Map<String, dynamic>?'

Open DraftedDev opened this issue 5 months ago • 0 comments

Steps to reproduce

Run dart run swagger_parser

Expected results

The generate generates valid dart code

Actual results

Error:

Building package executable...
Built swagger_parser:swagger_parser.

┃  ____ _ _ _ ____ ____ ____ ____ ____     ___  ____ ____ ____ ____ ____
┃  [__  | | | |__| | __ | __ |___ |__/     |__] |__| |__/ [__  |___ |__/
┃  ___] |_|_| |  | |__] |__] |___ |  \ ___ |    |  | |  \ ___] |___ |  \
┃

Generate...
> openapi:
    Failed to generate files.
    type 'bool' is not a subtype of type 'Map<String, dynamic>?' in type cast
    #0      OpenApiParser._findType (package:swagger_parser/src/parser/parser/open_api_parser.dart:1198:29)
    #1      OpenApiParser._findType (package:swagger_parser/src/parser/parser/open_api_parser.dart:1201:55)
    #2      OpenApiParser._findParametersAndImports (package:swagger_parser/src/parser/parser/open_api_parser.dart:762:32)
    #3      OpenApiParser.parseDataClasses.<anonymous closure>.<anonymous closure>.localFindParametersAndImports (package:swagger_parser/src/parser/parser/open_api_parser.dart:850:49)
    #4      OpenApiParser.parseDataClasses.<anonymous closure>.<anonymous closure> (package:swagger_parser/src/parser/parser/open_api_parser.dart:859:11)
    #5      ContextStack.withContext (package:swagger_parser/src/parser/utils/context_stack.dart:24:20)
    #6      OpenApiParser.parseDataClasses.<anonymous closure> (package:swagger_parser/src/parser/parser/open_api_parser.dart:834:21)
    #7      _LinkedHashMapMixin.forEach (dart:_compact_hash:764:13)
    #8      OpenApiParser.parseDataClasses (package:swagger_parser/src/parser/parser/open_api_parser.dart:833:14)
    #9      GenProcessor.generateFiles (package:swagger_parser/src/generator/generator/generator_processor.dart:34:32)
    <asynchronous suspension>
    #10     main (file:///C:/Users/Mikail/AppData/Local/Pub/Cache/hosted/pub.dev/swagger_parser-1.30.0/bin/swagger_parser.dart:28:39)
    <asynchronous suspension>


The generation was completed with errors.
No schemes were generated.

Your OpenApi snippet

{
  "openapi": "3.1.0",
  "info": {
    "title": "Elysium Open API",
    "description": "Open API specification for using the Elysium Web API.",
    "contact": {},
    "license": {
      "name": "MIT",
      "identifier": "MIT"
    },
    "version": "0.1.0"
  },
  "paths": {
    "/api/post/author": {
      "post": {
        "operationId": "get_post_author",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GetPostAuthorArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetPostAuthorResponse"
                }
              }
            }
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/post/comment": {
      "post": {
        "operationId": "comment",
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "Bearer token",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CommentArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": ""
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/post/create": {
      "post": {
        "operationId": "create_post",
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "Bearer token",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreatePostArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatePostResponse"
                }
              }
            }
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/post/delete": {
      "post": {
        "operationId": "delete_post",
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "Bearer token",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeletePostArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": ""
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/post/get": {
      "post": {
        "operationId": "get_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GetPostArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetPostResponse"
                }
              }
            }
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/post/recommend": {
      "post": {
        "operationId": "recommend_post",
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecommendPostResponse"
                }
              }
            }
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/user/auth": {
      "post": {
        "operationId": "auth_user",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuthUserArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthUserResponse"
                }
              }
            }
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/user/create": {
      "post": {
        "operationId": "create_user",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateUserArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": ""
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/user/delete": {
      "post": {
        "operationId": "delete_user",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeleteUserArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": ""
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/user/edit": {
      "post": {
        "operationId": "edit_user",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EditUserArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": ""
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/user/follow": {
      "post": {
        "operationId": "follow_user",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FollowUserArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": ""
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    },
    "/api/user/verify/email": {
      "post": {
        "operationId": "verify_email",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerifyUserEmailArgs"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": ""
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ElyError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AuthUserArgs": {
        "type": "object",
        "required": [
          "name",
          "password"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "password": {
            "type": "string"
          }
        }
      },
      "AuthUserResponse": {
        "type": "object",
        "required": [
          "token"
        ],
        "properties": {
          "token": {
            "type": "string"
          }
        }
      },
      "CommentArgs": {
        "type": "object",
        "required": [
          "on",
          "content"
        ],
        "properties": {
          "content": {
            "$ref": "#/components/schemas/Vec"
          },
          "on": {
            "$ref": "#/components/schemas/String"
          }
        }
      },
      "CreatePostArgs": {
        "type": "object",
        "required": [
          "content"
        ],
        "properties": {
          "content": {
            "$ref": "#/components/schemas/Vec"
          }
        }
      },
      "CreatePostResponse": {
        "type": "object",
        "required": [
          "post_id"
        ],
        "properties": {
          "post_id": {
            "$ref": "#/components/schemas/String"
          }
        }
      },
      "CreateUserArgs": {
        "type": "object",
        "required": [
          "name",
          "display",
          "email",
          "email_token",
          "password",
          "country_code"
        ],
        "properties": {
          "country_code": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "display": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "email_token": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "password": {
            "type": "string"
          }
        }
      },
      "DeletePostArgs": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/String"
          }
        }
      },
      "DeleteUserArgs": {
        "type": "object",
        "required": [
          "name",
          "password"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "password": {
            "type": "string"
          }
        }
      },
      "EditUserArgs": {
        "type": "object",
        "properties": {
          "display": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "password": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ElyError": {
        "type": "string",
        "enum": [
          "UserNotFound",
          "UserAlreadyExists",
          "SessionNotFound",
          "Unauthorized",
          "InvalidToken",
          "PostNotFound",
          "EmailNotVerified",
          "Database"
        ]
      },
      "FollowUserArgs": {
        "type": "object",
        "required": [
          "user",
          "unfollow"
        ],
        "properties": {
          "unfollow": {
            "type": "boolean"
          },
          "user": {
            "type": "string"
          }
        }
      },
      "GetPostArgs": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/String"
          }
        }
      },
      "GetPostAuthorArgs": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/String"
          }
        }
      },
      "GetPostAuthorResponse": {
        "type": "object",
        "required": [
          "user"
        ],
        "properties": {
          "user": {
            "$ref": "#/components/schemas/UserProfile"
          }
        }
      },
      "GetPostResponse": {
        "type": "object",
        "required": [
          "content"
        ],
        "properties": {
          "content": {
            "$ref": "#/components/schemas/Vec"
          }
        }
      },
      "RecommendPostResponse": {
        "type": "object",
        "required": [
          "posts"
        ],
        "properties": {
          "posts": {
            "type": "array",
            "items": {
              "type": "array",
              "items": false,
              "prefixItems": [
                {
                  "type": "array",
                  "items": {
                    "oneOf": [
                      {
                        "type": "object",
                        "required": [
                          "Text"
                        ],
                        "properties": {
                          "Text": {
                            "type": "string"
                          }
                        }
                      }
                    ]
                  }
                },
                {
                  "type": "object",
                  "required": [
                    "name",
                    "display"
                  ],
                  "properties": {
                    "display": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "String": {
        "type": "string"
      },
      "UserProfile": {
        "type": "object",
        "required": [
          "name",
          "display"
        ],
        "properties": {
          "display": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      },
      "Vec": {
        "type": "array",
        "items": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "Text"
              ],
              "properties": {
                "Text": {
                  "type": "string"
                }
              }
            }
          ]
        }
      },
      "VerifyUserEmailArgs": {
        "type": "object",
        "required": [
          "email"
        ],
        "properties": {
          "email": {
            "type": "string"
          }
        }
      }
    }
  }
}

Code sample

No response

Logs

No response

Dart version and used packages versions

Dart version
Dart SDK version: 3.9.2 (stable) (Wed Aug 27 03:49:40 2025 -0700) on "windows_x64"
Packages version
  swagger_parser: ^1.30.0

Config

swagger_parser:
  schema_path: ../elysium_server/openapi.json
  output_directory: lib/api
  name: null
  language: dart
  json_serializer: json_serializable
  default_content_type: "application/json"
  extras_parameter_by_default: false
  dio_options_parameter_by_default: false
  root_client: true
  root_client_name: RestApi
  put_in_folder: false
  put_clients_in_folder: false
  merge_clients: false
  client_postfix: Api
  path_method_name: false
  enums_to_json: false
  enums_parent_prefix: true
  unknown_enum_value: true
  mark_files_as_generated: true
  original_http_response: false
  replacement_rules:
    - pattern: "String"
      replacement: "RustString"

DraftedDev avatar Sep 10 '25 14:09 DraftedDev