yii2-openapi icon indicating copy to clipboard operation
yii2-openapi copied to clipboard

Prevent _id suffix in column name on reference properties

Open SOHELAHMED7 opened this issue 3 years ago • 5 comments

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

SOHELAHMED7 avatar Dec 11 '21 13:12 SOHELAHMED7

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?

Insolita avatar Dec 12 '21 19:12 Insolita

this redelivery_of reference to PK of same table and custom column name needed here is redelivery_of instead of redelivery_of_id

what is wrong with using _id? Even if it references itself, the naming convention is to use _id for foreign keys.

cebe avatar Dec 13 '21 10:12 cebe

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

SOHELAHMED7 avatar Dec 16 '21 14:12 SOHELAHMED7

In general I'd prefer to stick to convention unless there is a use case where convention prevents a valid use case from working.

cebe avatar Dec 21 '21 13:12 cebe

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

Insolita avatar Dec 21 '21 14:12 Insolita

This could be solved similar to #131 by adding an x-foreign-key-column-name or similar property to the allOf.

cebe avatar Jan 27 '23 11:01 cebe