serve original openapi json
This commit is contained in:
parent
238821aed8
commit
b0b286a5e7
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
output/
|
output/
|
||||||
__pycache__
|
__pycache__
|
||||||
regular.cs
|
regular.cs
|
||||||
|
OpenAPIDocCtrl.cs
|
||||||
|
3
ENV
3
ENV
@ -1,6 +1,9 @@
|
|||||||
PACKAGE_NAME=de.hottis.genericdatabaseapiservice
|
PACKAGE_NAME=de.hottis.genericdatabaseapiservice
|
||||||
export PACKAGE_NAME
|
export PACKAGE_NAME
|
||||||
|
|
||||||
|
ROUTE_PREFIX="pdb/v2/api"
|
||||||
|
export ROUTE_PREFIX
|
||||||
|
|
||||||
Database__User=apiservicetestdb
|
Database__User=apiservicetestdb
|
||||||
Database__Host=172.16.10.18
|
Database__Host=172.16.10.18
|
||||||
# Database__Password=xxx
|
# Database__Password=xxx
|
||||||
|
24
OpenAPIDocCtrl.cs.tmpl
Normal file
24
OpenAPIDocCtrl.cs.tmpl
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace de.hottis.genericdatabaseapiservice.Controllers {
|
||||||
|
[Route("/${env['routeprefix']}/openapi/JSON")]
|
||||||
|
public class OpenAPIDocCtrl : ControllerBase {
|
||||||
|
private IWebHostEnvironment _hostingEnvironment;
|
||||||
|
|
||||||
|
public OpenAPIDocCtrl(IWebHostEnvironment environment) {
|
||||||
|
_hostingEnvironment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> Index() {
|
||||||
|
return Content(
|
||||||
|
await System.IO.File.ReadAllTextAsync(Path.Combine(_hostingEnvironment.WebRootPath, "openapi-original.json")),
|
||||||
|
"text/plain"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -56,8 +56,11 @@ apiDefinition["GENERATED_CS_COMMENT"] = """
|
|||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
"""
|
"""
|
||||||
|
|
||||||
packageName = os.environ["PACKAGE_NAME"]
|
os.environ["PACKAGE_NAME"]
|
||||||
apiDefinition["env"] = { "packagename": packageName }
|
apiDefinition["env"] = {
|
||||||
|
"packagename": os.environ["PACKAGE_NAME"],
|
||||||
|
"routeprefix": os.environ["ROUTE_PREFIX"]
|
||||||
|
}
|
||||||
statementFinder = re.compile('STATEMENTBEGIN (.*) STATEMENTEND')
|
statementFinder = re.compile('STATEMENTBEGIN (.*) STATEMENTEND')
|
||||||
statementChecker = {
|
statementChecker = {
|
||||||
'get': re.compile('^select', re.IGNORECASE),
|
'get': re.compile('^select', re.IGNORECASE),
|
||||||
|
@ -85,7 +85,9 @@ if [ "$STAGE2" = "1" ]; then
|
|||||||
echo "patch DbService registering into generated startup code"
|
echo "patch DbService registering into generated startup code"
|
||||||
sed -i output/src/$PACKAGE_NAME/Startup.cs \
|
sed -i output/src/$PACKAGE_NAME/Startup.cs \
|
||||||
-e 's#\(using '$PACKAGE_NAME'.OpenApi;\)#\1\n\n// added by post-processor\nusing '$PACKAGE_NAME'.Services;\n#' \
|
-e 's#\(using '$PACKAGE_NAME'.OpenApi;\)#\1\n\n// added by post-processor\nusing '$PACKAGE_NAME'.Services;\n#' \
|
||||||
-e 's#^\([[:space:]]*\)\(// Add framework services.\)#\1// added by post-processor\n\1services.AddTransient<IDbService, DbService>();\n\n\1\2#'
|
-e 's#^\([[:space:]]*\)\(// Add framework services.\)#\1// added by post-processor\n\1services.AddTransient<IDbService, DbService>();\n\n\1\2#' \
|
||||||
|
-e 's#\(c.RoutePrefix = "\)openapi\(";\)#\1'$ROUTE_PREFIX'/doc\2#' \
|
||||||
|
-e 's#\(app.UseHttpsRedirection();\)#// \1#'
|
||||||
|
|
||||||
echo "disable documentation warnings in generated code"
|
echo "disable documentation warnings in generated code"
|
||||||
sed -i output/src/$PACKAGE_NAME/$PACKAGE_NAME.csproj \
|
sed -i output/src/$PACKAGE_NAME/$PACKAGE_NAME.csproj \
|
||||||
@ -101,6 +103,7 @@ if [ "$STAGE2" = "1" ]; then
|
|||||||
if [ -f regular.cs ]; then
|
if [ -f regular.cs ]; then
|
||||||
echo "copy endpoint code into source code tree"
|
echo "copy endpoint code into source code tree"
|
||||||
cp regular.cs output/src/$PACKAGE_NAME/Implementations
|
cp regular.cs output/src/$PACKAGE_NAME/Implementations
|
||||||
|
cp OpenAPIDocCtrl.cs output/src/$PACKAGE_NAME/Controllers
|
||||||
else
|
else
|
||||||
echo "implementation not available, forgot to run stage 1?"
|
echo "implementation not available, forgot to run stage 1?"
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user