Project: KICS (Provisioning / Security & Compliance)
File: 96beb800-566f-49a9-a0ea-dbdf4bc80429.md

title: JSON '$ref' alongside other properties (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 96beb800-566f-49a9-a0ea-dbdf4bc80429 Query name: JSON '$ref' alongside other properties (v3) Platform: OpenAPI Severity: <span style="color:#5bc0de">Info</span> Category: Best Practices URL: Each field on Open API specification which accepts '$ref', infers that field is using a reference object, which has only '$ref' key<br> ```json title="Positive test num. 1 - json file" hl_lines="17" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "schema": { "type": "integer", "$ref": "#/components/schemas/MyObject" } } } } } } } }, "components": { "schemas": { "MyObject": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" } } } } } } ``` ```yaml title="Positive test num. 2 - yaml file" hl_lines="15" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: "200": description: 200 response content: application/json: schema: type: integer "$ref": "#/components/schemas/MyObject" components: schemas: MyObject: type: object properties: id: type: string name: type: string ``` ```json title="Positive test num. 3 - json file" hl_lines="13" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "responses": { "200": { "description": "200 response", "schema": { "$ref": "#/definitions/User", "description": "schema" } } }, "operationId": "listVersionsv2", "summary": "List API versions" } } }, "definitions": { "User": { "properties": { "id": { "type": "integer" }, "name": { "type": "string" } }, "required": [ "id", "name" ] } } } ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="13" swagger: "2.0" info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: "200": description: 200 response schema: $ref: "#/definitions/User" description: schema definitions: User: properties: id: type: integer name: type: string required: id name ``` </details> ```json title="Negative test num. 1 - json file" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MyObject" } } } } } } } }, "components": { "schemas": { "MyObject": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" } } } } } } ``` ```yaml title="Negative test num. 2 - yaml file" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: "200": description: 200 response content: application/json: schema: "$ref": "#/components/schemas/MyObject" components: schemas: MyObject: type: object properties: id: type: string name: type: string ``` ```json title="Negative test num. 3 - json file" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "responses": { "200": { "description": "200 response", "schema": { "$ref": "#/definitions/User" } } }, "operationId": "listVersionsv2", "summary": "List API versions" } } }, "definitions": { "User": { "properties": { "id": { "type": "integer" }, "name": { "type": "string" } }, "required": [ "id", "name" ] } } } ``` <details><summary>Negative test num. 4 - yaml file</summary> ```yaml swagger: "2.0" info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: "200": description: 200 response schema: $ref: "#/definitions/User" definitions: User: properties: id: type: integer name: type: string required: id name ``` </details>