Project: KICS (Provisioning / Security & Compliance)
File: 013bdb4b-9246-4248-b0c3-7fb0fee42a29.md

title: Required Property With Default Value (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 013bdb4b-9246-4248-b0c3-7fb0fee42a29 Query name: Required Property With Default Value (v3) Platform: OpenAPI Severity: <span style="color:#5bc0de">Info</span> Category: Best Practices URL: Required properties receive value from requests, which makes unnecessary declare a default value<br> ```json title="Positive test num. 1 - json file" hl_lines="30 14" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "$ref": "#/components/schemas/MyObject" } } } } }, "components": { "schemas": { "MyObject": { "type": "object", "required": [ "id" ], "properties": { "id": { "type": "string", "default": "4056684e4e1347579362617ad82e5b4e" }, "name": { "type": "string", "default": "guest" } } } } } } ``` ```json title="Positive test num. 2 - json file" hl_lines="25" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "success", "content": { "application/json": { "schema": { "type": "object", "required": [ "id" ], "properties": { "id": { "type": "string", "default": "4056684e4e1347579362617ad82e5b4e" }, "name": { "type": "string", "default": "guest" } } } } } } } } } } } ``` ```yaml title="Positive test num. 3 - yaml file" hl_lines="12 22" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: '200': "$ref": "#/components/schemas/MyObject" components: schemas: MyObject: type: object required: id properties: id: type: string default: 4056684e4e1347579362617ad82e5b4e name: type: string default: guest ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="23" openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: '200': description: success content: application/json: schema: type: object required: id properties: id: type: string default: 4056684e4e1347579362617ad82e5b4e name: type: string default: guest ``` </details> <details><summary>Positive test num. 5 - json file</summary> ```json hl_lines="23" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "post": { "summary": "Add a new item", "parameters": [ { "in": "body", "name": "item", "schema": { "type": "object", "required": [ "id" ], "properties": { "id": { "type": "string", "default": "4056684e4e1347579362617ad82e5b4e" }, "name": { "type": "string", "default": "guest" } } } } ], "responses": { "200": { "description": "200 response" } } } } } } ``` </details> <details><summary>Positive test num. 6 - yaml file</summary> ```yaml hl_lines="19" swagger:

info: title: Simple API Overview version: 1.0.0 paths: "/": post: summary: Add a new item parameters: in: body name: item schema: type: object required: id properties: id: type: string default: 4056684e4e1347579362617ad82e5b4e name: type: string default: guest responses: "200": description: 200 response ``` </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": { "$ref": "#/components/schemas/MyObject" } } } } }, "components": { "schemas": { "MyObject": { "type": "object", "required": [ "id" ], "properties": { "id": { "type": "string" }, "name": { "type": "string", "default": "guest" } } } } } } ``` ```json title="Negative test num. 2 - 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": "success", "content": { "application/json": { "schema": { "type": "object", "required": [ "id" ], "properties": { "id": { "type": "string" }, "name": { "type": "string", "default": "guest" } } } } } } } } } } } ``` ```yaml title="Negative test num. 3 - 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': "$ref": "#/components/schemas/MyObject" components: schemas: MyObject: type: object required: id properties: id: type: string name: type: string default: guest ``` <details><summary>Negative test num. 4 - yaml file</summary> ```yaml openapi: 3.0.0 info: title: Simple API Overview version: 1.0.0 paths: "/": get: operationId: listVersionsv2 summary: List API versions responses: '200': description: success content: application/json: schema: type: object required: id properties: id: type: string name: type: string default: guest ``` </details> <details><summary>Negative test num. 5 - json file</summary> ```json { "swagger": "2.0", "info": { "title": "Simple API Overview", "version": "1.0.0" }, "paths": { "/": { "post": { "summary": "Add a new item", "responses": { "200": { "description": "200 response" } }, "parameters": [ { "in": "body", "name": "item", "schema": { "type": "object", "required": [ "id" ], "properties": { "id": { "type": "string" }, "name": { "type": "string", "default": "guest" } } } } ] } } } } ``` </details> <details><summary>Negative test num. 6 - yaml file</summary> ```yaml swagger: "2.0" info: title: Simple API Overview version: 1.0.0 paths: "/": post: summary: Add a new item responses: "200": description: 200 response parameters: in: body name: item schema: type: object required: id properties: id: type: string name: type: string default: guest ``` </details>