Open clouetb opened 2 years ago
Thanks for this.
I would like to understand this problem better. Can you share your swagger file, or generate a contrived swagger file that reproduces this issue?
Dear Martin, please find below a trimmed down version of the swagger:
openapi: 3.0.3
info:
title: Silly walk
version: 1.0.0
description: Silly walk app is a monitoring app
paths:
/sillywalk/checks/:
get:
operationId: sillywalk_checks_list
parameters:
- name: limit
required: false
in: query
description: Number of results to return per page.
schema:
type: integer
- name: offset
required: false
in: query
description: The initial index from which to return the results.
schema:
type: integer
tags:
- sillywalk
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedCheckPolymorphicList'
description: ''
post:
operationId: sillywalk_checks_create
tags:
- sillywalk
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
multipart/form-data:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'201':
content:
application/json:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
description: ''
/sillywalk/checks/{id}/:
get:
operationId: sillywalk_checks_retrieve
parameters:
- in: path
name: id
schema:
type: integer
description: A unique value identifying this check.
required: true
tags:
- sillywalk
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
description: ''
put:
operationId: sillywalk_checks_update
parameters:
- in: path
name: id
schema:
type: integer
description: A unique value identifying this check.
required: true
tags:
- sillywalk
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
multipart/form-data:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
description: ''
patch:
operationId: sillywalk_checks_partial_update
parameters:
- in: path
name: id
schema:
type: integer
description: A unique value identifying this check.
required: true
tags:
- sillywalk
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedCheckPolymorphic'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/PatchedCheckPolymorphic'
multipart/form-data:
schema:
$ref: '#/components/schemas/PatchedCheckPolymorphic'
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/CheckPolymorphic'
description: ''
delete:
operationId: sillywalk_checks_destroy
parameters:
- in: path
name: id
schema:
type: integer
description: A unique value identifying this check.
required: true
tags:
- sillywalk
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'204':
description: No response body
components:
schemas:
CheckPolymorphic:
oneOf:
- $ref: '#/components/schemas/HTTPCheck'
- $ref: '#/components/schemas/DNSCheck'
discriminator:
propertyName: resourcetype
mapping:
HTTPCheck: '#/components/schemas/HTTPCheck'
DNSCheck: '#/components/schemas/DNSCheck'
DNSCheck:
type: object
properties:
id:
type: integer
name:
type: string
nullable: true
maxLength: 250
description:
type: string
nullable: true
frequency:
type: string
format: decimal
pattern: ^\d{0,8}(?:\.\d{0,2})?$
nullable: true
polymorphic_ctype:
type: integer
readOnly: true
required:
- id
- polymorphic_ctype
HTTPCheck:
type: object
properties:
id:
type: integer
name:
type: string
nullable: true
maxLength: 250
description:
type: string
nullable: true
frequency:
type: string
format: decimal
pattern: ^\d{0,8}(?:\.\d{0,2})?$
nullable: true
polymorphic_ctype:
type: integer
readOnly: true
required:
- id
- polymorphic_ctype
PaginatedCheckPolymorphicList:
type: object
properties:
count:
type: integer
example: 123
next:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?offset=400&limit=100
previous:
type: string
nullable: true
format: uri
example: http://api.example.org/accounts/?offset=200&limit=100
results:
type: array
items:
$ref: '#/components/schemas/CheckPolymorphic'
PatchedCheckPolymorphic:
oneOf:
- $ref: '#/components/schemas/PatchedHTTPCheck'
- $ref: '#/components/schemas/PatchedDNSCheck'
discriminator:
propertyName: resourcetype
mapping:
HTTPCheck: '#/components/schemas/PatchedHTTPCheck'
DNSCheck: '#/components/schemas/PatchedDNSCheck'
PatchedDNSCheck:
type: object
properties:
id:
type: integer
name:
type: string
nullable: true
maxLength: 250
description:
type: string
nullable: true
frequency:
type: string
format: decimal
pattern: ^\d{0,8}(?:\.\d{0,2})?$
nullable: true
polymorphic_ctype:
type: integer
readOnly: true
PatchedHTTPCheck:
type: object
properties:
id:
type: integer
name:
type: string
nullable: true
maxLength: 250
description:
type: string
nullable: true
frequency:
type: string
format: decimal
pattern: ^\d{0,8}(?:\.\d{0,2})?$
nullable: true
polymorphic_ctype:
type: integer
readOnly: true
I guess I could have trimmed down the swagger a little bit more, but I'm unsure how to do it without harming the consistency of the whole file regarding your generator's need. The original swagger file is automatically generated by djangorestframework. Polymorphism is the result of the django-rest-polymorphic magic.
Thanks for this.
Hi there, while trying to generate using your tool (which is great by the way), I'm greeted with the same error depicted in issue #3. It appears that my swagger is containing oneOf (for inheritance implementation purpose).
I looked at the way you're implementing the allOf but it seems the way should be different in this case and I'm a little bit puzzled by the way it should be. Specifically, it seems two approaches may be chosen: either generate one form that would be somewhat polymorphic, or generate one form for each subclass type. Would you mind sharing some implementation advice to let me try to submit a PR?