Code Monkey home page Code Monkey logo

Comments (11)

MikeRalphson avatar MikeRalphson commented on June 6, 2024

Bad in what sense? It seems to be a valid ECMA-262 regex.

In the original AWS definition it was

{ "pattern":"^[0-9A-Za-z\\.\\-_]*(?<!\\.)$" }

and the output yaml is

pattern: '^[0-9A-Za-z\.\-_]*\(\?<!\.\)$'

So it may have been mangled by convertRegex.

https://github.com/Mermade/aws2openapi/blob/5c3208167355eb8949e224add24fb0a770189d48/index.js#L183-L209

from aws2openapi.

rbren avatar rbren commented on June 6, 2024

from aws2openapi.

MikeRalphson avatar MikeRalphson commented on June 6, 2024

I'm not sure - as their format is undocumented, but I've assumed it's POSIX BRE.

from aws2openapi.

MikeRalphson avatar MikeRalphson commented on June 6, 2024

Use of native JS RegExp here

https://github.com/aws/aws-sdk-js/blob/c108474595ec8714f97e47439090bc775fb76a25/lib/param_validator.js#L161-L169

Seems to indicate it should be a standard ECMA 262 RegExp... but if it was mangled by convertRegex that means the RegExp constructor throws on it:

SyntaxError: Invalid regular expression: /^[0-9A-Za-z.-_]*(?<!.)$/: Invalid group

Perhaps all we can do is report it upstream?

from aws2openapi.

rbren avatar rbren commented on June 6, 2024

If the original regexen are ECMA 262 already, why is convertRegex necessary?

The regex works properly in the aws-sdk, but the regex in their JSON does indeed throw an invalid group when passed to the RegExp constructor...

from aws2openapi.

MikeRalphson avatar MikeRalphson commented on June 6, 2024

If the original regexen are ECMA 262 already, why is convertRegex necessary?

Because a number of patterns in the AWS json files throw errors in the RegExp constructor* and I assumed it was because they were POSIX BREs not ECMA 262 REs. I think the first example I found showed up as BRE syntax in some tool or other.

*and I wanted the resultant OpenAPI definitions to pass validation.

Can you debug the SDK and see if/how it is managing to instantiate the regex?

The lambda client appears to the load the min version of the API definition, not the normal one, and the min version doesn't contain any pattern properties (or descriptions, or ...).

from aws2openapi.

rbren avatar rbren commented on June 6, 2024

It looks like the JS client doesn't do any client-side validation actually. Invalid regexen still get sent to the server, which responds with:

{"message":"1 validation error detected: Value 'foo&*' at 'code.s3Bucket' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[0-9A-Za-z\\.\\-_]*(?<!\\.)$"}

from aws2openapi.

rbren avatar rbren commented on June 6, 2024

According to this cheatsheet, the regex in question is a negative look-behind which says that the string can't end in a ., so foo- is legal but not foo..

I don't think JS has an equivalent to negative lookbehinds. I think the best solution is to strip the negative lookbehind, which would result in a regex that's more permissive than it should be, but would at least pass for valid strings.

from aws2openapi.

rbren avatar rbren commented on June 6, 2024

If you're good with that solution I can send a PR

from aws2openapi.

MikeRalphson avatar MikeRalphson commented on June 6, 2024

That would be great, thanks.

from aws2openapi.

MikeRalphson avatar MikeRalphson commented on June 6, 2024

I think we can close this?

from aws2openapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.