Skip to content

Commit

Permalink
Merge branch 'master' into regal-non-raw-regex-pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturRibeiro-CX authored Feb 28, 2025
2 parents 14bc51e + d305214 commit cdcb7e4
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 30 deletions.
24 changes: 13 additions & 11 deletions assets/queries/openAPI/3.0/invalid_media_type_value/query.rego
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import data.generic.openapi as openapi_lib

CxPolicy[result] {
doc := input.document[i]
openapi_lib.check_openapi(doc) == "3.0"
openapi_lib.check_openapi(doc) == "3.0"

[path, value] := walk(doc)
content = value.content[mime]
[path, value] := walk(doc)
content = value.content[mime]

not openapi_lib.is_valid_mime(mime)
# Ensure "content" inside "properties" is treated as a field name, not an OpenAPI content spec.
not path[count(path) - 1] == "properties"
not openapi_lib.is_valid_mime(mime)

result := {
"documentId": doc.id,
"searchKey": sprintf("%s.content.%s", [openapi_lib.concat_path(path), mime]),
"issueType": "IncorrectValue",
"keyExpectedValue": "The Media Type should be a valid value",
"keyActualValue": "The Media Type is a invalid value",
}
result := {
"documentId": doc.id,
"searchKey": sprintf("%s.content.%s", [openapi_lib.concat_path(path), mime]),
"issueType": "IncorrectValue",
"keyExpectedValue": "The Media Type should be a valid value",
"keyActualValue": "The Media Type is an invalid value",
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
openapi: 3.0.0
info:
title: Pet Store API
version: 1.0.0
servers:
- url: https://api.example.com/v1
paths:
/pets:
get:
summary: Get a list of pets
responses:
'200':
description: Successful response
content:
application/json:
example: { "pets": ["dog", "cat"] }
post:
summary: Add a new pet
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
example: "Fido"
pattern: "^[A-Za-z]{1,20}$"
species:
type: string
example: "dog"
color:
type: string
enum:
- brown
- grey
- black
- white
birthDate:
type: string
format: date
weight:
type: integer
format: int32
someSubType:
type: 'object'
properties:
content:
type: string
responses:
'201':
description: Pet added successfully
/pets/{petId}:
get:
summary: Get details of a specific pet
parameters:
- name: petId
in: path
required: true
schema:
type: integer
format: int64
responses:
'200':
description: Successful response
content:
application/json:
example: { "name": "Fido", "species": "dog" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"openapi": "3.0.0",
"info": {
"title": "Pet Store API",
"version": "1.0.0"
},
"servers": [
{
"url": "https://api.example.com/v1"
}
],
"paths": {
"/pets": {
"get": {
"summary": "Get a list of pets",
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"example": { "pets": ["dog", "cat"] }
}
}
}
}
},
"post": {
"summary": "Add a new pet",
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"example": "Fido",
"pattern": "^[A-Za-z]{1,20}$"
},
"species": {
"type": "string",
"example": "dog"
},
"color": {
"type": "string",
"enum": [
"brown",
"grey",
"black",
"white"
]
},
"birthDate": {
"type": "string",
"format": "date"
},
"weight": {
"type": "integer",
"format": "int32"
},
"someSubType": {
"type": "object",
"properties": {
"content": {
"type": "string"
}
}
}
}
}
}
}
},
"responses": {
"201": {
"description": "Pet added successfully"
}
}
}
},
"/pets/{petId}": {
"get": {
"summary": "Get details of a specific pet",
"parameters": [
{
"name": "petId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"example": { "name": "Fido", "species": "dog" }
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
openapi: 3.0.0
info:
title: Pet Store API
version: 1.0.0
servers:
- url: https://api.example.com/v1
paths:
/pets:
get:
summary: Get a list of pets
responses:
'200':
description: Successful response
content:
application/json:
example: { "pets": ["dog", "cat"] }
post:
summary: Add a new pet
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
example: "Fido"
pattern: "^[A-Za-z]{1,20}$"
species:
type: string
example: "dog"
color:
type: string
enum:
- brown
- grey
- black
- white
birthDate:
type: string
format: date
weight:
type: integer
format: int32
someSubType:
type: 'object'
properties:
content:
type: 'object'
properties:
content:
type: object
properties:
key1:
type: string
key2:
type: integer
responses:
'201':
description: Pet added successfully
/pets/{petId}:
get:
summary: Get details of a specific pet
parameters:
- name: petId
in: path
required: true
schema:
type: integer
format: int64
responses:
'200':
description: Successful response
content:
application/json:
example: { "name": "Fido", "species": "dog" }
Loading

0 comments on commit cdcb7e4

Please sign in to comment.