Project: KICS (Provisioning / Security & Compliance)
File: 881a6e71-c2a7-4fe2-b9c3-dfcf08895331.md

title: Example Not Compliant With Schema Type (v3) hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 881a6e71-c2a7-4fe2-b9c3-dfcf08895331 Query name: Example Not Compliant With Schema Type (v3) Platform: OpenAPI Severity: <span style="color:#5bc0de">Info</span> Category: Best Practices URL: Examples values and fields should be compliant with the schema type<br> ```json title="Positive test num. 1 - json file" hl_lines="21" { "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": { "$ref": "#/components/schemas/MyObject" }, "examples": { "object": { "$ref": "#/components/examples/objectExample" } } } } } } } } }, "components": { "schemas": { "MyObject": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" } } } }, "examples": { "objectExample": { "value": { "id": 1, "name": "new object" }, "summary": "A sample object" } } } } ``` ```yaml title="Positive test num. 2 - yaml file" hl_lines="20" 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 parameters: name: limit2 in: body description: max records to return required: true schema: type: string example: 132 ``` ```json title="Positive test num. 3 - json file" hl_lines="44" { "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" } }, "parameters": [ { "name": "limit2", "in": "body", "description": "max records to return", "required": true, "schema": { "type": "number", "example": 132 } } ] } } }, "definitions": { "Tag": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } }, "example": { "name": "Puma", "id": "1" } } } } ``` <details><summary>Positive test num. 4 - yaml file</summary> ```yaml hl_lines="30" 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 parameters: name: limit2 in: body description: max records to return required: true schema: type: number example: 132 definitions: Tag: type: object properties: id: type: integer format: int64 name: type: string example: name: "Puma" id: "1" ``` </details> <details><summary>Positive test num. 5 - 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: Success content: application/json: schema: "$ref": "#/components/schemas/MyObject" examples: object: "$ref": "#/components/examples/objectExample" components: schemas: MyObject: type: object properties: id: type: string name: type: string examples: objectExample: value: id: 1 name: new object summary: A sample object ``` </details> <details><summary>Positive test num. 6 - json file</summary> ```json hl_lines="24" { "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/my_schema" }, "examples": { "foo": { "value": "this is a string" }, "foo_2": { "value": true } } } } } } } } }, "components": { "schemas": { "my_schema": { "type": "string" } } }, "security": [ { "exampleSecurity": [] } ] } ``` </details> <details><summary>Positive test num. 7 - yaml file</summary> ```yaml hl_lines="20" 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:

"#/components/schemas/my_schema" examples: foo: value: "this is a string" foo_2: value: true components: schemas: my_schema: type: string security: exampleSecurity: [] ``` </details> <details><summary>Positive test num. 8 - json file</summary> ```json hl_lines="34 20" { "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/my_schema" }, "example": true } } }, "400": { "description": "200 response", "content": { "application/json": { "schema": { "type": "array", "items": { "type": "integer" } }, "example": [ 1, 2, "3", 4 ] } } } } } } }, "components": { "schemas": { "my_schema": { "type": "string" } } }, "security": [ { "exampleSecurity": [] } ] } ``` </details> <details><summary>Positive test num. 9 - yaml file</summary> ```yaml hl_lines="17 26" 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/my_schema" example: true "400": description: 200 response content: application/json: schema: type: array items: type: integer example: 1 2 "3" 4 components: schemas: my_schema: type: string security: exampleSecurity: [] ``` </details> <details><summary>Positive test num. 10 - json file</summary> ```json hl_lines="24" { "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": "array", "items": { "type": "string" } }, "examples": { "foo": { "value": [ true, "test2", "test3" ] } } } } } } } } }, "security": [ { "exampleSecurity": [] } ] } ``` </details> <details><summary>Positive test num. 11 - yaml file</summary> ```yaml hl_lines="20" 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: array items: type: string examples: foo: value: true "test2" "test3" security: exampleSecurity: [] ``` </details> <details><summary>Positive test num. 12 - json file</summary> ```json hl_lines="25" { "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" } }, "parameters": [ { "name": "limit2", "in": "body", "description": "max records to return", "required": true, "schema": { "type": "string", "example": 132 } } ] } } }, "parameters": { "limitParam": { "name": "limit", "in": "body", "description": "max records to return", "required": true, "schema": { "type": "string" } } } } ``` </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": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/MyObject" }, "examples": { "object": { "$ref": "#/components/examples/objectExample" } } } } } } } } }, "components": { "schemas": { "MyObject": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" } } } }, "examples": { "objectExample": { "value": { "id": "1", "name": "new object" }, "summary": "A sample object" } } } } ``` ```json title="Negative test num. 2 - json file" { "swagger": "2.0", "info": { "title": "Simple API Overview", "version":

}, "paths": { "/": { "get": { "operationId": "listVersionsv2", "summary": "List API versions", "responses": { "200": { "description": "200 response" } }, "parameters": [ { "name": "limit2", "in": "body", "description": "max records to return", "required": true, "schema": { "type": "number", "example": 132 } } ] } } }, "definitions": { "Tag": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } }, "example": { "name": "Puma", "id": 1 } } } } ``` ```yaml title="Negative test num. 3 - yaml file" 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 parameters: name: limit2 in: body description: max records to return required: true schema: type: number example: 132 definitions: Tag: type: object properties: id: type: integer format: int64 name: type: string example: name: "Puma" id: 1 ``` <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: "$ref": "#/components/schemas/MyObject" examples: object: "$ref": "#/components/examples/objectExample" components: schemas: MyObject: type: object properties: id: type: string name: type: string examples: objectExample: value: id: "1" name: new object summary: A sample object ``` </details> <details><summary>Negative test num. 5 - json file</summary> ```json { "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/my_schema" }, "examples": { "foo": { "value": "this is a string" }, "foo_2": { "value": "true" } } } } } } } } }, "components": { "schemas": { "my_schema": { "type": "string" } } }, "security": [ { "exampleSecurity": [] } ] } ``` </details> <details><summary>Negative test num. 6 - 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: $ref: "#/components/schemas/my_schema" examples: foo: value: "this is a string" foo_2: value: "true" components: schemas: my_schema: type: string security: exampleSecurity: [] ``` </details> <details><summary>Negative test num. 7 - json file</summary> ```json { "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/my_schema" }, "example": "true" } } } } } } }, "components": { "schemas": { "my_schema": { "type": "string" } } }, "security": [ { "exampleSecurity": [] } ] } ``` </details> <details><summary>Negative test num. 8 - 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: $ref: "#/components/schemas/my_schema" example: "true" components: schemas: my_schema: type: string security: exampleSecurity: [] ``` </details> <details><summary>Negative test num. 9 - json file</summary> ```json { "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": "array", "items": { "type": "string" } }, "examples": { "foo": { "value": [ "true", "test2", "test3" ] } } } } } } } } }, "security": [ { "exampleSecurity": [] } ] } ``` </details> <details><summary>Negative test num. 10 - 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: