mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
support for value prop in example
Add support for value prop in example
This commit is contained in:
committed by
Erik Mendoza
parent
fa623d32c0
commit
ac9df06e84
@@ -3,7 +3,8 @@
|
|||||||
* utils.js contains other util functions
|
* utils.js contains other util functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/schemaUtilsCommon.js'),
|
const { formatDataPath, checkIsCorrectType, isKnownType,
|
||||||
|
formatSchemaPathFromAJVErrorToConvertToDataPath } = require('./common/schemaUtilsCommon.js'),
|
||||||
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
|
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
sdk = require('postman-collection'),
|
sdk = require('postman-collection'),
|
||||||
@@ -1360,6 +1361,28 @@ module.exports = {
|
|||||||
return example;
|
return example;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
useExampleValueAsValue(schema, example, components) {
|
||||||
|
let isCandidate = true,
|
||||||
|
schemaProperties = [],
|
||||||
|
schemaObject,
|
||||||
|
schemaDataPath = '',
|
||||||
|
exampleProperties = [];
|
||||||
|
if (!schema) {
|
||||||
|
return isCandidate;
|
||||||
|
}
|
||||||
|
if (schema.$ref) {
|
||||||
|
schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(schema.$ref));
|
||||||
|
schemaObject = _.get(components, schemaDataPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
schemaObject = schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
schemaProperties = Object.keys(schemaObject.properties).sort();
|
||||||
|
exampleProperties = Object.keys(example.value).sort();
|
||||||
|
return JSON.stringify(schemaProperties) === JSON.stringify(exampleProperties);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* converts one of the eamples or schema in Media Type object to postman data
|
* converts one of the eamples or schema in Media Type object to postman data
|
||||||
* @param {*} bodyObj is MediaTypeObject
|
* @param {*} bodyObj is MediaTypeObject
|
||||||
@@ -1410,7 +1433,8 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
bodyData = bodyObj.example;
|
bodyData = bodyObj.example;
|
||||||
// return example value if present else example is returned
|
// return example value if present else example is returned
|
||||||
if (bodyData.hasOwnProperty('value')) {
|
if (bodyData.hasOwnProperty('value') &&
|
||||||
|
this.useExampleValueAsValue(bodyObj.schema, bodyObj.example, components)) {
|
||||||
bodyData = bodyData.value;
|
bodyData = bodyData.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ paths:
|
|||||||
get:
|
get:
|
||||||
operationId: someRequest
|
operationId: someRequest
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/components/parameters/DeepObjectNestedList'
|
|
||||||
- $ref: '#/components/parameters/DeepObjectLengthParameter'
|
- $ref: '#/components/parameters/DeepObjectLengthParameter'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
|
|||||||
91
test/data/valid_openapi/valuePropInExample.yaml
Normal file
91
test/data/valid_openapi/valuePropInExample.yaml
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
openapi: 3.0.0
|
||||||
|
info:
|
||||||
|
version: '1.1.1'
|
||||||
|
title: 'ExampleYaml'
|
||||||
|
license:
|
||||||
|
name: MIT
|
||||||
|
servers:
|
||||||
|
- url: 'localhost:3000'
|
||||||
|
paths:
|
||||||
|
/user:
|
||||||
|
get:
|
||||||
|
summary: 'Sample endpoint: Returns details about a particular user'
|
||||||
|
operationId: listUser
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: query
|
||||||
|
description: ID of the user
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: 'Sample response: Details about a user by ID'
|
||||||
|
headers:
|
||||||
|
x-next:
|
||||||
|
description: A link to the next page of responses
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/User'
|
||||||
|
example:
|
||||||
|
id: "5789-6378-6372-6372"
|
||||||
|
name: Vani
|
||||||
|
tag: true
|
||||||
|
value: QA
|
||||||
|
lastmodifieddate: "2022-03-30T07:01:46"
|
||||||
|
lastmodifiedBy: VM
|
||||||
|
default:
|
||||||
|
description: Unexpected error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Error'
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
User:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- id
|
||||||
|
- name
|
||||||
|
- tag
|
||||||
|
- value
|
||||||
|
- lastmodifieddate
|
||||||
|
- lastmodifiedBy
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
tag:
|
||||||
|
type: string
|
||||||
|
value:
|
||||||
|
type: string
|
||||||
|
lastmodifieddate:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
lastmodifiedBy:
|
||||||
|
type: string
|
||||||
|
Error:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- code
|
||||||
|
- message
|
||||||
|
properties:
|
||||||
|
code:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
securitySchemes:
|
||||||
|
BasicAuth:
|
||||||
|
type: http
|
||||||
|
scheme: basic
|
||||||
|
security:
|
||||||
|
- BasicAuth: []
|
||||||
Reference in New Issue
Block a user