jdkandersson / OpenAlchemy

Define SQLAlchemy models using the OpenAPI specification.
https://openapi-sqlalchemy.readthedocs.io/en/latest/
Apache License 2.0
47 stars 13 forks source link

foreign key in x-composite-index #353

Open Arzemn opened 3 years ago

Arzemn commented 3 years ago

As a user I want to have the ability to add a foreign key to an x-composite-index

Currently when adding a foreign key into the x-composite-index it generates a key error at the composite index creation step

Example:

ProjectDB:
      description: Basic Project Row
      type: object
      x-tablename: project
      properties:
        id:
          type: integer
          description: Unique identifier for the project 
          example: 0
          x-primary-key: true
          x-autoincrement: true
       project_id:
          type: integer
          description: Unique identifier for the project to the Server   
        server_id:
          $ref: "#/components/schemas/ServerDB"
       x-composite-index:
          - project_id
          - server_id

Results in

KeyError: 'server_id'

Even attempting to use the underlying foreign key "server_id_id" fails

 x-composite-index:
          - project_id
          - server_id_id

Result

open_alchemy.exceptions.MalformedSchemaError: ProjectDB :: x-composite-index :: all expressions must be properties, server_id_id is not

only way to overcome is to define the relation manually,