admin管理员组文章数量:1279021
I have tried creating a schema and validating yaml file structures based on their datatype and I have been constantly getting the same error no matter how I try to resolve it.
The source code where I'm getting this error is here: Openapi_validation
Error Message:
❌ Validation Error: PointerToNowhere: '/components/schemas/CustomAttribute' does not exist within {'oneOf': [{'type': 'string', 'minLength': 0, 'maxLength': 100, 'default': '', 'pattern': '.*', 'description': 'A string value.'}, {'type': 'integer', 'minimum': 0, 'maximum': 100, 'default': 0, 'description': 'An integer value.'}, {'type': 'boolean', 'default': False, 'enum': [True, False], 'description': 'A boolean value.'}, {'type': 'array', 'items': {'oneOf': [{'type': 'string'}, {'type': 'integer'}, {'type': 'boolean'}, {'$ref': '#/components/schemas/CustomAttribute'}]}, 'default': [], 'description': 'An array of values.'}, {'type': 'object', 'properties': {'default': {'type': 'object'}, 'description': {'type': 'string'}, 'properties': {'type': 'object', 'additionalProperties': {'$ref': '#/components/schemas/CustomAttribute'}}}, 'required': ['default', 'description', 'properties']}]}
Codes to run and check in local machine
openapi_schema.yaml
openapi: 3.0.0
info:
title: Custom CRD Validation Schema
version: 1.0.0
components:
schemas:
CustomAttribute:
oneOf:
- type: string
minLength: 0
maxLength: 100
default: ""
pattern: ".*"
description: "A string value."
- type: integer
minimum: 0
maximum: 100
default: 0
description: "An integer value."
- type: boolean
default: false
enum: [true, false]
description: "A boolean value."
- type: array
items:
oneOf:
- type: string
- type: integer
- type: boolean
- $ref: "#/components/schemas/CustomAttribute"
default: []
description: "An array of values."
- type: object
properties:
default:
type: object
description:
type: string
properties:
type: object
additionalProperties:
$ref: "#/components/schemas/CustomAttribute"
required: [default, description, properties]
validate_crd.py
import yaml
import json
from openapi_schema_validator import validate
import sys
# Load OpenAPI schema
with open("openapi_schema.yaml", "r") as f:
openapi_schema = yaml.safe_load(f)
# Load CRD file
with open(sys.argv[1], "r") as f:
crd_data = yaml.safe_load(f)
# Extract the schema definition correctly
custom_schema = openapi_schema["components"]["schemas"]["CustomAttribute"]
# Validate CRD file
try:
validate(instance=crd_data["customAttribute"], schema=custom_schema)
print("✅ CRD is valid.")
except Exception as e:
print(f"❌ Validation Error: {e}")
valid_crd.yaml
customAttribute:
type: object
default: {}
description: "A complex object with multiple properties."
properties:
name:
type: string
minLength: 3
maxLength: 20
default: "John Doe"
pattern: "^[A-Za-z ]+$"
description: "The name of the user."
age:
type: integer
minimum: 18
maximum: 100
default: 25
description: "The age of the user."
isActive:
type: boolean
default: true
enum: [true, false]
description: "Indicates if the user is active."
roles:
type: array
default: ["user", "admin"]
description: "List of user roles."
items:
type: string
settings:
type: object
default: {}
description: "User settings."
properties:
theme:
type: string
default: "dark"
description: "Preferred theme."
notifications:
type: boolean
default: true
description: "Enable or disable notifications."
Steps to Reproduce
- Run
pip install pyyaml openapi_schema_validator
- Run
python validate_crd.py valid_crd.yaml
It would really help if there is any fix for this
版权声明:本文标题:validation - PointerToNowhere Exception when validating CRDs using OpenAPI Schema Validator - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741283559a2370146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论