All Projects → jdkandersson → OpenAlchemy

jdkandersson / OpenAlchemy

Licence: Apache-2.0 license
Define SQLAlchemy models using the OpenAPI specification.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to OpenAlchemy

oas
OpenAPI Spec builder in go
Stars: ✭ 15 (-61.54%)
Mutual labels:  openapi, openapi-specification, openapi3
Spectral
A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI v2 & v3.
Stars: ✭ 876 (+2146.15%)
Mutual labels:  openapi, openapi-specification, openapi3
Apispec
A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..
Stars: ✭ 831 (+2030.77%)
Mutual labels:  openapi, openapi-specification, openapi3
Swagger Ui
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
Stars: ✭ 21,279 (+54461.54%)
Mutual labels:  openapi, openapi-specification, openapi3
openapi
OpenAPI 3 Specification for golang
Stars: ✭ 18 (-53.85%)
Mutual labels:  openapi, openapi-specification, openapi3
Swagger Parser
Swagger Spec to Java POJOs
Stars: ✭ 468 (+1100%)
Mutual labels:  openapi, openapi-specification, openapi3
openapi4j
OpenAPI 3 parser, JSON schema and request validator.
Stars: ✭ 92 (+135.9%)
Mutual labels:  openapi, openapi-specification, openapi3
Swagger Core
Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
Stars: ✭ 6,898 (+17587.18%)
Mutual labels:  openapi, openapi-specification, openapi3
Swurg
Parse OpenAPI documents into Burp Suite for automating OpenAPI-based APIs security assessments (approved by PortSwigger for inclusion in their official BApp Store).
Stars: ✭ 94 (+141.03%)
Mutual labels:  openapi, openapi-specification, openapi3
Openapivalidators
Use Jest or Chai to assert that HTTP responses satisfy an OpenAPI spec
Stars: ✭ 77 (+97.44%)
Mutual labels:  openapi, openapi-specification, openapi3
Openapi.tools
A collection of Editors, Linters, Parsers, Code Generators, Documentation, Testing
Stars: ✭ 257 (+558.97%)
Mutual labels:  openapi, openapi-specification, openapi3
Openapi Diff
Utility for comparing two OpenAPI specifications.
Stars: ✭ 208 (+433.33%)
Mutual labels:  openapi, openapi-specification, openapi3
go-openapi
OpenAPI Specification (OAS) 3.0 implementation for Go
Stars: ✭ 38 (-2.56%)
Mutual labels:  openapi, openapi-specification, openapi3
Oas Kit
Convert Swagger 2.0 definitions to OpenAPI 3.0 and resolve/validate/lint
Stars: ✭ 516 (+1223.08%)
Mutual labels:  openapi, openapi-specification, openapi3
openapi-schemas
JSON Schemas for every version of the OpenAPI Specification
Stars: ✭ 22 (-43.59%)
Mutual labels:  openapi, openapi-specification, openapi3
Springdoc Openapi
Library for OpenAPI 3 with spring-boot
Stars: ✭ 1,113 (+2753.85%)
Mutual labels:  openapi, openapi-specification, openapi3
Redoc
📘 OpenAPI/Swagger-generated API Reference Documentation
Stars: ✭ 15,935 (+40758.97%)
Mutual labels:  openapi, openapi-specification, openapi3
Safrs
SqlAlchemy Flask-Restful Swagger Json:API OpenAPI
Stars: ✭ 255 (+553.85%)
Mutual labels:  sqlalchemy, openapi, openapi3
specifications-ITS-REST
openEHR REST API Specifications
Stars: ✭ 20 (-48.72%)
Mutual labels:  openapi, openapi3
oaie-sketch
OpenAPI Visual Editor
Stars: ✭ 54 (+38.46%)
Mutual labels:  openapi, openapi3

OpenAlchemy

Code Quality Status Azure DevOps coverage Documentation Status Code Climate maintainability Code Climate technical debt LGTM Grade

Translates an OpenAPI schema to SQLAlchemy models.

Supports OpenAPI 3.0 and 3.1.

Installation

python -m pip install OpenAlchemy
# To be able to load YAML file
python -m pip install OpenAlchemy[yaml]

Example

For example, given the following OpenAPI specification:

# ./examples/simple/example-spec.yml
openapi: "3.0.0"

info:
  title: Test Schema
  description: API to illustrate OpenAlchemy MVP.
  version: "0.1"

paths:
  /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:
    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
          x-autoincrement: true
        name:
          type: string
          description: The name of the employee.
          example: David Andersson
          x-index: true
        division:
          type: string
          description: The part of the company the employee works in.
          example: Engineering
          x-index: true
        salary:
          type: number
          description: The amount of money the employee is paid.
          example: 1000000.00
      required:
        - id
        - name
        - division

The SQLALchemy models file then becomes:

# models.py
from open_alchemy import init_yaml

init_yaml("./examples/simple/example-spec.yml")

The Base and Employee objects can be accessed:

from open_alchemy.models import Base
from open_alchemy.models import Employee

With the models_filename parameter a file is auto generated with type hints for the SQLAlchemy models at the specified location, for example: type hinted models example. This adds support for IDE auto complete, for example for the model initialization:

autocomplete init

and for properties and methods available on an instance:

autocomplete instance

An extensive set of examples with a range of features is here:

examples for main features

An example API has been defined using connexion and Flask here:

example connexion app

Documentation

Read the Docs

Buy me a coffee

Buy Me A Coffee

Features

  • initializing from JSON,
  • initializing from YAML,
  • build a package with the models for distribution, packaged as sdist or wheel,
  • automatically generate a models file,
  • integer (32 and 64 bit),
  • number (float only),
  • boolean,
  • string,
  • password,
  • byte,
  • binary,
  • date,
  • date-time,
  • generic JSON data,
  • $ref references for columns and models,
  • remote $ref to other files on the same file system (not supported on Windows),
  • remote $ref to other files at a URL,
  • primary keys,
  • auto incrementing,
  • indexes,
  • composite indexes,
  • unique constraints,
  • composite unique constraints,
  • column nullability,
  • foreign keys,
  • default values for columns (both application and database side),
  • many to one relationships,
  • one to one relationships,
  • one to many relationships,
  • many to many relationships,
  • many to many relationships with custom association tables,
  • custom foreign keys for relationships,
  • back references for relationships,
  • allOf inheritance for columns and models,
  • joined and single table inheritance,
  • from_str model methods to construct from JSON string,
  • from_dict model methods to construct from dictionaries,
  • to_str model methods to convert instances to JSON string,
  • __str__ model methods to support the python str function,
  • __repr__ model methods to support the python repr function,
  • to_dict model methods to convert instances to dictionaries,
  • readOnly and writeOnly for influence the conversion to and from dictionaries,
  • exposing created models under open_alchemy.models removing the need for models.py files,
  • ability to mix in arbitrary classes into a model,
  • can use the short x- prefix or a namespaced x-open-alchemy- prefix for extension properties and
  • grouping models into schemas.

Contributing

Fork and checkout the repository. To install:

poetry install

To run tests:

poetry run pytest

Make your changes and raise a pull request.

Compiling Docs

poetry shell
cd docs
make html

This creates the index.html file in docs/build/html/index.html.

Release Commands

rm -r dist/*
poetry build
poetry publish
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].