Skip to content

Commit

Permalink
Core.ComputedDefaultValue (#266)
Browse files Browse the repository at this point in the history
* 0.24.0
* ComputedDefaultValue
* refactor tests
* Update Annotations.md
  • Loading branch information
ralfhandl authored Nov 7, 2023
1 parent 8c7e7db commit d6c9449
Show file tree
Hide file tree
Showing 8 changed files with 1,632 additions and 1,500 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.24.0] - 2023-11-07

### Added

- Core.ComputedDefaultValue means property is not required on create

## [0.23.4] - 2023-08-16

### Fixed
Expand Down
1 change: 1 addition & 0 deletions doc/Annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ See [Frequently Asked Questions](FAQ.md) for examples on how to use these annota
Term | Annotation Target | OpenAPI field
-----|-------------------|--------------
`Computed` | Property | omit from Create and Update structures
`ComputedDefaultValue` | Property | omit from required properties if key
`DefaultNamespace` | Schema | path templates for actions and functions without namespace prefix
`Description` | Action, ActionImport, Function, FunctionImport | `summary` of Operation Object
`Description` | EntitySet, Singleton | `description` of Tag Object
Expand Down
31 changes: 17 additions & 14 deletions lib/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2162,10 +2162,7 @@ module.exports.csdl2openapi = function (
] = ref("count");
}
}
if (
property[voc.Core.Permissions] != "Read" &&
!property[voc.Core.Computed]
) {
if (property[voc.Core.Permissions] != "Read") {
if (property.$ContainsTarget) {
if (suffix === SUFFIX.create)
schemaProperties[name] = schema(property, SUFFIX.create);
Expand All @@ -2186,20 +2183,26 @@ module.exports.csdl2openapi = function (
} else {
if (
property[voc.Core.Permissions] == "Read" ||
property[voc.Core.Computed]
property[voc.Core.Computed] ||
property[voc.Core.ComputedDefaultValue]
) {
let index = required.indexOf(name);
if (index != -1) required.splice(index, 1);
} else {
if (suffix === SUFFIX.create)
schemaProperties[name] = schema(property, SUFFIX.create);
if (
suffix === SUFFIX.update &&
!isKey[name] &&
!property[voc.Core.Immutable]
)
schemaProperties[name] = schema(property, SUFFIX.update);
}
if (
property[voc.Core.Permissions] == "Read" ||
property[voc.Core.Computed]
)
continue;

if (suffix === SUFFIX.create)
schemaProperties[name] = schema(property, SUFFIX.create);
if (
suffix === SUFFIX.update &&
!isKey[name] &&
!property[voc.Core.Immutable]
)
schemaProperties[name] = schema(property, SUFFIX.update);
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/edm.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function vocabularies(voc, alias) {
Core: [
"AcceptableMediaTypes",
"Computed",
"ComputedDefaultValue",
"DefaultNamespace",
"Description",
"Example",
Expand Down
10 changes: 8 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "odata-openapi",
"version": "0.23.4",
"version": "0.24.0",
"description": "Convert OData CSDL XML or CSDL JSON to OpenAPI",
"homepage": "https://github.com/oasis-tcs/odata-openapi/blob/master/lib/README.md",
"bugs": "https://github.com/oasis-tcs/odata-openapi/issues",
Expand Down
Loading

0 comments on commit d6c9449

Please sign in to comment.