gibahjoe / openapi-generator-dart

Openapi Generator for Dart/Flutter
BSD 3-Clause "New" or "Revised" License
128 stars 34 forks source link

'OneOf' not imported #165

Open Dreaming-Codes opened 1 week ago

Dreaming-Codes commented 1 week ago

Description of the bug

In one of the generated api dart code OneOf is not imported

Steps to reproduce

Generated code with the following schema

Minimal openapi specification

I'm not sure where the problem is so this is just a stripped down version of mine

{
  "components": {
    "schemas": {
      "Abilities": {
        "properties": {
          "charisma": {
            "$ref": "#/components/schemas/AbilityScore"
          },
          "constitution": {
            "$ref": "#/components/schemas/AbilityScore"
          },
          "dexterity": {
            "$ref": "#/components/schemas/AbilityScore"
          },
          "intelligence": {
            "$ref": "#/components/schemas/AbilityScore"
          },
          "strength": {
            "$ref": "#/components/schemas/AbilityScore"
          },
          "wisdom": {
            "$ref": "#/components/schemas/AbilityScore"
          }
        },
        "required": [
          "strength",
          "dexterity",
          "constitution",
          "intelligence",
          "wisdom",
          "charisma"
        ],
        "type": "object"
      },
      "AbilityScore": {
        "properties": {
          "proficiency": {
            "type": "boolean"
          },
          "score": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          }
        },
        "required": [
          "score",
          "proficiency"
        ],
        "type": "object"
      },
      "ClassProperties": {
        "properties": {
          "abilitiesModifiers": {
            "$ref": "#/components/schemas/Abilities"
          },
          "additionalFightingStyle": {
            "type": [
              "string",
              "null"
            ]
          },
          "fightingStyle": {
            "type": [
              "string",
              "null"
            ]
          },
          "level": {
            "description": "The level of the class",
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "spellCasting": {
            "allOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/ClassSpellCasting",
                "description": "Indexes from https://www.dnd5eapi.co/api/spells/"
              }
            ]
          },
          "subclass": {
            "description": "Index from https://www.dnd5eapi.co/api/subclasses/",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "level",
          "abilitiesModifiers"
        ],
        "type": "object"
      },
      "ClassSpellCasting": {
        "oneOf": [
          {
            "properties": {
              "knowledgePrepared": {
                "properties": {
                  "pending_preparation": {
                    "description": "If the user has already prepared spells for the day",
                    "type": "boolean"
                  },
                  "spells_index": {
                    "description": "Indexes from https://www.dnd5eapi.co/api/spells/",
                    "items": {
                      "items": {
                        "type": "string"
                      },
                      "type": "array"
                    },
                    "type": "array"
                  },
                  "spells_prepared_index": {
                    "description": "Indexes from https://www.dnd5eapi.co/api/spells/",
                    "items": {
                      "items": {
                        "type": "string"
                      },
                      "type": "array"
                    },
                    "type": "array"
                  }
                },
                "required": [
                  "spells_index",
                  "spells_prepared_index",
                  "pending_preparation"
                ],
                "type": "object"
              }
            },
            "required": [
              "knowledgePrepared"
            ],
            "type": "object"
          },
          {
            "properties": {
              "alreadyKnowPrepared": {
                "properties": {
                  "pending_preparation": {
                    "description": "If the user has already prepared spells for the day",
                    "type": "boolean"
                  },
                  "spells_prepared_index": {
                    "description": "Indexes from https://www.dnd5eapi.co/api/spells/",
                    "items": {
                      "items": {
                        "type": "string"
                      },
                      "type": "array"
                    },
                    "type": "array"
                  }
                },
                "required": [
                  "spells_prepared_index",
                  "pending_preparation"
                ],
                "type": "object"
              }
            },
            "required": [
              "alreadyKnowPrepared"
            ],
            "type": "object"
          },
          {
            "properties": {
              "knowledgeAlreadyPrepared": {
                "properties": {
                  "spells_index": {
                    "description": "Indexes from https://www.dnd5eapi.co/api/spells/",
                    "items": {
                      "items": {
                        "type": "string"
                      },
                      "type": "array"
                    },
                    "type": "array"
                  },
                  "usable_slots": {
                    "$ref": "#/components/schemas/UsableSlots"
                  }
                },
                "required": [
                  "spells_index",
                  "usable_slots"
                ],
                "type": "object"
              }
            },
            "required": [
              "knowledgeAlreadyPrepared"
            ],
            "type": "object"
          }
        ]
      },
      "Spell": {
        "properties": {
          "index": {
            "type": "string"
          },
          "level": {
            "format": "int32",
            "type": "integer"
          }
        },
        "required": [
          "index",
          "level"
        ],
        "type": "object"
      },
      "UsableSlots": {
        "properties": {
          "level1": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "level2": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "level3": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "level4": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "level5": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "level6": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "level7": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "level8": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          },
          "level9": {
            "format": "int32",
            "minimum": 0,
            "type": "integer"
          }
        },
        "required": [
          "level1",
          "level2",
          "level3",
          "level4",
          "level5",
          "level6",
          "level7",
          "level8",
          "level9"
        ],
        "type": "object"
      }
    }
  },
  "info": {
    "title": "masterai",
    "version": "0.1.0"
  },
  "openapi": "3.1.0"
}

Annotation used

@Openapi(
  additionalProperties:
  DioProperties(pubName: 'masterai_api', pubAuthor: 'DreamingCodes'),
  inputSpec:
  InputSpec(path: 'openapi/openapi.json'),
  generatorName: Generator.dio,
  runSourceGenOnOutput: true,
  outputDirectory: 'api/masterai_api',
)
class MasteraiClient {}

Expected behavior

OneOf gets imported and everything works.

Platform

Linux

Library version

6.0.0

Flutter version

3.24.3

Flutter channel

stable

gibahjoe commented 1 day ago

Hi, could you try adding import mappig config to your annotation? That seemed to work for me when I had this issue last time

@Openapi(
  additionalProperties:
  DioProperties(pubName: 'masterai_api', pubAuthor: 'DreamingCodes'),
  inputSpec:
  InputSpec(path: 'openapi/openapi.json'),
  importMappings: {
      'OneOf': 'package:one_of/one_of.dart', // <--- add this
    },
  generatorName: Generator.dio,
  runSourceGenOnOutput: true,
  outputDirectory: 'api/masterai_api',
)
class MasteraiClient {}