@microsoft/m365-spec-parser 0.2.3-alpha.6f30def09.0 → 0.2.3-alpha.86ff45725.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/dist/index.esm2017.js +2 -0
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +142 -1
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +2 -0
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +142 -1
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/interfaces.d.ts +1 -0
- package/dist/src/jsonDataGenerator.d.ts +6 -0
- package/package.json +3 -3
package/dist/index.node.cjs.js
CHANGED
|
@@ -104,6 +104,7 @@ exports.WarningType = void 0;
|
|
|
104
104
|
WarningType["ConvertSwaggerToOpenAPI"] = "convert-swagger-to-openapi";
|
|
105
105
|
WarningType["FuncDescriptionTooLong"] = "function-description-too-long";
|
|
106
106
|
WarningType["OperationIdContainsSpecialCharacters"] = "operationid-contains-special-characters";
|
|
107
|
+
WarningType["GenerateJsonDataFailed"] = "generate-json-data-failed";
|
|
107
108
|
WarningType["Unknown"] = "unknown";
|
|
108
109
|
})(exports.WarningType || (exports.WarningType = {}));
|
|
109
110
|
/**
|
|
@@ -144,6 +145,7 @@ ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are u
|
|
|
144
145
|
ConstantString.OperationIdContainsSpecialCharacters = "Operation id '%s' in OpenAPI description document contained special characters and was renamed to '%s'.";
|
|
145
146
|
ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
|
|
146
147
|
ConstantString.FuncDescriptionTooLong = "The description of the function '%s' is too long. The current length is %s characters, while the maximum allowed length is %s characters.";
|
|
148
|
+
ConstantString.GenerateJsonDataFailed = "Failed to generate JSON data for api: %s due to %s.";
|
|
147
149
|
ConstantString.WrappedCardVersion = "devPreview";
|
|
148
150
|
ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
|
|
149
151
|
ConstantString.WrappedCardResponseLayout = "list";
|
|
@@ -1981,6 +1983,130 @@ class ManifestUpdater {
|
|
|
1981
1983
|
}
|
|
1982
1984
|
}
|
|
1983
1985
|
|
|
1986
|
+
// Copyright (c) Microsoft Corporation.
|
|
1987
|
+
class JsonDataGenerator {
|
|
1988
|
+
static generate(schema) {
|
|
1989
|
+
return this.generateMockData(schema);
|
|
1990
|
+
}
|
|
1991
|
+
static generateMockData(schema) {
|
|
1992
|
+
if (this.visitedSchemas.has(schema)) {
|
|
1993
|
+
return null; // Prevent circular reference
|
|
1994
|
+
}
|
|
1995
|
+
this.visitedSchemas.add(schema);
|
|
1996
|
+
let result;
|
|
1997
|
+
if (schema.anyOf) {
|
|
1998
|
+
// Select the first schema in anyOf
|
|
1999
|
+
const selectedSchema = schema.anyOf[0];
|
|
2000
|
+
result = this.generateMockData(selectedSchema);
|
|
2001
|
+
}
|
|
2002
|
+
else if (schema.oneOf) {
|
|
2003
|
+
// Select the first schema in oneOf
|
|
2004
|
+
const selectedSchema = schema.oneOf[0];
|
|
2005
|
+
result = this.generateMockData(selectedSchema);
|
|
2006
|
+
}
|
|
2007
|
+
else if (schema.allOf) {
|
|
2008
|
+
// merge all schemas in allOf
|
|
2009
|
+
result = {};
|
|
2010
|
+
for (const subschema of schema.allOf) {
|
|
2011
|
+
const data = this.generateMockData(subschema);
|
|
2012
|
+
result = Object.assign(Object.assign({}, result), data);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
else {
|
|
2016
|
+
switch (schema.type) {
|
|
2017
|
+
case "string":
|
|
2018
|
+
if (schema.example !== undefined) {
|
|
2019
|
+
result = schema.example;
|
|
2020
|
+
}
|
|
2021
|
+
else if (schema.format) {
|
|
2022
|
+
switch (schema.format) {
|
|
2023
|
+
case "date-time":
|
|
2024
|
+
result = "2024-11-01T05:25:43.593Z";
|
|
2025
|
+
break;
|
|
2026
|
+
case "email":
|
|
2027
|
+
result = "example@example.com";
|
|
2028
|
+
break;
|
|
2029
|
+
case "uuid":
|
|
2030
|
+
result = "123e4567-e89b-12d3-a456-426614174000";
|
|
2031
|
+
break;
|
|
2032
|
+
case "ipv4":
|
|
2033
|
+
result = "192.168.0.1";
|
|
2034
|
+
break;
|
|
2035
|
+
case "ipv6":
|
|
2036
|
+
result = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
|
|
2037
|
+
break;
|
|
2038
|
+
default:
|
|
2039
|
+
result = "example string";
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
else {
|
|
2043
|
+
result = "example string";
|
|
2044
|
+
}
|
|
2045
|
+
break;
|
|
2046
|
+
case "number":
|
|
2047
|
+
if (schema.example !== undefined) {
|
|
2048
|
+
result = schema.example;
|
|
2049
|
+
}
|
|
2050
|
+
else if (schema.format) {
|
|
2051
|
+
switch (schema.format) {
|
|
2052
|
+
case "float":
|
|
2053
|
+
result = 3.14;
|
|
2054
|
+
break;
|
|
2055
|
+
case "double":
|
|
2056
|
+
result = 3.14159;
|
|
2057
|
+
break;
|
|
2058
|
+
default:
|
|
2059
|
+
result = 123;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
else {
|
|
2063
|
+
result = 123;
|
|
2064
|
+
}
|
|
2065
|
+
break;
|
|
2066
|
+
case "integer":
|
|
2067
|
+
if (schema.example !== undefined) {
|
|
2068
|
+
result = schema.example;
|
|
2069
|
+
}
|
|
2070
|
+
else if (schema.format) {
|
|
2071
|
+
switch (schema.format) {
|
|
2072
|
+
case "int32":
|
|
2073
|
+
result = 123456;
|
|
2074
|
+
break;
|
|
2075
|
+
case "int64":
|
|
2076
|
+
result = 123456789;
|
|
2077
|
+
break;
|
|
2078
|
+
default:
|
|
2079
|
+
result = 123;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
else {
|
|
2083
|
+
result = 123;
|
|
2084
|
+
}
|
|
2085
|
+
break;
|
|
2086
|
+
case "boolean":
|
|
2087
|
+
result = schema.example !== undefined ? schema.example : true;
|
|
2088
|
+
break;
|
|
2089
|
+
case "array":
|
|
2090
|
+
result = [this.generateMockData(schema.items)];
|
|
2091
|
+
break;
|
|
2092
|
+
case "object":
|
|
2093
|
+
result = {};
|
|
2094
|
+
if (schema.properties) {
|
|
2095
|
+
for (const key in schema.properties) {
|
|
2096
|
+
result[key] = this.generateMockData(schema.properties[key]);
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
break;
|
|
2100
|
+
default:
|
|
2101
|
+
result = schema.example || null;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
this.visitedSchemas.delete(schema);
|
|
2105
|
+
return result;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
JsonDataGenerator.visitedSchemas = new Set();
|
|
2109
|
+
|
|
1984
2110
|
// Copyright (c) Microsoft Corporation.
|
|
1985
2111
|
/**
|
|
1986
2112
|
* A class that parses an OpenAPI specification file and provides methods to validate, list, and generate artifacts.
|
|
@@ -2293,9 +2419,24 @@ class SpecParser {
|
|
|
2293
2419
|
const safeAdaptiveCardName = operation.operationId.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2294
2420
|
const fileName = path__default['default'].join(adaptiveCardFolder, `${safeAdaptiveCardName}.json`);
|
|
2295
2421
|
const wrappedCard = wrapAdaptiveCard(card, jsonPath);
|
|
2422
|
+
const { json } = Utils.getResponseJson(operation, false);
|
|
2423
|
+
const schema = json.schema;
|
|
2424
|
+
let jsonData = {};
|
|
2425
|
+
if (schema && Object.keys(schema).length > 0) {
|
|
2426
|
+
try {
|
|
2427
|
+
jsonData = JsonDataGenerator.generate(schema);
|
|
2428
|
+
}
|
|
2429
|
+
catch (err) {
|
|
2430
|
+
result.warnings.push({
|
|
2431
|
+
type: exports.WarningType.GenerateJsonDataFailed,
|
|
2432
|
+
content: Utils.format(ConstantString.GenerateJsonDataFailed, operation.operationId, err.toString()),
|
|
2433
|
+
data: operation.operationId,
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2296
2437
|
yield fs__default['default'].outputJSON(fileName, wrappedCard, { spaces: 2 });
|
|
2297
2438
|
const dataFileName = path__default['default'].join(adaptiveCardFolder, `${safeAdaptiveCardName}.data.json`);
|
|
2298
|
-
yield fs__default['default'].outputJSON(dataFileName,
|
|
2439
|
+
yield fs__default['default'].outputJSON(dataFileName, jsonData, { spaces: 2 });
|
|
2299
2440
|
}
|
|
2300
2441
|
catch (err) {
|
|
2301
2442
|
result.allSuccess = false;
|