Skip to content

Many-to-many relationship specification doesn't work #448

@al3ad

Description

@al3ad

Using OpenAPI generator 7.1.0 I attempted to generate the YAML spec provided on the tutorial.

However, when I do that I get the following error:

Traceback (most recent call last):
  File "/usr/src/app/./openapi_server/__main__.py", line 29, in <module>
    app = create_app(app_config)
  File "/usr/src/app/./openapi_server/__init__.py", line 45, in create_app
    init_yaml(spec_file, base=SQLALCHEMY_DB.Model, models_filename=models_filename)
  File "/usr/local/lib/python3.8/dist-packages/open_alchemy/__init__.py", line 206, in init_yaml
    return _init_optional_base(
  File "/usr/local/lib/python3.8/dist-packages/open_alchemy/__init__.py", line 122, in _init_optional_base
    init_model_factory(
  File "/usr/local/lib/python3.8/dist-packages/open_alchemy/__init__.py", line 67, in init_model_factory
    _schemas_module.process(schemas=schemas, spec_filename=spec_path)
  File "/usr/local/lib/python3.8/dist-packages/open_alchemy/schemas/__init__.py", line 25, in process
    validation.process(schemas=schemas, spec_filename=spec_filename)
  File "/usr/local/lib/python3.8/dist-packages/open_alchemy/schemas/validation/__init__.py", line 130, in process
    raise _exceptions.MalformedSchemaError(other_results_result.reason)
open_alchemy.exceptions.MalformedSchemaError: duplicate "x-tablename" value project defined on the schema Employee_projects_inner, already defined on the schema Project      
unable to load app 0 (mountpoint='/') (callable not found or import error)

I'm not sure if the problem is with my setup or with openAlchemy?

Here's the YAML spec for convenience:

openapi: "3.0.0"

info:
  title: Test Schema
  description: API to illustrate Many to Many Relationships.
  version: "0.1"

paths:
  /project:
    get:
      summary: Used to retrieve all projects.
      responses:
        200:
          description: Return all projects from the database.
          content:
            application/json:
              schema:
                type: array
                items:
                  "$ref": "#/components/schemas/Project"
  /employee:
    get:
      summary: Used to retrieve all employees.
      responses:
        200:
          description: Return all employees from the database.
          content:
            application/json:
              schema:
                type: array
                items:
                  "$ref": "#/components/schemas/Employee"

components:
  schemas:
    Project:
      description: A large sized business objective.
      type: object
      x-tablename: project
      properties:
        id:
          type: integer
          description: Unique identifier for the project.
          example: 0
          x-primary-key: true
        name:
          type: string
          description: The name of the project.
          example: Expand to the USA
    Employee:
      description: Person that works for a company.
      type: object
      x-tablename: employee
      properties:
        id:
          type: integer
          description: Unique identifier for the employee.
          example: 0
          x-primary-key: true
        name:
          type: string
          description: The name of the employee.
          example: David Andersson
        projects:
          type: array
          items:
            allOf:
              - "$ref": "#/components/schemas/Project"
              - x-secondary: employee_project
          description: The projects the employee is working on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions