Project: KICS (Provisioning / Security & Compliance)
File: b481d46c-9c61-480f-86d9-af07146dc4a4.md

title: Schema Discriminator Not Required (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: b481d46c-9c61-480f-86d9-af07146dc4a4 Query name: Schema Discriminator Not Required (v3) Platform: OpenAPI Severity: <span style="color:#5bc0de">Info</span> Category: Structure and Semantics URL: The discriminator property in the Schema Object should be a required property<br> ```json title="Positive test num. 1 - json file" hl_lines="53" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0", "contact": { "name": "contact", "url": "https://www.google.com/", "email": "user@gmail.com" } }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "examples": { "foo": { "value": { "versions": [ { "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "id": "v2.0", "links": [ { "href": "http://127.0.0.1:8774/v2/", "rel": "self" } ] } ] } } } } } } } } } }, "components": { "schemas": { "GeneralError": { "type": "object", "discriminator": { "propertyName": "petType" }, "properties": { "code": { "type": "integer", "format": "int32" }, "petType": { "type": "string" } }, "required": [ "name" ] } } } } ``` ```json title="Positive test num. 2 - json file" hl_lines="25" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0", "contact": { "name": "contact", "url": "https://www.google.com/", "email": "user@gmail.com" } }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "schema": { "type": "object", "discriminator": { "propertyName": "petType" }, "properties": { "code": { "type": "integer", "format": "int32" }, "petType": { "type": "string" } } }, "examples": { "foo": { "value": { "versions": [ { "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "id": "v2.0", "links": [ { "href": "http://127.0.0.1:8774/v2/", "rel": "self" } ] } ] } } } } } } } } } } } ``` ```yaml title="Positive test num. 3 - yaml file" hl_lines="32" 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: examples: foo: value: versions: status: CURRENT updated: "2011-01-21T11:33:21Z" id: v2.0 links: href: http://127.0.0.1:8774/v2/ rel: self security: exampleSecurity: [] components: schemas: GeneralError: type: object discriminator: propertyName: petType properties: code: type: string format: int32 petType: type: string required: name ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="18" 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: object discriminator: propertyName: petType properties: code: type: string format: int32 petType: type: string examples: foo: value: versions: status: CURRENT updated: "2011-01-21T11:33:21Z" id: v2.0 links: href:

rel: self security: exampleSecurity: [] ``` </details> <details><summary>Positive test num. 5 - json file</summary> ```json hl_lines="35" { "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" } } } } }, "definitions": { "GeneralError": { "properties": { "code": { "type": "string", "format": "int32" }, "petType": { "type": "string" } }, "required": [ "name" ], "type": "object", "discriminator": "petType" } } } ``` </details> <details><summary>Positive test num. 6 - yaml file</summary> ```yaml hl_lines="16" 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 definitions: GeneralError: type: object discriminator: petType properties: code: type: string format: int32 petType: type: string required: name ``` </details> <details><summary>Positive test num. 7 - json file</summary> ```json hl_lines="16" { "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": { "discriminator": "petType", "properties": { "code": { "format": "int32", "type": "string" }, "petType": { "type": "string" } }, "type": "object" } } } } } } } ``` </details> <details><summary>Positive test num. 8 - yaml file</summary> ```yaml hl_lines="15" 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: type: object discriminator: petType properties: code: type: string format: int32 petType: type: string ``` </details> ```json title="Negative test num. 1 - json file" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0", "contact": { "name": "contact", "url": "https://www.google.com/", "email": "user@gmail.com" } }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "examples": { "foo": { "value": { "versions": [ { "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "id": "v2.0", "links": [ { "href": "http://127.0.0.1:8774/v2/", "rel": "self" } ] } ] } } } } } } } } } }, "components": { "schemas": { "GeneralError": { "type": "object", "discriminator": { "propertyName": "petType" }, "properties": { "code": { "type": "integer", "format": "int32" }, "petType": { "type": "string" } }, "required": [ "petType" ] } } } } ``` ```json title="Negative test num. 2 - json file" { "openapi": "3.0.0", "info": { "title": "Simple API Overview", "version": "1.0.0", "contact": { "name": "contact", "url": "https://www.google.com/", "email":

} }, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response", "content": { "application/json": { "schema": { "type": "object", "discriminator": { "propertyName": "petType" }, "properties": { "code": { "type": "integer", "format": "int32" }, "petType": { "type": "string" } }, "required": [ "petType" ] }, "examples": { "foo": { "value": { "versions": [ { "status": "CURRENT", "updated": "2011-01-21T11:33:21Z", "id": "v2.0", "links": [ { "href": "http://127.0.0.1:8774/v2/", "rel": "self" } ] } ] } } } } } } } } } } } ``` ```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": description: 200 response content: application/json: examples: foo: value: versions: status: CURRENT updated: "2011-01-21T11:33:21Z" id: v2.0 links: href: http://127.0.0.1:8774/v2/ rel: self security: exampleSecurity: [] components: schemas: GeneralError: type: object discriminator: propertyName: petType properties: code: type: string format: int32 petType: type: string required: petType ``` <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: 200 response content: application/json: schema: type: object discriminator: propertyName: petType properties: code: type: string format: int32 petType: type: string required: petType examples: foo: value: versions: status: CURRENT updated: "2011-01-21T11:33:21Z" id: v2.0 links: href: http://127.0.0.1:8774/v2/ rel: self security: exampleSecurity: [] ``` </details> <details><summary>Negative test num. 5 - json file</summary> ```json { "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" } } } } }, "definitions": { "GeneralError": { "properties": { "code": { "type": "string", "format": "int32" }, "petType": { "type": "string" } }, "required": [ "petType" ], "type": "object", "discriminator": "petType" } } } ``` </details> <details><summary>Negative test num. 6 - 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 definitions: GeneralError: type: object discriminator: petType properties: code: type: string format: int32 petType: type: string required: petType ``` </details> <details><summary>Negative test num. 7 - json file</summary> ```json { "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": { "discriminator": "petType", "properties": { "code": { "format": "int32", "type": "string" }, "petType": { "type": "string" } }, "type": "object", "required": [ "petType" ] } } } } } } } ``` </details> <details><summary>Negative test num. 8 - 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: type: object discriminator: petType properties: code: type: string format: int32 required: petType ``` </details>