Closed KillianLeroux closed 3 years ago
I make some modifications:
function extractPathParameters(path, paramsMeta) {
const regexParamBraces = /{\s*[\w-]+\s*}/g
const regexParamDoubleDots = /:\s*[\w-]+/g
const matched = path.match(regexParamBraces) || path.match(regexParamDoubleDots) || []
return matched.map(match => {
let name = match.replace(':', '')
if (match.match(regexParamBraces)) {
name = match.slice(1, -1)
}
const { type = 'string', description, example } = paramsMeta[name] || {}
return {
name,
in: 'path',
schema: { type },
required: true,
...(description ? { description } : {}),
...(example ? { example } : {})
}
})
}
function scrapeURL (url) {
if (url === '' || url.raw === '') {
return { valid: false }
}
if (typeof url === 'string' || url instanceof String) {
const objUrl = new URL(url)
return {
raw: url,
path: decodeURIComponent(objUrl.pathname).slice(1).split('/'),
query: [],
protocol: objUrl.protocol.slice(0, -1),
host: decodeURIComponent(objUrl.hostname).split('.'),
port: objUrl.port,
valid: true
}
}
const regexParamDoubleDots = /:\s*[\w-]+/g
if (url.raw && typeof url.raw === 'string' && url.raw.search(regexParamDoubleDots) > 0) {
const paramsToReplace = url.raw.match(regexParamDoubleDots) || []
paramsToReplace.map(match => {
const paramFormatted = '{' + match.replace(':', '') + '}'
url.raw = url.raw.replace(match, paramFormatted)
const index = url.path.indexOf(match)
if (~index) {
url.path[index] = paramFormatted
}
})
}
return { ...url, valid: true }
}
And I obtain that in result:
/companies/{companyId}:
get:
tags:
- Companies
summary: Get Company
description: Get Company informations from provided Company ID.
parameters:
- name: format
in: query
schema:
type: string
description: '{{Desc - Format}}'
example: xml
- name: withOffers
in: query
schema:
type: boolean
description: Indicates if you want Company informations with its offers or not
example: 'true'
- name: companyId
in: path
schema:
type: string
required: true
responses:
'200':
description: Successful response
content:
application/json: {}
It seems to work :)
What do you think?
@KillianLeroux hi!
Interesting I didn't know about the semi colon sintax in path parameters, is that a new feature from postman?
I will take into account your suggestions definitely and will add as soon as I have time or you can create a pull request with the changes and I will integrate faster ;-)
Best regards
Ahah I don't know if it's a new feature ^^
Fine I'll try to find time to make a PR ;)
@KillianLeroux thanks! I will include anyway as I think is a cool feature, so if you have not time don't worry I will implement anyway for sure ;-)
Hi!
First of all: thanks for your work! ;)
I use path parameters in my requests and it's impossible to use in Swagger :(
Documentation: https://learning.postman.com/docs/sending-requests/requests/#sending-parameters
Example:
Postman interface:![image](https://user-images.githubusercontent.com/13987239/127632752-16af53dd-0524-43d9-96fd-a8451297cb66.png)
Postman JSON Export:
p2o result:
Do you think it's difficult to add? I could try to add this :)
Thank you =)