mcadecio / universal-database-proxy-rest

Transform any database you have into a RESTful API.
MIT License
3 stars 0 forks source link

PostgresDB: Add support for composite primary keys #15

Closed mcadecio closed 10 months ago

mcadecio commented 1 year ago

Postgres proxy fails to start with the following error:

ERROR|0910-15:01:09 899|vert.x-eventloop-thread-3|RestApiVerticle|Failed to create router: 
io.vertx.ext.web.openapi.RouterBuilderException: Spec is invalid
    at io.vertx.ext.web.openapi.RouterBuilderException.createInvalidSpec(RouterBuilderException.java:46) ~[vertx-web-openapi-4.3.1.jar:4.3.1]
Caused by: io.vertx.json.schema.common.ValidationExceptionImpl: array elements must be unique
    at io.vertx.json.schema.ValidationException.create(ValidationException.java:85) ~[vertx-json-schema-4.3.1.jar:4.3.1]

This is the schema

CREATE TABLE students
(
    roll_no serial      not null,
    name    varchar(20),
    age     int,
    phone   varchar(10) not null,
    PRIMARY KEY (name, age)
)

Generated OpenApi

openapi: 3.0.1
info:
  title: Auto Generated Open API
  description: "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/)\
    \ or HTML."
  version: 1.0.1
servers:
- url: /
  description: "Optional server description, e.g. Main (production) server"
tags:
- name: students
paths:
  /students:
    get:
      tags:
      - students
      summary: Returns a list of students
      description: Auto Generated
      operationId: get_students
      parameters:
      - name: name
        in: query
        schema:
          type: string
      - name: roll_no
        in: query
        schema:
          type: integer
      - name: roll_no
        in: query
        schema:
          type: integer
      - name: age
        in: query
        schema:
          type: integer
      - name: age
        in: query
        schema:
          type: integer
      - name: phone
        in: query
        schema:
          type: string
      - name: phone
        in: query
        schema:
          type: string
      responses:
        "200":
          description: A JSON array of students
          content:
            application/json:
              schema:
                type: array
                items:
                  required:
                  - name
                  - roll_no
                  - roll_no
                  - age
                  - age
                  - phone
                  - phone
                  type: object
                  properties:
                    name:
                      type: string
                      nullable: false
                    roll_no:
                      type: integer
                      nullable: false
                    age:
                      type: integer
                      nullable: false
                    phone:
                      type: string
                      nullable: false
      x-metadata:
        database: database-proxy
        schema: money
        table: students
    post:
      tags:
      - students
      summary: Creates a new students
      description: Auto Generated
      operationId: create_students
      requestBody:
        content:
          application/json:
            schema:
              required:
              - name
              - roll_no
              - roll_no
              - age
              - age
              - phone
              - phone
              type: object
              properties:
                name:
                  type: string
                  nullable: false
                roll_no:
                  type: integer
                  nullable: false
                age:
                  type: integer
                  nullable: false
                phone:
                  type: string
                  nullable: false
        required: true
      responses:
        "201":
          description: A new students has been created.
          headers:
            Location:
              description: The URI of the resource created.
              schema:
                type: string
      x-metadata:
        database: database-proxy
        schema: money
        table: students
  /students/{name}:
    get:
      tags:
      - students
      summary: Get a  students by id
      description: Auto Generated
      operationId: get_students_by_id
      parameters:
      - name: name
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: A JSON representing students
          content:
            application/json:
              schema:
                required:
                - name
                - roll_no
                - roll_no
                - age
                - age
                - phone
                - phone
                type: object
                properties:
                  name:
                    type: string
                    nullable: false
                  roll_no:
                    type: integer
                    nullable: false
                  age:
                    type: integer
                    nullable: false
                  phone:
                    type: string
                    nullable: false
      x-metadata:
        database: database-proxy
        schema: money
        table: students
    put:
      tags:
      - students
      summary: Update a students by id
      description: Auto Generated
      operationId: update_students_by_id
      parameters:
      - name: name
        in: path
        required: true
        schema:
          type: string
      requestBody:
        content:
          application/json:
            schema:
              required:
              - name
              - roll_no
              - roll_no
              - age
              - age
              - phone
              - phone
              type: object
              properties:
                name:
                  type: string
                  nullable: false
                roll_no:
                  type: integer
                  nullable: false
                age:
                  type: integer
                  nullable: false
                phone:
                  type: string
                  nullable: false
        required: true
      responses:
        "204":
          description: The students has been updated.
      x-metadata:
        database: database-proxy
        schema: money
        table: students
    delete:
      tags:
      - students
      summary: Delete students by id
      description: Auto Generated
      operationId: delete_students_by_id
      parameters:
      - name: name
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: Deleted students successfully.
      x-metadata:
        database: database-proxy
        schema: money
        table: students
  /openapi:
    get:
      tags:
      - Open API
      summary: Get OpenAPI
      description: Auto Generated Open API
      operationId: getOpenApi
      responses:
        "200":
          description: The Open API Spec
          content:
            application/json:
              schema:
                type: object
                example: |-
                  {
                    "openapi" : "3.0.1",
                    "info" : {
                      "title" : "Auto Generated Open API",
                      "description" : "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
                      "version" : "1.0.1"
                    },
                    "servers" : [ {
                      "url" : "/",
                      "description" : "Optional server description, e.g. Main (production) server"
                    } ],
                    "paths" : {
                      "/cars" : {
                        "get" : {
                          "summary" : "Returns a list of cars",
                          "operationId" : "get_cars",
                          "responses" : {
                            "200" : {
                              "description" : "A JSON array of cars",
                              "content" : {
                                "application/json" : {
                                  "schema" : {
                                    "type" : "array",
                                    "items" : {
                                      "required" : [ "id", "name", "doors" ],
                                      "type" : "object",
                                      "properties" : {
                                        "id" : {
                                          "type" : "integer",
                                          "example" : "1"
                                        },
                                        "name" : {
                                          "type" : "string",
                                          "example" : "Ferrari"
                                        },
                                        "doors" : {
                                          "type" : "integer",
                                          "example" : "5"
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
      x-metadata: {}
components:
  schemas:
    ANY:
      description: "Can be anything: string, number, array, object, etc., including\
        \ `null`"

It seems some of the schema properties are duplicate.

mcadecio commented 10 months ago

Supported as of 1.0.2