Amartus / yang2swagger

Yang to swagger generator
Eclipse Public License 1.0
32 stars 21 forks source link

Add regex patterns to swagger #3

Closed jdillard closed 5 years ago

jdillard commented 6 years ago

The swagger schemas currently only shows a type of string, without pulling in the associated pattern, e.g. in typedef ipv4-address, if it exists. Looking into it, Swagger supports the pattern field in the parameter object, so it would be nice to pull that in to help with validation on the API calls.

We started looking into it, but weren't sure the best way to implement. We found a getPattern function in swagger-core, but wasn't sure where to tie that in. If anyone has ideas on how to get the patterns in, I think that would be a helpful addition to the yang2swagger tool.

bartoszm commented 6 years ago

I have started looking into that

dmrozowicz commented 6 years ago

The YANG "pattern" statement, which is an optional substatement to the "type" statement, takes as an argument a regular expression in XML Schema (xsd) dialect https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#regexs

Mentioned format is not fully compatible with Swagger pattern which uses JavaScript/ECMA 262 regular expression dialect (https://www.ecma-international.org/ecma-262/8.0/index.html#sec-lexical-and-regexp-grammars). Below are main differences/limitations that my lead to bizarre issues when it comes to validation using XSD regex treated as as ECMA 262 dialect:

jdillard commented 6 years ago

This is unfortunate, but you make an excellent point about the lack of compatibility between the two dialects. Thank you for the information.