yii2-openapi
yii2-openapi copied to clipboard
Prevent _id suffix in column name on reference properties
I have Open API model that represents a DB table
# del:
title: Del
x-table: del
type: object
required:
- id
- user
# ...
properties:
id:
type: integer
readOnly: true
example: 1337
user:
$ref: '../openapi.yaml#/components/schemas/User' # this will automatically create `user_id` columns
# ...
here _id is automatically get suffixed to user. That is helpful in lot of cases.
However in certain cases, I would like to have column name that is a reference but not suffixed by _id and having custom column name
Example:
# del:
title: Del
x-table: del
type: object
required:
- id
# ...
properties:
id:
type: integer
readOnly: true
example: 1337
redelivery_of:
$ref: '../openapi.yaml#/components/schemas/Del'
# ...
this redelivery_of reference to PK of same table and custom column name needed here is redelivery_of instead of redelivery_of_id
Meta:
- feature request
It is a very specific case and It will require additional configuration that will increase complexity... Why not try another name? @cebe What do you think?
this
redelivery_ofreference to PK of same table and custom column name needed here isredelivery_ofinstead ofredelivery_of_id
what is wrong with using _id? Even if it references itself, the naming convention is to use _id for foreign keys.
There is nothing wrong redelivery_of_id. Certainly I can use some other name also with suffix _id. Here redelivery_of is just an example.
At the end I am trying to say in my humble opinion, it would be great to have functionality that allow us to provide custom columns names for foreign keys
In general I'd prefer to stick to convention unless there is a use case where convention prevents a valid use case from working.
I will keep it in mind during #77 realization, but customization of fk names also will touch fk index naming and more... And we must be sure that custom rule is really unique for prevent collisions or ambiguous meaning
This could be solved similar to #131 by adding an x-foreign-key-column-name or similar property to the allOf.