MCPcopy Create free account
hub / github.com/Exrick/xpay / schemaToJSON

Function schemaToJSON

xpay-code/src/main/resources/static/swagger/swagger-ui.js:24617–24702  ·  view source on GitHub ↗
(schema, models, modelsToIgnore, modelPropertyMacro)

Source from the content-addressed store, hash-verified

24615
24616 // copy-pasted from swagger-js
24617 var schemaToJSON = function (schema, models, modelsToIgnore, modelPropertyMacro) {
24618 // Resolve the schema (Handle nested schemas)
24619 schema = resolveSchema(schema);
24620
24621 if(typeof modelPropertyMacro !== 'function') {
24622 modelPropertyMacro = function(prop){
24623 return (prop || {}).default;
24624 };
24625 }
24626
24627 modelsToIgnore= modelsToIgnore || {};
24628
24629 var type = schema.type || 'object';
24630 var format = schema.format;
24631 var model;
24632 var output;
24633
24634 if (!_.isUndefined(schema.example)) {
24635 output = schema.example;
24636 } else if (_.isUndefined(schema.items) && _.isArray(schema.enum)) {
24637 output = schema.enum[0];
24638 }
24639
24640 if (_.isUndefined(output)) {
24641 if (schema.$ref) {
24642 model = models[simpleRef(schema.$ref)];
24643
24644 if (!_.isUndefined(model)) {
24645 if (_.isUndefined(modelsToIgnore[model.name])) {
24646 modelsToIgnore[model.name] = model;
24647 output = schemaToJSON(model.definition, models, modelsToIgnore, modelPropertyMacro);
24648 delete modelsToIgnore[model.name];
24649 } else {
24650 if (model.type === 'array') {
24651 output = [];
24652 } else {
24653 output = {};
24654 }
24655 }
24656 }
24657 } else if (!_.isUndefined(schema.default)) {
24658 output = schema.default;
24659 } else if (type === 'string') {
24660 if (format === 'date-time') {
24661 output = new Date().toISOString();
24662 } else if (format === 'date') {
24663 output = new Date().toISOString().split('T')[0];
24664 } else {
24665 output = 'string';
24666 }
24667 } else if (type === 'integer') {
24668 output = 0;
24669 } else if (type === 'number') {
24670 output = 0.0;
24671 } else if (type === 'boolean') {
24672 output = true;
24673 } else if (type === 'object') {
24674 output = {};

Callers 2

swagger-ui.jsFile · 0.85
createJSONSampleFunction · 0.85

Calls 2

resolveSchemaFunction · 0.85
simpleRefFunction · 0.85

Tested by

no test coverage detected