Compare commits

..

7 Commits

Author SHA1 Message Date
Lothar Bender
9a6f4b71b3 adopt latest custom build task changes
- single BuildTaskHandler instead of BuildTaskProvider/BuildTaskHandler
  approach
- static build task handler config moved to meta
- default build task properties are now returned as name/value pairs
  using property config
- runWith to declare dependencies across build task handlers, ensuring
  correct dependency graph
- optional getTasks method to implement build task specific constraints
2021-12-09 13:04:08 +01:00
Lothar Bender
c796bda9ad Merge branch 'main' into add/customBuildTask 2021-12-06 10:10:14 +01:00
Lothar Bender
8852c91406 rename applyTaskDefaults 2021-11-24 18:30:30 +01:00
Lothar Bender
a7ab8b3bda optional plugin.activate() method 2021-11-24 17:59:43 +01:00
Lothar Bender
b2b4907b4a Merge branch 'main' into add/customBuildTask 2021-11-24 11:51:03 +01:00
Lothar Bender
69126b94af lookupTasks becomes optional
- change output dir
2021-11-24 11:47:52 +01:00
Lothar Bender
8b0f6010a5 add custom build task contribution sample 2021-11-23 23:11:32 +01:00
8 changed files with 1828 additions and 1626 deletions

View File

@@ -8,6 +8,9 @@
"express": "^4.17.1", "express": "^4.17.1",
"passport": "0.4.1" "passport": "0.4.1"
}, },
"devDependencies": {
"@cds/cds-plugin-openapi": "*"
},
"scripts": { "scripts": {
"genres": "cds serve test/genres.cds", "genres": "cds serve test/genres.cds",
"start": "cds run", "start": "cds run",
@@ -18,9 +21,6 @@
"db": { "db": {
"kind": "sql" "kind": "sql"
} }
},
"features": {
"assert_integrity": "db"
} }
} }
} }

View File

@@ -17,7 +17,7 @@ GET {{server}}/browse/$metadata
### ------------------------------------------------------------------------ ### ------------------------------------------------------------------------
# Browse Books as any user # Browse Books as any user
GET {{server}}/browse/Books? GET {{server}}/browse/Books?
&$select=title,stock,author # &$select=title,stock
# &$expand=currency # &$expand=currency
# &sap-language=de # &sap-language=de
{{me}} {{me}}
@@ -62,22 +62,6 @@ Authorization: Basic alice:
"currency": { "code": "USD" } "currency": { "code": "USD" }
} }
### ------------------------------------------------------------------------
# Create book with invalid author ID -> will fail
POST {{server}}/admin/Books
Content-Type: application/json;IEEE754Compatible=true
Authorization: Basic alice:
{
"ID": 34,
"title": "Let constraints do the magic",
"descr": "Database constraints are helpful little things that prevent messing up your data.",
"author": { "ID": 777 },
"genre": { "ID": 14 },
"stock": 4,
"price": "19.99",
"currency": { "code": "USD" }
}
### ------------------------------------------------------------------------ ### ------------------------------------------------------------------------
# Put image to books # Put image to books

View File

@@ -0,0 +1,29 @@
/* eslint-disable require-await */
const cds = require('@sap/cds'), { BuildTaskHandler } = cds.build
const cdsdk = require('@sap/cds-dk')
cds.build.register(class OpenApiHandler extends BuildTaskHandler {
static get meta() {
return {
id: 'openapi',
runWith: ['node-cf', 'java-cf'],
config: { src: cds.env.folders.srv.replace(/\/$/, '') }
}
}
async clean() {
return this.remove('openapi-docs')
}
async build() {
const model = await this.model()
const { options } = this.task
// generate openapi files for all services
await Promise.all(cds.linked(model).services.map(service => {
const openApi = cdsdk.compile.to.openapi(model, {
service: service.name,
'openapi:diagram': String(options.diagram) === 'true'
})
this.write(openApi).to(`openapi-docs/${service.name}.openapi3.json`)
}))
}
})

View File

@@ -0,0 +1,9 @@
{
"name": "@sap/cds-plugin-openapi",
"version": "1.0.0",
"description": "OpenAPI service specification build plugin",
"main": "index.js",
"dependencies": {
"@sap/cds-dk": "^4"
}
}

View File

@@ -4,10 +4,5 @@
"dependencies": { "dependencies": {
"@capire/common": "*", "@capire/common": "*",
"@sap/cds": "^5" "@sap/cds": "^5"
},
"cds": {
"features": {
"assert_integrity": "db"
}
} }
} }

3374
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -13,13 +13,14 @@
"@capire/media": "./media", "@capire/media": "./media",
"@capire/orders": "./orders", "@capire/orders": "./orders",
"@capire/reviews": "./reviews", "@capire/reviews": "./reviews",
"@sap/cds": "^5.7.3" "@sap/cds": "git+https://github.tools.sap/cap/cds#add/customBuildTaskProviders"
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.3.4", "chai": "^4.3.4",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0", "chai-subset": "^1.6.0",
"sqlite3": "^5" "sqlite3": "^5",
"@cds/cds-plugin-openapi": "./cds-plugin-openapi"
}, },
"scripts": { "scripts": {
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules", "cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
@@ -30,7 +31,6 @@
"media": "cds watch media", "media": "cds watch media",
"mocha": "npx mocha || echo", "mocha": "npx mocha || echo",
"jest": "npx jest", "jest": "npx jest",
"start": "cds watch fiori",
"test": "npm run jest -- --silent", "test": "npm run jest -- --silent",
"test:hello": "cd hello && npm test" "test:hello": "cd hello && npm test"
}, },

View File

@@ -18,9 +18,6 @@
"[production]": { "kind": "enterprise-messaging" } "[production]": { "kind": "enterprise-messaging" }
}, },
"db": { "kind": "sql" } "db": { "kind": "sql" }
},
"features": {
"assert_integrity": "db"
} }
} }
} }