Skip to content

'OneOf' not imported #165

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

Open
Dreaming-Codes opened this issue Nov 18, 2024 · 1 comment
Open

'OneOf' not imported #165

Dreaming-Codes opened this issue Nov 18, 2024 · 1 comment
Labels
bug Something isn't working waiting for response

Comments

@Dreaming-Codes
Copy link

Dreaming-Codes commented Nov 18, 2024

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

@Dreaming-Codes Dreaming-Codes added the bug Something isn't working label Nov 18, 2024
@Dreaming-Codes Dreaming-Codes changed the title Undefined class 'OneOf'. 'OneOf' not imported Nov 18, 2024
@gibahjoe
Copy link
Owner

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 {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for response
Projects
None yet
Development

No branches or pull requests

2 participants