This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
forked from Redocly/openapi-sampler
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(samplers): strengthen the checks of keywords (#6)
- Loading branch information
Showing
18 changed files
with
249 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ test | |
|
||
commitlint.config.js | ||
release.config.js | ||
.idea |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@neuralegion/openapi-sampler", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"private": false, | ||
"description": "Tool for generation samples based on OpenAPI payload/response schema", | ||
"main": "dist/openapi-sampler.js", | ||
|
@@ -20,14 +20,20 @@ | |
"type": "git", | ||
"url": "git+https://github.com/Neuralegion/openapi-sampler.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"keywords": [ | ||
"OpenAPI", | ||
"Swagger", | ||
"instantiator", | ||
"sampler", | ||
"faker" | ||
], | ||
"author": "Mirsad Halilcevic <[email protected]>", | ||
"contributors": [ | ||
"Mirsad Halilcevic <[email protected]>", | ||
"Artem Derevnjuk <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Neuralegion/openapi-sampler/issues" | ||
|
@@ -40,6 +46,7 @@ | |
"@babel/register": "^7.4.4", | ||
"@commitlint/cli": "^8.2.0", | ||
"@commitlint/config-conventional": "^8.2.0", | ||
"@semantic-release/git": "^7.0.17", | ||
"babel-eslint": "^10.0.3", | ||
"babel-loader": "^8.0.6", | ||
"babel-plugin-istanbul": "^5.1.4", | ||
|
@@ -98,7 +105,7 @@ | |
} | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"src/**/*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
'use strict'; | ||
|
||
import { traverse } from './traverse'; | ||
import { mergeDeep } from './utils'; | ||
|
||
export function allOfSample(into, children, options, spec) { | ||
let res = traverse(into, options, spec); | ||
const res = traverse(into, options, spec); | ||
|
||
const subSamples = []; | ||
|
||
for (let subSchema of children) { | ||
const { type, readOnly, writeOnly, value } = traverse({ type, ...subSchema }, options, spec); | ||
|
||
if (res.type && type && type !== res.type) { | ||
throw new Error('allOf: schemas with different types can\'t be merged'); | ||
} | ||
|
||
res.type = res.type || type; | ||
res.readOnly = res.readOnly || readOnly; | ||
res.writeOnly = res.writeOnly || writeOnly; | ||
if (value != null) subSamples.push(value); | ||
|
||
if (value != null) { | ||
subSamples.push(value); | ||
} | ||
} | ||
|
||
if (res.type === 'object') { | ||
res.value = mergeDeep(res.value || {}, ...subSamples); | ||
return res; | ||
} else { | ||
if (res.type === 'array') { | ||
// TODO: implement arrays | ||
if (!options.quiet) console.warn('OpenAPI Sampler: found allOf with "array" type. Result may be incorrect'); | ||
// TODO: implement arrays | ||
if (res.type === 'array' && !options.quiet) { | ||
console.warn('OpenAPI Sampler: found allOf with "array" type. Result may be incorrect'); | ||
} | ||
|
||
const lastSample = subSamples[subSamples.length - 1]; | ||
res.value = lastSample != null ? lastSample : res.value; | ||
return res; | ||
} | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.