Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
cubes
api
Commits
d1d8ceafcf23
Commit
d1d8ceafcf23
authored
2 years ago
by
Arnaud Vergnet
Browse files
Options
Downloads
Patches
Plain Diff
fix: write openapi.yaml to cubicweb config dir
parent
b974ab06d0c1
No related branches found
No related tags found
1 merge request
!16
fix: write openapi.yaml to cubicweb config dir
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cubicweb_api/openapi/openapi.py
+12
-7
12 additions, 7 deletions
cubicweb_api/openapi/openapi.py
with
12 additions
and
7 deletions
cubicweb_api/openapi/openapi.py
+
12
−
7
View file @
d1d8ceaf
...
...
@@ -17,6 +17,7 @@
from
cubicweb_api.constants
import
API_ROUTE_NAME_PREFIX
from
cubicweb_api.httperrors
import
get_http_error
,
get_http_500_error
from
cubicweb_api.util
import
get_cw_repo
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -28,7 +29,7 @@
production
=
"
openapi.yaml
"
def
get_
file_in_folder
(
filename
:
str
)
->
str
:
return
path
.
join
(
path
.
dirname
(
__file__
),
filenam
e
)
def
get_
template_file_path
(
)
->
str
:
return
path
.
join
(
path
.
dirname
(
__file__
),
OpenApiFiles
.
templat
e
)
...
...
@@ -33,7 +34,11 @@
def
generate_openapi_file
(
path_prefix
:
str
):
spec_dict
:
Dict
=
read_yaml_file
(
get_file_in_folder
(
OpenApiFiles
.
template
))
def
get_production_file_path
(
config
:
Configurator
)
->
str
:
return
path
.
join
(
get_cw_repo
(
config
).
config
.
apphome
,
OpenApiFiles
.
production
)
def
generate_openapi_file
(
config
:
Configurator
,
path_prefix
:
str
):
spec_dict
:
Dict
=
read_yaml_file
(
get_template_file_path
())
paths_dict
:
Optional
[
Dict
[
str
,
Dict
]]
=
spec_dict
.
get
(
"
paths
"
)
edited_path_dict
=
{}
if
paths_dict
is
None
:
...
...
@@ -44,9 +49,9 @@
]
=
f
"
{
API_ROUTE_NAME_PREFIX
}{
path_item
[
OPENAPI_PYRAMID_KEY
]
}
"
edited_path_dict
[
f
"
{
path_prefix
}{
path_str
}
"
]
=
path_item
spec_dict
[
"
paths
"
]
=
edited_path_dict
with
open
(
get_
file_in_folder
(
OpenApiFiles
.
production
),
"
w
"
)
as
file
:
with
open
(
get_
production_file_path
(
config
),
"
w
"
)
as
file
:
dump
(
spec_dict
,
file
)
def
register_openapi_routes
(
config
:
Configurator
,
path_prefix
:
str
):
config
.
include
(
"
pyramid_openapi3
"
)
...
...
@@ -48,8 +53,8 @@
dump
(
spec_dict
,
file
)
def
register_openapi_routes
(
config
:
Configurator
,
path_prefix
:
str
):
config
.
include
(
"
pyramid_openapi3
"
)
generate_openapi_file
(
path_prefix
)
generate_openapi_file
(
config
,
path_prefix
)
# TODO block access if anonymous access is disabled and user is not connected
config
.
pyramid_openapi3_spec
(
...
...
@@ -54,6 +59,6 @@
# TODO block access if anonymous access is disabled and user is not connected
config
.
pyramid_openapi3_spec
(
f
"
{
path
.
dirname
(
__file__
)
}
/openapi.yaml
"
,
get_production_file_path
(
config
)
,
route
=
f
"
{
path_prefix
}
/openapi.yaml
"
,
)
config
.
pyramid_openapi3_add_explorer
(
route
=
f
"
{
path_prefix
}
/openapi
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment