orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
3.18k stars 336 forks source link

fix: faker recursive reference pascal sanitation #1673

Closed Marfyy closed 4 weeks ago

Marfyy commented 4 weeks ago

Status

READY

Description

Fixed bug when faker attempted to create mocked data, the schema had recursive references, where the name of the schema was changed when sanitized to pascal case. The bug was fixed with the change in packages\mock\src\faker\getters\scalar.ts:176, but I found two checks to existingReferencedProperties in packages\mock\src\faker\getters\object.ts and packages\mock\src\faker\getters\combine.ts, so I thought I would proactively fix them too

Todos

Steps to Test or Reproduce

Here is a simplified, obfuscated version of the json that caused the issue. The sanitation changed Foo.Bar.MainMenuItemDTO to FooBarMainMenuItemDTO, causing it to miss the check in existingReferencedProperties

I ran this json in the react query sample to confirm the bug, and the fix

{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "Foo Bar Api"
  },
  "host": "localhost:443",
  "basePath": "/",
  "schemes": ["https"],
  "paths": {
    "/api/foo/bar": {
      "get": {
        "tags": ["Foo"],
        "operationId": "Foo_Bar",
        "consumes": [],
        "produces": ["application/json"],
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/Foo.Bar.MainMenuItemDTO"
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "definitions": {
    "Foo.Bar.MainMenuItemDTO": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Foo.Bar.MainMenuItemDTO"
          }
        }
      }
    }
  }
}
Marfyy commented 4 weeks ago

Hmm, I saw that the yarn.lock file was updated and bumped a few version locally when I did yarn install. I discarded that. Not sure why it did, since I did not change any packages.

melloware commented 4 weeks ago

safe to rebase!