OpenAPITools / OpenAPITools/openapi-generator

[REQ][MySQL] Primary and Foreign Keys

Open
#3,534 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature Schema: MySQL
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

It would be great to generate tables with primary keys, but current Openapi spec doesn't have an option to clearly mark identifiers. Let's take a look at the example:

# part of /modules/openapi-generator/src/test/resources/2_0/petstore-proto.yaml
Order:
  title: Pet Order
  description: An order for a pets from the pet store
  type: object
  properties:
    id:
      type: integer
      format: int64
    petId:
      type: integer
      format: int64
    quantity:
      type: integer
      format: int32
    shipDate:
      type: string
      format: date-time

any experienced developer would say that id is primary key and petId is not(maybe just an index). It just feels so.

Describe the solution you'd like

We can make a guess and add PRIMARY KEY to all properties called id.

Describe alternatives you've considered

Or maybe it's a bad idea from the start and we shouldn't rely on property names. Maybe PRIMARY KEYs should be explicitly specified and with vendor extensions only. Another argument is that PRIMARY KEYs usually followed by AUTO_INCREMENT statement which I don't know how to produce without vendor extension.

Additional context

There was another related discussion in #1672. I don't know how to produce FOREIGN KEYs either, because it's hard to say which properties are connected identifiers in two models.

I think it's important to hear out all opinions from community before proceed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the OpenAPI fixture at modules/openapi-generator/src/test/resources/2_0/petstore-proto.yaml and review the related discussion in issue #1672. The issue does not identify a generator entry point or tests, and completion is not defined because the community has not decided between name-based keys and explicit vendor extensions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mysql
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.