yii2-openapi icon indicating copy to clipboard operation
yii2-openapi copied to clipboard

Bug $ref with x-faker

Open siggi-k opened this issue 1 year ago • 1 comments

Initial

schema.yaml

openapi: 3.0.3
# Edit this schema and start your project
# This is sample schema
# To generate code which is based on this schema
# run commands mentioned Development section in README.md file
info:
  title: 'Proxy-Service'
  description: ""
  version: 1.0.0
  contact:
    name: '...'
    email: [email protected]
servers:
  - url: 'http://localhost:9937'
    description: 'Local Dev API'
security:
  - BasicAuth: []
components:
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
  schemas:

    Order:
      type: object
      required:
        - id
      properties:
        id:
          type: integer
        invoice:
          $ref: '#/components/schemas/Invoice'
          x-faker: false

Reproduction steps

$ref: AND x-faker on same attribute

Expected Ref-Attribute with NULL in every row.

Result Don't work

UseCase You already have orders, but the corresponding invoices are only made later, by a self-written function, and not by faker.

siggi-k avatar Feb 05 '24 15:02 siggi-k

Update

I tried with

        invoice:
          allOf:
            - $ref: '#/components/schemas/Invoice'
            - x-faker: false

Unfortunately that doesn't work either. The following is then generated for the migration: $model->invoice = $faker->sentence; But i need this field empty.

siggi-k avatar Feb 08 '24 10:02 siggi-k

Meanwhile the issue is being fixed, this work-around can be used:

`x-faker: '$faker->optional(0, null)->sentence'`

Edit:

Sorry, it won't work in referenced property at this moment

SOHELAHMED7 avatar Apr 24 '24 17:04 SOHELAHMED7