Skip to content

OneOf is generated to an all required model #197

@JuliaIncibit

Description

@JuliaIncibit

Is your issue related to the code that was generated?

No, my issue is with the openapi-generator-dart wrapper/config

Description of the bug

This code is generated though it should be one of (passwort and username or token)

class AuthLoginRequest {
  /// Returns a new [AuthLoginRequest] instance.
  AuthLoginRequest({
    required this.username,
    required this.password,
    required this.token,
    this.redirect,
    this.session = false,
  });

  /// Username for authentication
  String username;

  /// User password
  String password;

  /// Authentication token
  String token;

....

Steps to reproduce

Add one of to a schema in paths, generate code, check code

Minimal openapi specification

"/api/v2/app/auth/login": {
      "post": {
        "tags": [
          "Authentication"
        ],
        "summary": "Authenticate user and get access token",
        "description": "Authenticate user using either a login token or username and password. Non-student users will receive a redirect URL for web login.",
        "operationId": "authLogin",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "description": "Either provide a token or username/password.",
                "oneOf": [
                  {
                    "required": [
                      "username",
                      "password"
                    ],
                    "properties": {
                      "username": {
                        "description": "Username for authentication",
                        "type": "string"
                      },
                      "password": {
                        "description": "User password",
                        "type": "string",
                        "format": "password"
                      },
                      "redirect": {
                        "type": "string",
                        "nullable": true
                      },
                      "session": {
                        "description": "Set to false in native app. Set to true in browser based web app.",
                        "type": "boolean",
                        "default": false
                      }
                    },
                    "type": "object"
                  },
                  {
                    "required": [
                      "token"
                    ],
                    "properties": {
                      "token": {
                        "description": "Authentication token",
                        "type": "string"
                      },
                      "redirect": {
                        "type": "string",
                        "nullable": true
                      },
                      "session": {
                        "description": "Set to false in native app. Set to true in browser based web app.",
                        "type": "boolean",
                        "default": false
                      }
                    },
                    "type": "object"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful login",
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/UserInfos"
                    }
                  },
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "Invalid credentials or inactive account",
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "error": {
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      },
                      "type": "object"
                    }
                  },
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },

Annotation used

@Openapi(
  additionalProperties: AdditionalProperties(pubName: 'xxxx', pubAuthor: 'xxxxx'),
  inputSpec: InputSpec(path: './lib/api-docs.json'),
  generatorName: Generator.dart,
  outputDirectory: 'api',
  importMappings: {
      'OneOf': 'package:one_of/one_of.dart',
    },
)
class GeneratorConfig {}

Expected behavior

Possibility to use username and password without token an vice versa

Logs


Screenshots

No response

Platform

Android

Library version

6.1.0

Flutter version

3.35.6

Flutter channel

stable

Additional context


Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions