[BUG][MYSQL-SCHEMA] howto handle nested objects in schema generation?
Created by: el2ro
Description
When generating DB schema out of OpenAPI spec how should be nested data structures be handled?
Currently it is working so that nested object will create a new table with fields in nested structure. Nested parameter in parent table is set as TEXT. This does not feel like right?
I am not sure if this is a bug, but I am looking info how this should be really handled in nested object case. Background: I am trying to make Postgresql-schema generator and this thing came up, this also applies to mysql-schema generator.
Somehow it feels that it should set nested object as JSON type to main table and not to generate additional table at all.
openapi-generator version
3.3.4 or 4.x.x
Using 3.xx open api yaml spec
OpenAPI declaration file content or url
Full test.yaml https://gist.github.com/el2ro/7d6a3007389429b906b4a49878621dc7 Only important part of it:
components:
schemas:
Test:
title: test
type: object
description: Test
properties:
id:
type: string
format: uuid
name:
type: string
description:
type: string
settings:
type: object
description: Nested object inside an object
properties:
startValue:
type: object
endValue:
type: object
someValue:
type: object
CREATE TABLE IF NOT EXISTS `Test` (
`id` TEXT DEFAULT NULL,
`name` TEXT DEFAULT NULL,
`description` TEXT DEFAULT NULL,
`settings` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Test';
CREATE TABLE IF NOT EXISTS `Test_settings` (
`startValue` JSON DEFAULT NULL,
`endValue` JSON DEFAULT NULL,
`someValue` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Nested object inside an object';
(for JSON code), so it becomes more readable. If it is longer than about ten lines, please create a Gist (https://gist.github.com) or upload it somewhere else and link it here. -->
Command line used for generation
openapi-generator generate \
-i src/test.yaml \
-g mysql-schema \
-o generated/