Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where conversion was stuck for certain schemas with pattern. #720

Merged
merged 1 commit into from
May 12, 2023

Conversation

VShingala
Copy link
Member

Overview

For certain definitions, the conversion process was getting stuck. i.e. Even after large amount of type conversion was still going without any result. Below is sample definition for which this issue could happen sometimes.

Sample definition
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: An paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
        nameOnCard:
          maxLength: 63
          minLength: 2
          pattern: "^[A-Za-z !#$%&0-9,'*+\\-.()/:;=@\\\\_\\[\\]`{}]*$"
          type: string
          description: The exact name on the credit card.
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

RCA

Issue was happening due to an infinite loop due to randomness in generation of data from random express. We use json-schema-faker to generate data from schema. In this interface, we have a logic where we add same value into string in cases schema has maxLength defined and generated data from pattern does not satisfy maxLength. While doing so, we were contacting already generated value to itself.

In certain cases having patterns which can generate string with length of 0 as well, we ended up concating empty string on top of empty string infinitely as breaking condition requires certain string length.

Fix

We'll make sure in case of empty string, we keep adding a space to this string in loop to avoid infinite loop.

@VShingala VShingala merged commit 4f2dc7f into develop May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants