I\'m writing my swagger definition in yaml. Say I have a definition that looks something like this.
paths:
/payloads:
post:
summary: create a pay
I'm in the same problem rigth now. Im my case, I tried to override requerid block of model. But didn't work. =[ Then, I remembered we can add new properties of a $ref. So it works if you define the requeried fields on schema for each method. Some thing like this (Focus on required block for each ref):
swagger: '2.0'
info:
title: API
version: 0.0.1
host: api.help.v1
basePath: /help
schemes:
- https
definitions:
MyModel:
description: 'Exemplo'
type: object
properties:
field_1:
type: string
field_2:
type: string
field_3:
type: string
paths:
'/helps':
post:
description: ''
summary: ''
parameters:
- in: body
name: payload
schema:
type: object
allOf:
- $ref: '#/definitions/MyModel'
required:
- field_1
responses:
'200':
description: OK
'400':
description: N_OK
put:
description: ''
summary: ''
parameters:
- in: body
name: payload
schema:
type: object
allOf:
- $ref: '#/definitions/MyModel'
required:
- field_2
responses:
'200':
description: OK
'400':
description: N_OK
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
Oh! On swagger editor show that only by model view:
I didn't try yet. But should be possible to define Model like that.