surety-scaffold 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- surety_scaffold-0.0.1/.github/workflows/publish.yml +30 -0
- surety_scaffold-0.0.1/.github/workflows/pylint.yml +24 -0
- surety_scaffold-0.0.1/.github/workflows/release.yml +41 -0
- surety_scaffold-0.0.1/.github/workflows/test.yml +53 -0
- surety_scaffold-0.0.1/.gitignore +210 -0
- surety_scaffold-0.0.1/LICENSE +21 -0
- surety_scaffold-0.0.1/PKG-INFO +173 -0
- surety_scaffold-0.0.1/README.md +134 -0
- surety_scaffold-0.0.1/pyproject.toml +43 -0
- surety_scaffold-0.0.1/requirements/base.txt +0 -0
- surety_scaffold-0.0.1/requirements/test.txt +0 -0
- surety_scaffold-0.0.1/setup.cfg +4 -0
- surety_scaffold-0.0.1/surety/scaffold/__init__.py +3 -0
- surety_scaffold-0.0.1/surety/scaffold/cli.py +72 -0
- surety_scaffold-0.0.1/surety/scaffold/extract/__init__.py +0 -0
- surety_scaffold-0.0.1/surety/scaffold/extract/base.py +24 -0
- surety_scaffold-0.0.1/surety/scaffold/extract/json_extractor.py +110 -0
- surety_scaffold-0.0.1/surety/scaffold/extract/renderer.py +82 -0
- surety_scaffold-0.0.1/surety/scaffold/extract/type_extractor.py +59 -0
- surety_scaffold-0.0.1/surety_scaffold.egg-info/PKG-INFO +173 -0
- surety_scaffold-0.0.1/surety_scaffold.egg-info/SOURCES.txt +31 -0
- surety_scaffold-0.0.1/surety_scaffold.egg-info/dependency_links.txt +1 -0
- surety_scaffold-0.0.1/surety_scaffold.egg-info/entry_points.txt +2 -0
- surety_scaffold-0.0.1/surety_scaffold.egg-info/requires.txt +3 -0
- surety_scaffold-0.0.1/surety_scaffold.egg-info/top_level.txt +1 -0
- surety_scaffold-0.0.1/tests/__init__.py +0 -0
- surety_scaffold-0.0.1/tests/extract/__init__.py +0 -0
- surety_scaffold-0.0.1/tests/extract/render_data.py +208 -0
- surety_scaffold-0.0.1/tests/extract/test_extract_from_json.py +171 -0
- surety_scaffold-0.0.1/tests/extract/test_json_extract.py +38 -0
- surety_scaffold-0.0.1/tests/extract/test_render.py +114 -0
- surety_scaffold-0.0.1/tests/extract/test_type_extract.py +91 -0
- surety_scaffold-0.0.1/tests/test_cli.py +135 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_run:
|
|
5
|
+
workflows: ["Create Release"]
|
|
6
|
+
types: [completed]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
deploy:
|
|
10
|
+
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
with:
|
|
16
|
+
fetch-depth: 0
|
|
17
|
+
- name: Set up Python
|
|
18
|
+
uses: actions/setup-python@v2
|
|
19
|
+
with:
|
|
20
|
+
python-version: '3.x'
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: |
|
|
23
|
+
python -m pip install --upgrade pip
|
|
24
|
+
pip install build
|
|
25
|
+
- name: Build package
|
|
26
|
+
run: python -m build
|
|
27
|
+
- name: Publish package
|
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
29
|
+
with:
|
|
30
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Pylint
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
lint:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
strategy:
|
|
9
|
+
matrix:
|
|
10
|
+
python-version: ["3.9", "3.10", "3.11"]
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v3
|
|
13
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
14
|
+
uses: actions/setup-python@v3
|
|
15
|
+
with:
|
|
16
|
+
python-version: ${{ matrix.python-version }}
|
|
17
|
+
- name: Install dependencies
|
|
18
|
+
run: |
|
|
19
|
+
python -m pip install --upgrade pip
|
|
20
|
+
pip install -r requirements/test.txt
|
|
21
|
+
pip install -e .
|
|
22
|
+
- name: Analysing the code with pylint
|
|
23
|
+
run:
|
|
24
|
+
python -m pylint surety/scaffold tests
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Create Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
tag-and-release:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
|
|
24
|
+
- run: pip install build setuptools-scm
|
|
25
|
+
|
|
26
|
+
- name: Build package
|
|
27
|
+
run: python -m build
|
|
28
|
+
|
|
29
|
+
- name: Create tag
|
|
30
|
+
id: tag
|
|
31
|
+
uses: anothrNick/github-tag-action@1.67.0
|
|
32
|
+
env:
|
|
33
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
34
|
+
DEFAULT_BUMP: patch
|
|
35
|
+
WITH_V: true
|
|
36
|
+
|
|
37
|
+
- name: Create GitHub Release
|
|
38
|
+
uses: softprops/action-gh-release@v2
|
|
39
|
+
with:
|
|
40
|
+
tag_name: ${{ steps.tag.outputs.new_tag }}
|
|
41
|
+
files: dist/*
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
permissions: write-all
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Set up Python
|
|
18
|
+
uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.10"
|
|
21
|
+
cache: "pip"
|
|
22
|
+
cache-dependency-path: |
|
|
23
|
+
requirements/test.txt
|
|
24
|
+
pyproject.toml
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: |
|
|
28
|
+
python -m pip install --upgrade pip
|
|
29
|
+
pip install -r requirements/test.txt
|
|
30
|
+
pip install -e .
|
|
31
|
+
|
|
32
|
+
- name: Run tests
|
|
33
|
+
run: |
|
|
34
|
+
pytest \
|
|
35
|
+
--cache-clear \
|
|
36
|
+
--junitxml=test-report.xml \
|
|
37
|
+
--cov=surety/scaffold \
|
|
38
|
+
--cov-report=term-missing:skip-covered \
|
|
39
|
+
--cov-report=xml \
|
|
40
|
+
> pytest-coverage.txt
|
|
41
|
+
|
|
42
|
+
- name: Pytest coverage comment
|
|
43
|
+
if: always()
|
|
44
|
+
uses: MishaKav/pytest-coverage-comment@main
|
|
45
|
+
with:
|
|
46
|
+
pytest-coverage-path: pytest-coverage.txt
|
|
47
|
+
junitxml-path: test-report.xml
|
|
48
|
+
|
|
49
|
+
- name: Publish test report
|
|
50
|
+
if: always()
|
|
51
|
+
uses: elenakulgavaya/pytest-report-action@v1.3
|
|
52
|
+
with:
|
|
53
|
+
path: test-report.xml
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# packaging fixes
|
|
7
|
+
*/__init__.pyi
|
|
8
|
+
|
|
9
|
+
# C extensions
|
|
10
|
+
*.so
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
.Python
|
|
14
|
+
build/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
dist/
|
|
17
|
+
downloads/
|
|
18
|
+
eggs/
|
|
19
|
+
.eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
wheels/
|
|
26
|
+
share/python-wheels/
|
|
27
|
+
*.egg-info/
|
|
28
|
+
.installed.cfg
|
|
29
|
+
*.egg
|
|
30
|
+
MANIFEST
|
|
31
|
+
|
|
32
|
+
# PyInstaller
|
|
33
|
+
# Usually these files are written by a python script from a template
|
|
34
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
35
|
+
*.manifest
|
|
36
|
+
*.spec
|
|
37
|
+
|
|
38
|
+
# Installer logs
|
|
39
|
+
pip-log.txt
|
|
40
|
+
pip-delete-this-directory.txt
|
|
41
|
+
|
|
42
|
+
# Unit test / coverage reports
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cache
|
|
49
|
+
nosetests.xml
|
|
50
|
+
coverage.xml
|
|
51
|
+
*.cover
|
|
52
|
+
*.py.cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
.pytest_cache/
|
|
55
|
+
cover/
|
|
56
|
+
|
|
57
|
+
# Translations
|
|
58
|
+
*.mo
|
|
59
|
+
*.pot
|
|
60
|
+
|
|
61
|
+
# Django stuff:
|
|
62
|
+
*.log
|
|
63
|
+
local_settings.py
|
|
64
|
+
db.sqlite3
|
|
65
|
+
db.sqlite3-journal
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
.pybuilder/
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
|
|
84
|
+
# IPython
|
|
85
|
+
profile_default/
|
|
86
|
+
ipython_config.py
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
90
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
91
|
+
# .python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# UV
|
|
101
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
102
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
103
|
+
# commonly ignored for libraries.
|
|
104
|
+
#uv.lock
|
|
105
|
+
|
|
106
|
+
# poetry
|
|
107
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
108
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
109
|
+
# commonly ignored for libraries.
|
|
110
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
111
|
+
#poetry.lock
|
|
112
|
+
#poetry.toml
|
|
113
|
+
|
|
114
|
+
# pdm
|
|
115
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
116
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
117
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
118
|
+
#pdm.lock
|
|
119
|
+
#pdm.toml
|
|
120
|
+
.pdm-python
|
|
121
|
+
.pdm-build/
|
|
122
|
+
|
|
123
|
+
# pixi
|
|
124
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
125
|
+
#pixi.lock
|
|
126
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
127
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
128
|
+
.pixi
|
|
129
|
+
|
|
130
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
131
|
+
__pypackages__/
|
|
132
|
+
|
|
133
|
+
# Celery stuff
|
|
134
|
+
celerybeat-schedule
|
|
135
|
+
celerybeat.pid
|
|
136
|
+
|
|
137
|
+
# SageMath parsed files
|
|
138
|
+
*.sage.py
|
|
139
|
+
|
|
140
|
+
# Environments
|
|
141
|
+
.env
|
|
142
|
+
.envrc
|
|
143
|
+
.venv
|
|
144
|
+
env/
|
|
145
|
+
venv/
|
|
146
|
+
ENV/
|
|
147
|
+
env.bak/
|
|
148
|
+
venv.bak/
|
|
149
|
+
|
|
150
|
+
# Spyder project settings
|
|
151
|
+
.spyderproject
|
|
152
|
+
.spyproject
|
|
153
|
+
|
|
154
|
+
# Rope project settings
|
|
155
|
+
.ropeproject
|
|
156
|
+
|
|
157
|
+
# mkdocs documentation
|
|
158
|
+
/site
|
|
159
|
+
|
|
160
|
+
# mypy
|
|
161
|
+
.mypy_cache/
|
|
162
|
+
.dmypy.json
|
|
163
|
+
dmypy.json
|
|
164
|
+
|
|
165
|
+
# Pyre type checker
|
|
166
|
+
.pyre/
|
|
167
|
+
|
|
168
|
+
# pytype static type analyzer
|
|
169
|
+
.pytype/
|
|
170
|
+
|
|
171
|
+
# Cython debug symbols
|
|
172
|
+
cython_debug/
|
|
173
|
+
|
|
174
|
+
# PyCharm
|
|
175
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
176
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
177
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
178
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
179
|
+
#.idea/
|
|
180
|
+
|
|
181
|
+
# Abstra
|
|
182
|
+
# Abstra is an AI-powered process automation framework.
|
|
183
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
184
|
+
# Learn more at https://abstra.io/docs
|
|
185
|
+
.abstra/
|
|
186
|
+
|
|
187
|
+
# Visual Studio Code
|
|
188
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
189
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
190
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
191
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
192
|
+
# .vscode/
|
|
193
|
+
|
|
194
|
+
# Ruff stuff:
|
|
195
|
+
.ruff_cache/
|
|
196
|
+
|
|
197
|
+
# PyPI configuration file
|
|
198
|
+
.pypirc
|
|
199
|
+
|
|
200
|
+
# Cursor
|
|
201
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
202
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
203
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
204
|
+
.cursorignore
|
|
205
|
+
.cursorindexingignore
|
|
206
|
+
|
|
207
|
+
# Marimo
|
|
208
|
+
marimo/_static/
|
|
209
|
+
marimo/_lsp/
|
|
210
|
+
__marimo__/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Elena Kulgavaya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: surety-scaffold
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Code generation for surety contracts
|
|
5
|
+
Author-email: Elena Kulgavaya <elena.kulgavaya@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Elena Kulgavaya
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Keywords: api,contract-testing,automation,codegen,surety
|
|
29
|
+
Classifier: Programming Language :: Python :: 3
|
|
30
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
31
|
+
Classifier: Operating System :: OS Independent
|
|
32
|
+
Requires-Python: >=3.9
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: surety<1.0,>=0.0.4
|
|
36
|
+
Requires-Dist: pyyaml>=6.0
|
|
37
|
+
Requires-Dist: jsonschema>=4.0
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# surety-scaffold
|
|
41
|
+
|
|
42
|
+
Code generation toolkit for the [surety](https://github.com/elenakulgavaya/surety) contract-testing framework.
|
|
43
|
+
|
|
44
|
+
Bootstraps surety schemas, contracts, callers, and test scaffolding from existing JSON payloads, JSON Schema, and OpenAPI specs — so you can start contract-based testing without writing boilerplate by hand.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install surety-scaffold
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Requires `surety>=0.0.4`.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
### Extract contract from JSON
|
|
61
|
+
|
|
62
|
+
Turn a raw JSON payload into surety `Dictionary` class definitions.
|
|
63
|
+
|
|
64
|
+
**Programmatic:**
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import json
|
|
68
|
+
from surety.scaffold import extract_from_json
|
|
69
|
+
|
|
70
|
+
payload = json.dumps({
|
|
71
|
+
"order_id": 42,
|
|
72
|
+
"status": "pending",
|
|
73
|
+
"total": 199.99,
|
|
74
|
+
"is_express": False,
|
|
75
|
+
"customer": {
|
|
76
|
+
"customer_id": 7,
|
|
77
|
+
"email": "jane@example.com"
|
|
78
|
+
},
|
|
79
|
+
"items": [
|
|
80
|
+
{"sku": "ABC-1", "qty": 2}
|
|
81
|
+
]
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
print(extract_from_json(payload, class_name="Order"))
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Output:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from surety import Array, Bool, Dictionary, Float, Int, String
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class Customer(Dictionary):
|
|
94
|
+
CustomerId = Int(name='customer_id', required=True)
|
|
95
|
+
Email = String(name='email', required=True)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class Items(Dictionary):
|
|
99
|
+
Sku = String(name='sku', required=True)
|
|
100
|
+
Qty = Int(name='qty', required=True)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class Order(Dictionary):
|
|
104
|
+
OrderId = Int(name='order_id', required=True)
|
|
105
|
+
Status = String(name='status', required=True)
|
|
106
|
+
Total = Float(name='total', required=True)
|
|
107
|
+
IsExpress = Bool(name='is_express', required=True)
|
|
108
|
+
Customer = Customer(name='customer', required=True)
|
|
109
|
+
Items = Array(Items, name='items', required=True)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Type inference rules:**
|
|
113
|
+
|
|
114
|
+
| JSON value | Surety type |
|
|
115
|
+
|------------|-------------|
|
|
116
|
+
| `true` / `false` | `Bool` |
|
|
117
|
+
| integer | `Int` |
|
|
118
|
+
| float | `Float` |
|
|
119
|
+
| UUID string | `Uuid` |
|
|
120
|
+
| ISO 8601 datetime or date string | `DateTime` |
|
|
121
|
+
| any other string | `String` |
|
|
122
|
+
| object `{}` | nested `Dictionary` subclass |
|
|
123
|
+
| array of objects | `Array(NestedClass, ...)` |
|
|
124
|
+
| array of primitives | `Array(PrimitiveType, ...)` |
|
|
125
|
+
| `null` | `String(allow_none=True)` |
|
|
126
|
+
|
|
127
|
+
Nested objects produce their own `Dictionary` subclass and are always emitted before the class that references them. Arrays of objects merge all items across the array to capture the full set of fields. Duplicate class names (same key appearing at different nesting levels) are disambiguated automatically with a numeric suffix.
|
|
128
|
+
|
|
129
|
+
**Key naming:**
|
|
130
|
+
JSON keys are converted to `PascalCase` for both the class attribute name and the generated class name. `snake_case`, `camelCase`, and `kebab-case` are all handled.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
**CLI:**
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# Pass JSON as an argument
|
|
138
|
+
surety-scaffold '{"order_id": 1, "status": "pending"}' --class-name Order
|
|
139
|
+
|
|
140
|
+
# Pipe from a file or command
|
|
141
|
+
cat response.json | surety-scaffold --class-name Order
|
|
142
|
+
|
|
143
|
+
# Skip clipboard copy
|
|
144
|
+
surety-scaffold '{"x": 1}' --no-clipboard
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The result is printed to stdout and automatically copied to the clipboard (`pbcopy` on macOS, `xclip` on Linux).
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
usage: surety-scaffold [-h] [--class-name CLASS_NAME] [--no-clipboard] [json]
|
|
151
|
+
|
|
152
|
+
positional arguments:
|
|
153
|
+
json JSON string to extract from. Reads from stdin if omitted.
|
|
154
|
+
|
|
155
|
+
options:
|
|
156
|
+
--class-name, -c Name for the top-level generated class (default: Schema).
|
|
157
|
+
--no-clipboard Do not copy the result to the clipboard.
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Roadmap
|
|
163
|
+
|
|
164
|
+
The following features are planned for this library. They complement the core surety framework with static analysis, code generation, and developer tooling.
|
|
165
|
+
|
|
166
|
+
### In scope for surety-scaffold
|
|
167
|
+
|
|
168
|
+
| # | Feature | Status |
|
|
169
|
+
|---|---------|--------|
|
|
170
|
+
| 1 | **Extract contract from JSON** — infer surety schemas from raw API responses | done |
|
|
171
|
+
| 4 | **Parse JSON Schema / OpenAPI** — generate surety `Dictionary` classes from JSON Schema or OpenAPI 3.x specs, resolving `$ref` and mapping constraints | planned |
|
|
172
|
+
| 5 | **Generate callers** — produce `ApiContract` boilerplate and caller function stubs from OpenAPI operations | planned |
|
|
173
|
+
| 12 | **Generate test scenarios (basic)** — scaffold positive pytest test cases (required fields, full fields, `with_values` overrides) for a given contract | planned |
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# surety-scaffold
|
|
2
|
+
|
|
3
|
+
Code generation toolkit for the [surety](https://github.com/elenakulgavaya/surety) contract-testing framework.
|
|
4
|
+
|
|
5
|
+
Bootstraps surety schemas, contracts, callers, and test scaffolding from existing JSON payloads, JSON Schema, and OpenAPI specs — so you can start contract-based testing without writing boilerplate by hand.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install surety-scaffold
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires `surety>=0.0.4`.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
### Extract contract from JSON
|
|
22
|
+
|
|
23
|
+
Turn a raw JSON payload into surety `Dictionary` class definitions.
|
|
24
|
+
|
|
25
|
+
**Programmatic:**
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import json
|
|
29
|
+
from surety.scaffold import extract_from_json
|
|
30
|
+
|
|
31
|
+
payload = json.dumps({
|
|
32
|
+
"order_id": 42,
|
|
33
|
+
"status": "pending",
|
|
34
|
+
"total": 199.99,
|
|
35
|
+
"is_express": False,
|
|
36
|
+
"customer": {
|
|
37
|
+
"customer_id": 7,
|
|
38
|
+
"email": "jane@example.com"
|
|
39
|
+
},
|
|
40
|
+
"items": [
|
|
41
|
+
{"sku": "ABC-1", "qty": 2}
|
|
42
|
+
]
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
print(extract_from_json(payload, class_name="Order"))
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Output:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from surety import Array, Bool, Dictionary, Float, Int, String
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Customer(Dictionary):
|
|
55
|
+
CustomerId = Int(name='customer_id', required=True)
|
|
56
|
+
Email = String(name='email', required=True)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class Items(Dictionary):
|
|
60
|
+
Sku = String(name='sku', required=True)
|
|
61
|
+
Qty = Int(name='qty', required=True)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Order(Dictionary):
|
|
65
|
+
OrderId = Int(name='order_id', required=True)
|
|
66
|
+
Status = String(name='status', required=True)
|
|
67
|
+
Total = Float(name='total', required=True)
|
|
68
|
+
IsExpress = Bool(name='is_express', required=True)
|
|
69
|
+
Customer = Customer(name='customer', required=True)
|
|
70
|
+
Items = Array(Items, name='items', required=True)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Type inference rules:**
|
|
74
|
+
|
|
75
|
+
| JSON value | Surety type |
|
|
76
|
+
|------------|-------------|
|
|
77
|
+
| `true` / `false` | `Bool` |
|
|
78
|
+
| integer | `Int` |
|
|
79
|
+
| float | `Float` |
|
|
80
|
+
| UUID string | `Uuid` |
|
|
81
|
+
| ISO 8601 datetime or date string | `DateTime` |
|
|
82
|
+
| any other string | `String` |
|
|
83
|
+
| object `{}` | nested `Dictionary` subclass |
|
|
84
|
+
| array of objects | `Array(NestedClass, ...)` |
|
|
85
|
+
| array of primitives | `Array(PrimitiveType, ...)` |
|
|
86
|
+
| `null` | `String(allow_none=True)` |
|
|
87
|
+
|
|
88
|
+
Nested objects produce their own `Dictionary` subclass and are always emitted before the class that references them. Arrays of objects merge all items across the array to capture the full set of fields. Duplicate class names (same key appearing at different nesting levels) are disambiguated automatically with a numeric suffix.
|
|
89
|
+
|
|
90
|
+
**Key naming:**
|
|
91
|
+
JSON keys are converted to `PascalCase` for both the class attribute name and the generated class name. `snake_case`, `camelCase`, and `kebab-case` are all handled.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
**CLI:**
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Pass JSON as an argument
|
|
99
|
+
surety-scaffold '{"order_id": 1, "status": "pending"}' --class-name Order
|
|
100
|
+
|
|
101
|
+
# Pipe from a file or command
|
|
102
|
+
cat response.json | surety-scaffold --class-name Order
|
|
103
|
+
|
|
104
|
+
# Skip clipboard copy
|
|
105
|
+
surety-scaffold '{"x": 1}' --no-clipboard
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The result is printed to stdout and automatically copied to the clipboard (`pbcopy` on macOS, `xclip` on Linux).
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
usage: surety-scaffold [-h] [--class-name CLASS_NAME] [--no-clipboard] [json]
|
|
112
|
+
|
|
113
|
+
positional arguments:
|
|
114
|
+
json JSON string to extract from. Reads from stdin if omitted.
|
|
115
|
+
|
|
116
|
+
options:
|
|
117
|
+
--class-name, -c Name for the top-level generated class (default: Schema).
|
|
118
|
+
--no-clipboard Do not copy the result to the clipboard.
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Roadmap
|
|
124
|
+
|
|
125
|
+
The following features are planned for this library. They complement the core surety framework with static analysis, code generation, and developer tooling.
|
|
126
|
+
|
|
127
|
+
### In scope for surety-scaffold
|
|
128
|
+
|
|
129
|
+
| # | Feature | Status |
|
|
130
|
+
|---|---------|--------|
|
|
131
|
+
| 1 | **Extract contract from JSON** — infer surety schemas from raw API responses | done |
|
|
132
|
+
| 4 | **Parse JSON Schema / OpenAPI** — generate surety `Dictionary` classes from JSON Schema or OpenAPI 3.x specs, resolving `$ref` and mapping constraints | planned |
|
|
133
|
+
| 5 | **Generate callers** — produce `ApiContract` boilerplate and caller function stubs from OpenAPI operations | planned |
|
|
134
|
+
| 12 | **Generate test scenarios (basic)** — scaffold positive pytest test cases (required fields, full fields, `with_values` overrides) for a given contract | planned |
|