Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4cbf93e
HCK-3034: update swagger-parser validator
taras-dubyk Feb 8, 2023
69c1425
add 3.1 version option
taras-dubyk Feb 8, 2023
010af1c
add json schema spec config
taras-dubyk Feb 17, 2023
bed37da
add json schema dialect property
taras-dubyk Feb 17, 2023
4f16317
HCK-3105: add null type
taras-dubyk Feb 23, 2023
2576f05
adapt JSON Schema based on targetDBVersion
taras-dubyk Feb 23, 2023
6caa765
HCK: 3106: enable multiple types for 3.1.0
taras-dubyk Feb 23, 2023
dff23a5
add json schema 2020-12 props
taras-dubyk Feb 23, 2023
d1da63d
use specVersion
taras-dubyk Feb 24, 2023
2ceab45
Merge remote-tracking branch 'origin/master' into feature/v3.1
taras-dubyk Feb 24, 2023
bd4f859
enable multiple complex types
taras-dubyk Mar 2, 2023
df68873
use target spec version
taras-dubyk Mar 3, 2023
833cff5
use spec version for remaining components
taras-dubyk Mar 6, 2023
cea0f90
enable summary prop for example component
taras-dubyk Mar 6, 2023
028003e
remove number default data props
taras-dubyk Mar 15, 2023
19086db
update complex types FE for v3.1
taras-dubyk Mar 15, 2023
2f88a37
handle primitive types
taras-dubyk Mar 15, 2023
6298ddd
fix getting array items from 2020-12 schema
taras-dubyk Mar 15, 2023
8ca0305
fix parameters mapping
taras-dubyk Mar 15, 2023
f8ec244
remove integer default data props
taras-dubyk Mar 16, 2023
172a338
enable v3.1.x schema RE
taras-dubyk Mar 16, 2023
a5ed9d4
add handling webhooks
taras-dubyk Mar 23, 2023
8f6b6dc
add license identifier
taras-dubyk Mar 24, 2023
ca669b3
add mutualTLS security schema option
taras-dubyk Mar 27, 2023
760d6eb
fix handling ref description and summary
taras-dubyk Mar 27, 2023
99cf182
add summary property for API info
taras-dubyk Mar 27, 2023
247a408
remove schema dialect redundant prop
taras-dubyk Mar 29, 2023
02337b9
fix specVersion argument
taras-dubyk Mar 29, 2023
4d1571f
return nullable for boolean
taras-dubyk Mar 29, 2023
ddb7acb
fix missed props
taras-dubyk Mar 30, 2023
76a560f
bump min app version
taras-dubyk Mar 30, 2023
03cdd9d
tolerate missed paths object
taras-dubyk Apr 4, 2023
3d9a0d2
remove nullable prop for null type
taras-dubyk Apr 4, 2023
030da5d
add jsonSchemaDialect handling
taras-dubyk Apr 7, 2023
0d9b83e
mark example property as deprecated
taras-dubyk Apr 7, 2023
7e93b44
use textarea for license identifier
taras-dubyk Apr 4, 2023
72c3215
make license identifier and url mutually exclusive
taras-dubyk Apr 6, 2023
4587076
fix license prop dependency
taras-dubyk Apr 11, 2023
d8510fb
handle v3.1.0 while detecting openapi schema file
taras-dubyk Apr 13, 2023
5c83d41
increase minimum app version
taras-dubyk Apr 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 23 additions & 4 deletions forward_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ module.exports = {
generateModelScript(data, logger, cb) {
try {
const {
dbVersion,
dbVersion: specVersion,
externalDocs: modelExternalDocs,
tags: modelTags,
security: modelSecurity,
servers: modelServers,
jsonSchemaDialect,
} = data.modelData[0];

const containersIdsFromCallbacks = commonHelper.getContainersIdsForCallbacks(data);
Expand All @@ -32,19 +33,23 @@ module.exports = {
const servers = getServers(modelServers);
const externalDefinitions = JSON.parse(data.externalDefinitions || '{}').properties || {};
const containers = handleRefInContainers(data.containers, externalDefinitions, resolveApiExternalRefs);
const paths = getPaths(containers, containersIdsFromCallbacks);
const { pathContainers, webhookContainers } = separatePathAndWebhooks(containers);
const paths = getPaths(pathContainers, containersIdsFromCallbacks, specVersion);
const webhooks = getPaths(webhookContainers, containersIdsFromCallbacks, specVersion);
const definitions = JSON.parse(data.modelDefinitions) || {};
const definitionsWithHandledReferences = mapJsonSchema(definitions, handleRef(externalDefinitions, resolveApiExternalRefs));
const components = getComponents(definitionsWithHandledReferences, data.containers);
const components = getComponents({ definitions: definitionsWithHandledReferences, containers: data.containers, specVersion });
const security = commonHelper.mapSecurity(modelSecurity);
const tags = commonHelper.mapTags(modelTags);
const externalDocs = commonHelper.mapExternalDocs(modelExternalDocs);

const openApiSchema = {
openapi: dbVersion,
openapi: specVersion,
info,
...(jsonSchemaDialect && { jsonSchemaDialect }),
servers,
paths,
...(webhooks && Object.keys(webhooks).length ? { webhooks } : {}),
components,
security,
tags,
Expand Down Expand Up @@ -212,3 +217,17 @@ const handleRef = (externalDefinitions, resolveApiExternalRefs) => field => {

return { ...field, ...ref };
};

const separatePathAndWebhooks = containers => {
const pathContainers = [];
const webhookContainers = [];
containers.forEach(container => {
if (container.containerData?.[0]?.webhook) {
webhookContainers.push(container);
} else {
pathContainers.push(container);
}
});

return { pathContainers, webhookContainers };
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const getExtensions = require('../extensionsHelper');
const { getRef, hasRef } = require('../typeHelper');

function getExamples(data) {
function getExamples(data, specVersion) {
if (!data || !data.properties) {
return;
}
Expand All @@ -10,7 +10,7 @@ function getExamples(data) {
.map(([key, value]) => {
return {
key,
value: mapExample(value)
value: mapExample(value, specVersion)
};
})
.reduce((acc, { key, value }) => {
Expand All @@ -19,12 +19,12 @@ function getExamples(data) {
}, {});
}

function mapExample(data) {
function mapExample(data, specVersion) {
if (!data) {
return;
}
if (hasRef(data)) {
return getRef(data);
return getRef(data, specVersion);
}

const { summary, description, value, externalValue, scopesExtensions } = data;
Expand Down
20 changes: 10 additions & 10 deletions forward_engineering/helpers/componentsHelpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ const renameComponents = (components) => {
}, {});
};

function getComponents(definitions, containers) {
function getComponents({ definitions, containers, specVersion }) {
const componentsData = get(definitions, 'properties', {});

const schemas = renameComponents(getSchemas(componentsData.schemas));
const responses = renameComponents(getResponses(componentsData.responses));
const parameters = renameComponents(getParameters(componentsData.parameters));
const examples = renameComponents(getExamples(componentsData.examples));
const requestBodies = renameComponents(getRequestBodies(componentsData.requestBodies));
const headers = renameComponents(getHeaders(prepareHeadersComponents(componentsData.headers), true));
const securitySchemes = renameComponents(getSecuritySchemes(componentsData.securitySchemes));
const links = renameComponents(getLinks(componentsData.links));
const callbacks = renameComponents(getCallbacks(componentsData.callbacks, containers));
const schemas = renameComponents(getSchemas(componentsData.schemas, specVersion));
const responses = renameComponents(getResponses(componentsData.responses, specVersion));
const parameters = renameComponents(getParameters(componentsData.parameters, specVersion));
const examples = renameComponents(getExamples(componentsData.examples, specVersion));
const requestBodies = renameComponents(getRequestBodies(componentsData.requestBodies, specVersion));
const headers = renameComponents(getHeaders({ data: prepareHeadersComponents(componentsData.headers), isParentActivated: true, specVersion }));
const securitySchemes = renameComponents(getSecuritySchemes(componentsData.securitySchemes, specVersion));
const links = renameComponents(getLinks(componentsData.links, specVersion));
const callbacks = renameComponents(getCallbacks({ data: componentsData.callbacks, containers, specVersion }));

const extensions = getExtensions(get(componentsData, `['Specification Extensions'].scopesExtensions`));

Expand Down
9 changes: 4 additions & 5 deletions forward_engineering/helpers/componentsHelpers/linksHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { getRef, hasRef } = require('../typeHelper');
const getExtensions = require('../extensionsHelper');
const { mapServer } = require('../serversHelper');

function getLinks(data) {
function getLinks(data, specVersion) {
if (!data || !data.properties) {
return;
}
Expand All @@ -12,7 +12,7 @@ function getLinks(data) {
.map(([key, value]) => {
return {
key,
value: mapLink(value)
value: mapLink(value, specVersion)
};
})
.reduce((acc, { key, value }) => {
Expand All @@ -21,12 +21,12 @@ function getLinks(data) {
}, {});
}

function mapLink(data) {
function mapLink(data, specVersion) {
if (!data) {
return;
}
if (hasRef(data)) {
return getRef(data);
return getRef(data, specVersion);
}

const { operationRef, operationId, description, server, scopesExtensions } = data;
Expand Down Expand Up @@ -71,5 +71,4 @@ function mapParameters(data) {

module.exports = {
getLinks,
mapLink
};
52 changes: 26 additions & 26 deletions forward_engineering/helpers/componentsHelpers/parametersHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ const { getRef, hasRef, hasChoice } = require('../typeHelper');
const { commentDeactivatedItemInner } = require('../commentsHelper');
const { activateItem } = require('../commonHelper');

function getParameters(data) {
function getParameters(data, specVersion) {
if (!data || !data.properties) {
return;
}

return Object.entries(data.properties)
.map(([key, value]) => {
const required = data.required ? data.required.includes(key) : false;
return { key, value: mapParameter(activateItem(value), required, true) };
return { key, value: mapParameter({ data: activateItem(value), required, isParentActivated: true, specVersion }) };
})
.reduce((acc, { key, value }) => {
acc[key] = value;
return acc;
}, {});
}

function mapParameter(data, required, isParentActivated = false) {
function mapParameter({ data, required, isParentActivated = false, specVersion}) {
if (!data) {
return;
}
if (hasRef(data)) {
return commentDeactivatedItemInner(getRef(data), data.isActivated, isParentActivated);
return commentDeactivatedItemInner(getRef(data, specVersion), data.isActivated, isParentActivated);
}
const schemaKeyword = getSchemaKeyword(data.properties);
const isActivated = data.isActivated && isParentActivated;
Expand All @@ -41,10 +41,10 @@ function mapParameter(data, required, isParentActivated = false) {
style: data.style,
explode: data.explode,
allowReserved: data.allowReserved,
schema: mapSchema(get(data, ['properties', schemaKeyword]), 'schema', isActivated),
schema: mapSchema({ data: get(data, ['properties', schemaKeyword]), key: 'schema', isParentActivated: isActivated, specVersion }),
example: data.sample,
examples: getExamples(get(data, 'properties.examples')),
content: getContent(get(data, 'properties.content'), isActivated)
examples: getExamples(get(data, 'properties.examples'), specVersion),
content: getContent({ data: get(data, 'properties.content'), isParentActivated: isActivated, specVersion })
};
const extensions = getExtensions(data.scopesExtensions);

Expand All @@ -62,7 +62,7 @@ function getIn(parameterType) {
return parameterTypeToIn[parameterType];
}

function getHeaders(data, isParentActivated = false) {
function getHeaders({ data, isParentActivated = false, specVersion }) {
if (!data || !data.properties) {
return;
}
Expand All @@ -72,7 +72,7 @@ function getHeaders(data, isParentActivated = false) {
const isActivated = value.isActivated;
return {
key,
value: mapHeader(value, isActivated && isParentActivated),
value: mapHeader({ data: value, isParentActivated: isActivated && isParentActivated, specVersion }),
isActivated
};
})
Expand All @@ -82,19 +82,19 @@ function getHeaders(data, isParentActivated = false) {
}, {});
}

function mapHeader(data, isParentActivated = false) {
function mapHeader({ data, isParentActivated = false, specVersion }) {
if (!data) {
return;
}
if (hasRef(data)) {
return commentDeactivatedItemInner(getRef(data), data.isActivated, isParentActivated);
return commentDeactivatedItemInner(getRef(data, specVersion), data.isActivated, isParentActivated);
}

delete data.parameterName;
return mapParameter(data, false, isParentActivated);
return mapParameter({ data, required: false, isParentActivated, specVersion });
}

function getContent(data, isParentActivated) {
function getContent({ data, isParentActivated, specVersion }) {
if (!data || !data.properties) {
return;
}
Expand All @@ -117,10 +117,11 @@ function getContent(data, isParentActivated) {
}
const isActivated = data.properties[key].isActivated;
acc[key] = commentDeactivatedItemInner(
mapMediaTypeObject(
data.properties[key],
isActivated && isParentActivated
),
mapMediaTypeObject({
data: data.properties[key],
isParentActivated: isActivated && isParentActivated,
specVersion
}),
isActivated,
isParentActivated
);
Expand All @@ -134,23 +135,23 @@ function getContent(data, isParentActivated) {
return result;
}

function mapMediaTypeObject(data, isParentActivated = false) {
function mapMediaTypeObject({ data, isParentActivated = false, specVersion }) {
if (!data || !data.properties) {
return;
}
const schemaKeyword = getSchemaKeyword(data.properties);
let schema = mapSchema(get(data, ['properties', schemaKeyword]), 'schema', isParentActivated);
let schema = mapSchema({ data: get(data, ['properties', schemaKeyword]), key: 'schema', isParentActivated, specVersion });
if (!schema && hasChoice(data)) {
schema = mapSchema({
schema = mapSchema({ data: {
type: 'object',
allOf: data.allOf,
oneOf: data.oneOf,
anyOf: data.anyOf,
not: data.not
}, 'schema', isParentActivated);
}, key: 'schema', isParentActivated, specVersion });
}
const examples = getExamples(get(data, 'properties.examples'));
const encoding = mapEncoding(get(data, 'properties.encoding'));
const examples = getExamples(get(data, 'properties.examples'), specVersion);
const encoding = mapEncoding({ data: get(data, 'properties.encoding'), specVersion });
let example;
try {
example = JSON.parse(data.sample);
Expand All @@ -163,7 +164,7 @@ function mapMediaTypeObject(data, isParentActivated = false) {
return Object.assign({}, mediaTypeObj, extensions);
}

function mapEncoding(data) {
function mapEncoding({ data, specVersion }) {
if (!data || !data.properties) {
return;
}
Expand All @@ -172,7 +173,7 @@ function mapEncoding(data) {
.map(([key, value]) => {
const encodingObj = {
contentType: value.contentType,
headers: getHeaders(get(value, 'properties.headers')),
headers: getHeaders({ data: get(value, 'properties.headers'), isParentActivated: value.isActivated, specVersion }),
style: value.style,
explode: value.explode || undefined,
allowReserved: value.allowReserved || undefined
Expand Down Expand Up @@ -215,7 +216,6 @@ module.exports = {
getParameters,
mapParameter,
getHeaders,
mapHeader,
getContent,
prepareHeadersComponents
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { getRef, hasRef } = require('../typeHelper');
const { commentDeactivatedItemInner } = require('../commentsHelper');
const { activateItem } = require('../commonHelper');

function getRequestBodies(data) {
function getRequestBodies(data, specVersion) {
if (!data || !data.properties) {
return;
}
Expand All @@ -14,7 +14,7 @@ function getRequestBodies(data) {
.map(([key, value]) => {
return {
key,
value: mapRequestBody(activateItem(value), get(data, 'required', []).includes(key), true)
value: mapRequestBody({ data: activateItem(value), required: get(data, 'required', []).includes(key), isParentActivated: true, specVersion }),
};
})
.reduce((acc, { key, value }) => {
Expand All @@ -23,15 +23,15 @@ function getRequestBodies(data) {
}, {});
}

function mapRequestBody(data, required, isParentActivated = false) {
function mapRequestBody({ data, required, isParentActivated = false, specVersion }) {
if (!data) {
return;
}
if (hasRef(data)) {
return commentDeactivatedItemInner(getRef(data), data.isActivated, isParentActivated);
return commentDeactivatedItemInner(getRef(data, specVersion), data.isActivated, isParentActivated);
}

const content = getContent(data, data.isActivated && isParentActivated);
const content = getContent({ data, isParentActivated: data.isActivated && isParentActivated, specVersion });
if (!content) {
return;
}
Expand Down
Loading