open-api icon indicating copy to clipboard operation
open-api copied to clipboard

[openapi-jsonschema-parameters] Some Openapi Schema in Path Parameters cannot be converted to JSON schema

Open zihehuang opened this issue 6 years ago • 3 comments

The converter fails to convert some openapi schema, such as the one shown below:

const parametersSchemas = convertParametersToJSONSchema([
  {
    "name": "id_or_uri",
    "in": "path",
    "description": "The id or uri of the resource",
    "required": true,
    "schema": {
      "oneOf": [
        {
          "type": "string",
          "pattern": "^[0-9a-km-zA-HJ-Z]{7}$"
        },
        {
          "type": "string",
          "pattern": "^prefix:[0-9]{6,12}$"
        }
      ]
    }
  }
]);

console.log(parametersSchema)
{
  path: {
    properties: {
      id_or_uri: {}
    },
    required: [ 'id_or_uri' ] 
  }
}

I haven't dug very deep into the source code yet, but I am curious what's the rationale behind this behavior.

zihehuang avatar Feb 25 '19 19:02 zihehuang

Please investigate further and open a PR!

jsdevel avatar Feb 25 '19 23:02 jsdevel

can confirm that pattern validation is not working for:

ObjectId:
      type: string
      pattern: /^[a-f\d]{24}$/i
id:
      in: path
      name: id
      schema:
        $ref: '#/components/schemas/ObjectId'

l-ko avatar May 21 '19 09:05 l-ko

please open a PR @I-ko, if you have time

jsdevel avatar May 21 '19 16:05 jsdevel