Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ jobs:
poetry install
- name: Run static code analyser
run: |
${{ matrix.command }}
${{ matrix.command }} || (poetry install && ${{ matrix.command }})

staticNode:
runs-on: ubuntu-latest
strategy:
matrix:
command:
- npx cspell "open_alchemy/**/*.py" "open_alchemy/**/*.json" "open_alchemy/**/*.j2" "docs/**/*.rst" "docs/**/*/yml" "docs/**/*.yaml" "tests/**/*.py" "*.yaml" "*.json" "*.yml" "examples/**/*.py" "examples/**/*.yaml" "examples/**/*.yml"
- find examples -name "*spec.yml" ! -path "*/remote/*" | xargs -n 1 sh -c 'npx swagger-cli validate $0 || exit 255'
- find examples -name "*spec.yml" ! -path "*/remote/*" ! -path "*/openapi-3-1/*" | xargs -n 1 sh -c 'npx swagger-cli validate $0 || exit 255'
steps:
- uses: actions/checkout@v2
- name: Set up Node
Expand Down Expand Up @@ -155,7 +155,7 @@ jobs:
- name: Build the documentation
run: |
cd docs
poetry run make html
poetry run make html || (poetry install && poetry run make html)
- name: Upload documentation for release
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v2.2.2
Expand Down Expand Up @@ -271,21 +271,19 @@ jobs:
shell: bash
- uses: actions/checkout@v2
- name: Get latest Changelog Entry
id: changelog_entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v2
with:
version: v${{ steps.tag_name.outputs.current_version }}
path: ./CHANGELOG.md
- name: Retrieve packages
uses: actions/download-artifact@v2.0.8
with:
name: wheel
path: dist/
- name: Publish the release
uses: softprops/action-gh-release@v1
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: ${{ steps.changelog_entry.outputs.log_entry }}
files: |
dist/*
tag_name: ${{ steps.changelog_reader.outputs.version }}
release_name: Release ${{ steps.changelog_reader.outputs.version }}
body: ${{ steps.changelog_reader.outputs.changes }}
prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }}
draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }}
63 changes: 34 additions & 29 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v2.2.0] - 2021-01-23
### Added

- Add support for OpenAPI 3.1. [#276]

## [2.2.0] - 2021-01-23

### Fixed

Expand All @@ -17,27 +21,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Caching validation results to speed up startup. [#251]

## [v2.1.0] - 2020-12-20
## [2.1.0] - 2020-12-20

### Added

- Add support for namespaced `x-open-alchemy-` prefix on top of the shorter
`x-` prefix for extension properties. [#236]

## [v2.0.2] - 2020-12-19
## [2.0.2] - 2020-12-19

### Changed

- Changed from `setup.py` to poetry

## [v2.0.1] - 2020-12-08
## [2.0.1] - 2020-12-08

### Added

- Add version, title and description (if defined) into the JSON OpenAPI
specification stored with the package generated by the build module.

## [v2.0.0] - 2020-11-15
## [2.0.0] - 2020-11-15

### Added

Expand Down Expand Up @@ -79,7 +83,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`True`. _This means that a pure model reference (a schema with only the
`$ref` key) can no longer be used to change the name of a model._ [#189]

## [v1.6.0] - 2020-10-10
## [1.6.0] - 2020-10-10

### Added

Expand All @@ -94,7 +98,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
directory.
- Drop support for Python 3.6 and add support for Python 3.9. [#198]

## [v1.5.4] - 2020-08-30
## [1.5.4] - 2020-08-30

### Changed

Expand All @@ -106,20 +110,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Correct `format` key to no longer have a trailing `_` for artifacts.

## [v1.5.2] - 2020-08-29
## [1.5.2] - 2020-08-29

### Changed

- Expose function that collects artifacts for the models.
- Expose function that collects artifacts for the model properties.

## [v1.5.1] - 2020-08-23
## [1.5.1] - 2020-08-23

### Added

- Add support for arbitrary mix in classes.

## [v1.5.0] - 2020-08-22
## [1.5.0] - 2020-08-22

### Added

Expand All @@ -135,27 +139,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Change schema validation to process properties even if the model is not
valid.

## [v1.4.3] - 2020-08-16
## [1.4.3] - 2020-08-16

### Removed

- Remove dependency on black

## [v1.4.2] - 2020-08-16
## [1.4.2] - 2020-08-16

### Fixed

- Fix bug where iterating over constructable schemas did not handle some
exceptions
- Add black dependency back in

## [v1.4.1] - 2020-08-09
## [1.4.1] - 2020-08-09

### Removed

- Remove black dependency

## [v1.4.0] - 2020-08-09
## [1.4.0] - 2020-08-09

### Added

Expand Down Expand Up @@ -480,21 +484,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[1.1.1]: https://github.com/jdkandersson/OpenAlchemy/releases/1.1.1
[1.2.0]: https://github.com/jdkandersson/OpenAlchemy/releases/1.2.0
[1.3.0]: https://github.com/jdkandersson/OpenAlchemy/releases/1.3.0
[v1.4.0]: https://github.com/jdkandersson/OpenAlchemy/releases/1.4.0
[v1.4.1]: https://github.com/jdkandersson/OpenAlchemy/releases/1.4.1
[v1.4.2]: https://github.com/jdkandersson/OpenAlchemy/releases/1.4.2
[v1.4.3]: https://github.com/jdkandersson/OpenAlchemy/releases/1.4.3
[v1.5.0]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.0
[v1.5.1]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.1
[v1.5.2]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.2
[v1.5.3]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.3
[v1.5.4]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.4
[v1.6.0]: https://github.com/jdkandersson/OpenAlchemy/releases/1.6.0
[v2.0.0]: https://github.com/jdkandersson/OpenAlchemy/releases/2.0.0
[v2.0.1]: https://github.com/jdkandersson/OpenAlchemy/releases/2.0.1
[v2.0.2]: https://github.com/jdkandersson/OpenAlchemy/releases/2.0.2
[v2.1.0]: https://github.com/jdkandersson/OpenAlchemy/releases/2.1.0
[v2.2.0]: https://github.com/jdkandersson/OpenAlchemy/releases/2.2.0
[1.4.0]: https://github.com/jdkandersson/OpenAlchemy/releases/1.4.0
[1.4.1]: https://github.com/jdkandersson/OpenAlchemy/releases/1.4.1
[1.4.2]: https://github.com/jdkandersson/OpenAlchemy/releases/1.4.2
[1.4.3]: https://github.com/jdkandersson/OpenAlchemy/releases/1.4.3
[1.5.0]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.0
[1.5.1]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.1
[1.5.2]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.2
[1.5.3]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.3
[1.5.4]: https://github.com/jdkandersson/OpenAlchemy/releases/1.5.4
[1.6.0]: https://github.com/jdkandersson/OpenAlchemy/releases/1.6.0
[2.0.0]: https://github.com/jdkandersson/OpenAlchemy/releases/2.0.0
[2.0.1]: https://github.com/jdkandersson/OpenAlchemy/releases/2.0.1
[2.0.2]: https://github.com/jdkandersson/OpenAlchemy/releases/2.0.2
[2.1.0]: https://github.com/jdkandersson/OpenAlchemy/releases/2.1.0
[2.2.0]: https://github.com/jdkandersson/OpenAlchemy/releases/2.2.0
[///]: # "Issue/PR links"
[#189]: https://github.com/jdkandersson/OpenAlchemy/issues/189
[#190]: https://github.com/jdkandersson/OpenAlchemy/issues/190
Expand All @@ -505,3 +509,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#236]: https://github.com/jdkandersson/OpenAlchemy/issues/236
[#251]: https://github.com/jdkandersson/OpenAlchemy/issues/251
[#255]: https://github.com/jdkandersson/OpenAlchemy/issues/255
[#276]: https://github.com/jdkandersson/OpenAlchemy/issues/276
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

Translates an OpenAPI schema to SQLAlchemy models.

Supports OpenAPI 3.0 and 3.1.

Get started with the online editor that will guide you through using your
existing OpenAPI specification to define your database schema and offers
installing your models using `pip`:
Expand Down
3 changes: 3 additions & 0 deletions docs/source/examples/alembic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ models which means that they work with Alembic.

`Alembic documentation <https://alembic.sqlalchemy.org/en/latest/>`_
Documentation for Alembic.

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/all_of.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/all_of/model_models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/composite_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/composite_index/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/composite_unique.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/composite_unique/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/connexion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ The duplication of the data schema has been reduced by defining the SQLAlchemy
models based on the OpenAPI specification. This means that, to change the
database schema, the OpenAPI specification has to be updated and vice-versa.
This ensures that the two are always in synch and up to date.

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/default/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
1 change: 1 addition & 0 deletions docs/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Examples
connexion
alembic
simple
nullable
namespaced
default
server_default
Expand Down
3 changes: 3 additions & 0 deletions docs/source/examples/inheritance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/inheritance/single_models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/json/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/mixins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/mixins/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/namespaced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ SQLAlchemy models:
.. literalinclude:: ../../../examples/namespaced/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
39 changes: 39 additions & 0 deletions docs/source/examples/nullable.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Nullable
========

A property can be set to be nullable using the :samp:`nullable` property for
OpenAPI 3.0:

.. literalinclude:: ../../../examples/nullable/openapi-3-0/example-spec.yml
:language: yaml
:linenos:

Or by including :samp:`null` in the :samp:`type` array for OpenAPI 3.1:

.. literalinclude:: ../../../examples/nullable/openapi-3-1/example-spec.yml
:language: yaml
:linenos:

The following example models file makes use of the OpenAPI specification to
define the SQLAlchemy models:

.. literalinclude:: ../../../examples/nullable/openapi-3-1/models.py
:language: python
:linenos:

This models file instructs OpenAlchemy to construct the SQLAlchemy models
equivalent to the following traditional SQLAlchemy models.py file:

.. literalinclude:: ../../../examples/nullable/openapi-3-1/models_traditional.py
:language: python
:linenos:

OpenAlchemy also generates a fully type hinted version of the generated
SQLAlchemy models:

.. literalinclude:: ../../../examples/nullable/openapi-3-1/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/read_only.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/read_only/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/ref/model_models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/server_default.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/server_default/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
3 changes: 3 additions & 0 deletions docs/source/examples/write_only.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ OpenAlchemy will generate the following typed models:
.. literalinclude:: ../../../examples/write_only/models_auto.py
:language: python
:linenos:

.. seealso::
:ref:`getting-started`
9 changes: 5 additions & 4 deletions docs/source/technical_details/null.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ There are 3 methods used to determine the value of :samp:`nullable` for a
:samp:`SQLAlchemy` column. The first is the :samp:`required` property of the
schema, the second is whether the column value is generated (using, for
example, :samp:`x-autoincrement`) and the third is the :samp:`nullable`
property of an object property. :samp:`nullable` overrides :samp:`required`.
If :samp:`required` would indicate that the column is nullable but the value
is generated, then it is not nullable. The following truth table shows the
logic:
property of an object property or the presence of :samp:`null` if :samp:`type`
is an array (consider these to be equivalent for this discussion).
:samp:`nullable` overrides :samp:`required`. If :samp:`required` would indicate
that the column is nullable but the value is generated, then it is not
nullable. The following truth table shows the logic:

+-------------+-----------+-------------------+-----------------+
| required | generated | property nullable | column nullable |
Expand Down
3 changes: 3 additions & 0 deletions docs/source/technical_details/type_mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ following mappings:
| :samp:`boolean` | | :samp:`Boolean` | :samp:`bool` |
+----------------------+------------------------+-------------------------+---------------------------+

:samp:`type` as an array is supported, however, exactly one type (other than
:samp:`null`) is required.

String
------

Expand Down
Loading