0

I've got the following structure in my Flask-RestX application:

  • api_models
    • users
    • permissions
  • namespaces
    • users
    • permissions

I've got a permission_model in api_models/permissions which I want to use in user_model in api_models/users. Usecase:

Permission model: (in api_models/permissions.py)

permission_model = permission_api.model('Permission', {
    "id": fields.String(description="Permission ID", required=True)
})

User model: (in api_models/users.py)

from .permissions import permission_model

user_model = users_api.model('User', {
    "id": fields.String(description="User ID", required=True),
    "permissions": fields.List(fields.Nested(permission_model))
})

I thought it's just as easy as importing models from one file to the other but the whole API breaks down when doing that ("No API definition provided."). I assume this is because they are attached to different Namespaces?

  1. Is there a workaround?
  2. How do people use models cross Namespaces?

Thanks.

1 Answers1

1

This actually works as expected. After spending a lot of time trying to understand why models are not shared, I've started from scratch, reviewing every line of code and when I got to the Namespace registration block....I felt incredibly stupid: I forgot to register the actual "Permissions" Namespace into the app. Did that and now works fine and models are shared as expected.