-
Notifications
You must be signed in to change notification settings - Fork 96
Resolve: Better way to resolve allOf #208
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: master
Are you sure you want to change the base?
Resolve: Better way to resolve allOf #208
Conversation
Requirements:Simple example of resolving a property: Schema: openapi: 3.0.3
info:
title: Resolve property
version: 1.0.0
components:
schemas:
User:
type: object
required:
- id
- name
properties:
id:
type: integer
name:
type: string
Post:
type: object
properties:
id:
type: integer
content:
type: string
user:
$ref: '#/components/schemas/User'
paths:
'/':
get:
responses:
'200':
description: OK After resolving the references: components:
schemas:
User:
type: object
required:
- id
- name
properties:
id:
type: integer
name:
type: string
Post:
type: object
properties:
id:
type: integer
content:
type: string
user:
type: object
required:
- id
- name
properties:
id:
type: integer
name:
type: string In the same manner Post:
type: object
properties:
id:
type: integer
content:
type: string
user:
allOf:
- $ref: '#/components/schemas/User'
- x-faker: false must be resolved as: Post:
type: object
properties:
id:
type: integer
content:
type: string
user:
type: object
required:
- id
- name
properties:
id:
type: integer
name:
type: string
x-faker: false So we can access /** @var \cebe\openapi\spec\Schema $user A property (similar to "content" and "id") of a Post component schema */
$user->type # 'object'
$user->required # [0 => 'id', 1 => 'name']
$user->{'x-faker'} # `false` At this moment references are resolved but not
|
If a duplicate property is found components:
schemas:
User:
type: object
required:
- id
- name # <--------------------------------------------------------------
properties:
id:
type: integer
name: # <--------------------------------------------------------------
type: string
maxLength: 10 # <--------------------------------------------------------------
Pet:
type: object
required:
- id2
- name # <--------------------------------------------------------------
properties:
id2:
type: integer
name: # <--------------------------------------------------------------
type: string
maxLength: 12 # <--------------------------------------------------------------
Post:
type: object
properties:
id:
type: integer
content:
type: string
user:
allOf:
- $ref: '#/components/schemas/User'
- $ref: '#/components/schemas/Pet'
- x-faker: true then property from the last component schema will be considered: Post:
type: object
properties:
id:
type: integer
content:
type: string
user:
type: object
required:
- id
- name # <--------------------------------------------------------------
- id2
properties:
id:
type: integer
name: # <--------------------------------------------------------------
type: string
maxLength: 12 # <--------------------------------------------------------------
id2:
type: integer
x-faker: true |
This reverts commit b4c19c7.
You'll have better chance in https://github.com/DEVizzent/cebe-php-openapi since this repo is abandoned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the recursive call. This can be a significant performance problem. I'd keep the resolveAllOf part on the Schema only and call it if needed.
@SOHELAHMED7 can you explain more about why you implemented the recursive resolution of allOf? allOf is a property of Schema and it only make sense to call it on a schema object. I'd expect the resolveAllOf() function inside of Schema and see it applied to sub-schemas only. |
I think So I implemented resolving |
Co-authored-by: Carsten Brandt <mail@cebe.cc>
Co-authored-by: Carsten Brandt <mail@cebe.cc>
Co-authored-by: Carsten Brandt <mail@cebe.cc>
Fixes cebe/yii2-openapi#165
Also part of php-openapi/yii2-openapi#10
@cebe
At this moment
allOf
wiil be only resolved for OpenAPI entities classes inheriting from SpecBaseObject.If this pull request is approved and merged I will create similar pull request for Callbacks, Responses and Paths