cancel
Showing results for 
Search instead for 
Did you mean: 

how to avoid repeating properties in open-api specs

Highlighted
New Contributor

how to avoid repeating properties in open-api specs

Hi,

I have collection in that for the collection item,I do not want to see the properties,the swagger edition gives warning for repeating properties,how to avoid it? 

6 REPLIES 6
Highlighted
Moderator

Re: how to avoid repeating properties in open-api specs

Can your post your API definition? So that we could see where the error is.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
New Contributor

Re: how to avoid repeating properties in open-api specs

Hey,

you can consider this as sample open -api specs,getting error at line 41 in swagger editor,want to avoid it.

---
openapi: 3.0.1
info:
title: Test
version: v1
paths:
/v1/getList:
get:
summary: get List.
description: get List.
operationId: getList
responses:
default:
description: get List
content:
application/json:
schema:
$ref: '#/components/schemas/B'
components:
schemas:
A:
title: A
type: object
properties:
field1:
type: string
field2:
type: string

B:
title: B
type: object
properties:
field3:
maxLength: 80
type: string
aList:
type: array
items:
$ref: '#/components/schemas/A'
properties:
field1:
type: string
field2:
type: string


Highlighted
Moderator

Re: how to avoid repeating properties in open-api specs

@abhijitjadhav67, it looks like YAML indentation was lost when you pasted the example. Could you please either post the file as an attachment, or use the "insert code" button to re-post the YAML? Thanks.

 

HKosova_0-1594914317648.png

 


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
New Contributor

Re: how to avoid repeating properties in open-api specs

---
openapi: 3.0.1
info:
  title: Test
  version: v1
paths:
  /v1/getList:
    get:
      summary: get List.
      description: get List.
      operationId: getList
      responses:
        default:
          description: get List
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/B'
components:
  schemas:
    A:
      title: A
      type: object
      properties:
        field1:
          type: string
        field2:
          type: string
   
    B:
      title: B
      type: object
      properties:
        field3:
          maxLength: 80
          type: string
        aList:
          type: array
          items:
            $ref: '#/components/schemas/A'
            properties:
              field1:
                type: string
              field2:
                type: string
 
 
Highlighted
Moderator

Re: how to avoid repeating properties in open-api specs

Try this:

    B:
      title: B
      type: object
      properties:
        field3:
          maxLength: 80
          type: string
        aList:
          type: array
          items:
            $ref: '#/components/schemas/A'

 When you use $ref, there's no need to redefine the referenced properties alongside the $ref.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
New Contributor

Re: how to avoid repeating properties in open-api specs

@HKosova 

I see,Thank you

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors