@team-supercharge/oasg 4.5.0 → 4.6.0
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.
- package/CHANGELOG.md +14 -0
- package/README.md +29 -0
- package/package.json +1 -1
- package/rules/default.yaml +1 -0
- package/rules/functions/schema-enumeration.js +39 -0
- package/targets/feign/generator-config.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [4.6.0](https://gitlab.com/team-supercharge/oasg/compare/v4.5.1...v4.6.0) (2022-09-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add schema-enumeration custom linter function ([bd5cd09](https://gitlab.com/team-supercharge/oasg/commit/bd5cd090b7e3c5c85d19c13ee8f4d9f56ba6290c))
|
|
11
|
+
|
|
12
|
+
### [4.5.1](https://gitlab.com/team-supercharge/oasg/compare/v4.5.0...v4.5.1) (2022-09-14)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **feign:** fix Date type to LocalDate type import ([3d9e7d7](https://gitlab.com/team-supercharge/oasg/commit/3d9e7d71e2df13275c3544afce9e9c384e5ecb29))
|
|
18
|
+
|
|
5
19
|
## [4.5.0](https://gitlab.com/team-supercharge/oasg/compare/v4.4.0...v4.5.0) (2022-06-13)
|
|
6
20
|
|
|
7
21
|
|
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ Design APIs in OpenAPI 3.0 format, lint them, and generate client/server package
|
|
|
15
15
|
* [Publish](#publish)
|
|
16
16
|
* [Linter rules](#linter-rules)
|
|
17
17
|
* [Custom rules](#custom-rules)
|
|
18
|
+
* [Custom functions](#custom-functions)
|
|
18
19
|
* [Configuration](#configuration)
|
|
19
20
|
* [Source](#source)
|
|
20
21
|
* [Simple](#simple)
|
|
@@ -209,6 +210,34 @@ The following rules are defined in the custom _OASg Ruleset_.
|
|
|
209
210
|
| property casing | `oasg-property-casing-camel` | Y | enforces `camelCasing` for property names |
|
|
210
211
|
| property casing | `oasg-property-casing-pascal` | | enforces `PascalCasing` for property names |
|
|
211
212
|
|
|
213
|
+
### Custom functions
|
|
214
|
+
|
|
215
|
+
#### `schema-enumeration`
|
|
216
|
+
|
|
217
|
+
The function enables to verify a value against a set of enumeration values defined in a schema.
|
|
218
|
+
|
|
219
|
+
Function parameters:
|
|
220
|
+
* `schema` - Name of the schema to be validated against, must contain `enum` definition
|
|
221
|
+
* `file` - (optional) YAML file with `components.schemas` defined, otherwise the currently linted documenet is used
|
|
222
|
+
|
|
223
|
+
Example usage in a custom project ruleset:
|
|
224
|
+
|
|
225
|
+
```yaml
|
|
226
|
+
project-valid-permissions:
|
|
227
|
+
recommended: true
|
|
228
|
+
type: style
|
|
229
|
+
severity: error
|
|
230
|
+
description: Property x-permissions should use values from the Permission enum
|
|
231
|
+
message: '{{error}}'
|
|
232
|
+
given:
|
|
233
|
+
- $.paths.*.*.x-permissions[*]
|
|
234
|
+
then:
|
|
235
|
+
function: schema-enumeration
|
|
236
|
+
functionOptions:
|
|
237
|
+
file: ./api/common.yaml
|
|
238
|
+
schema: Permission
|
|
239
|
+
```
|
|
240
|
+
|
|
212
241
|
---
|
|
213
242
|
|
|
214
243
|
## Configuration
|
package/package.json
CHANGED
package/rules/default.yaml
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const yaml = require('js-yaml');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
const CACHE_KEY = 'values';
|
|
5
|
+
|
|
6
|
+
module.exports = function (targetVal, opts, _paths, otherValues) {
|
|
7
|
+
if (!this.cache.has(CACHE_KEY)) {
|
|
8
|
+
if (opts.file) {
|
|
9
|
+
// load document from file if needed
|
|
10
|
+
try {
|
|
11
|
+
document = yaml.load(fs.readFileSync(opts.file, 'utf8'));
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
throw Error(`file ${opts.file} not found`);
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
// otherwise get the current resolved document
|
|
18
|
+
document = otherValues.documentInventory.resolved;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!(document && document.components && document.components.schemas && document.components.schemas[opts.schema])) {
|
|
22
|
+
throw Error(`schema ${opts.schema} not found`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!document.components.schemas[opts.schema].enum) {
|
|
26
|
+
throw Error(`schema ${opts.schema} must be an enumeration`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.cache.set(CACHE_KEY, document.components.schemas[opts.schema].enum);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const values = this.cache.get(CACHE_KEY);
|
|
33
|
+
|
|
34
|
+
if (!values.includes(targetVal)) {
|
|
35
|
+
return [ { message: `\`${targetVal}\` should be a valid entry from the ${opts.schema} enum` } ];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return;
|
|
39
|
+
};
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
"generateForOpenFeign": true,
|
|
8
8
|
"removeEnumValuePrefix": false,
|
|
9
9
|
"typeMappings": {
|
|
10
|
-
"OffsetDateTime": "Instant"
|
|
10
|
+
"OffsetDateTime": "java.time.Instant",
|
|
11
|
+
"Date": "java.time.LocalDate"
|
|
11
12
|
},
|
|
12
13
|
"importMappings": {
|
|
13
|
-
"java.time.OffsetDateTime": "java.time.Instant"
|
|
14
|
+
"java.time.OffsetDateTime": "java.time.Instant",
|
|
15
|
+
"java.util.Date": "java.time.LocalDate"
|
|
14
16
|
}
|
|
15
17
|
}
|