cebe / yii2-openapi

REST API application generator for Yii2, openapi 3.0 YAML -> Yii2
MIT License
129 stars 23 forks source link

Bug $ref with x-faker #162

Closed siggi-k closed 7 months ago

siggi-k commented 9 months ago

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: you@example.com
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 commented 9 months ago

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.

SOHELAHMED7 commented 7 months ago

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