Support Kubernetes Open API Spec or JSON Schema
See original GitHub issueI’ve tried to run this against Kubernetes OpenAPI Spec but ran into some errors.
curl -O https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json
datamodel-codegen --input swagger.json --input-file-type=openapi --output=mode.py
[... error abridged ...]
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/parser/base.py", line 164, in parse
self.parse_raw()
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/parser/openapi.py", line 12, in parse_raw
spec_string=self.text, backend='openapi-spec-validator'
File "/proj/.venv/lib/python3.7/site-packages/prance/__init__.py", line 106, in __init__
self.parse()
File "/proj/.venv/lib/python3.7/site-packages/prance/__init__.py", line 137, in parse
self._validate()
File "/proj/.venv/lib/python3.7/site-packages/prance/__init__.py", line 172, in _validate
validator(parsed)
File "/proj/.venv/lib/python3.7/site-packages/prance/__init__.py", line 237, in _validate_openapi_spec_validator
raise_from(ValidationError, type_ex)
File "/proj/.venv/lib/python3.7/site-packages/prance/util/exceptions.py", line 16, in raise_from
raise klass(*from_value.args) from from_value
prance.ValidationError: unhashable type: 'dict'
I also tried the JSON Schema version but hit different errors.
pip install openapi2jsonschema
openapi2jsonschema swagger.json --kubernetes
cd schemas
datamodel-codegen --input pod.yaml --input-file-type=jsonschema --output=mode.py
Traceback (most recent call last):
File "/proj/.venv/bin/datamodel-codegen", line 8, in <module>
sys.exit(main())
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/__main__.py", line 168, in main
result = parser.parse()
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/parser/base.py", line 164, in parse
self.parse_raw()
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/parser/jsonschema.py", line 472, in parse_raw
self.parse_raw_obj(obj_name, raw_obj)
File "/proj/.venv/lib/python3.7/site-packages/datamodel_code_generator/parser/jsonschema.py", line 455, in parse_raw_obj
obj = JsonSchemaObject.parse_obj(raw)
File "/proj/.venv/lib/python3.7/site-packages/pydantic/main.py", line 402, in parse_obj
return cls(**obj)
File "/proj/.venv/lib/python3.7/site-packages/pydantic/main.py", line 283, in __init__
raise validation_error
pydantic.error_wrappers.ValidationError: 2 validation errors for JsonSchemaObject
properties -> apiVersion -> type
str type expected (type=type_error.str)
properties -> kind -> type
str type expected (type=type_error.str)
Can this library support Kubernetes Open API Spec or JSON Schema?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Kubernetes supports OpenAPI
OpenAPI allows API providers to define their operations and models, and enables developers to automate their tools and generate their favorite ...
Read more >instrumenta/kubernetes-json-schema - GitHub
The tooling for generating these schemas is openapi2jsonschema. It's not Kubernetes specific and should work with other OpenAPI APIs too. This should be...
Read more >json schema, openapi, kubernetes crd - SEAN K.H. LIAO
Open API describes what your (rest) api looks like. Designed as an extension to json schema, the current version is 3.1.0 which importantly...
Read more >Schemas for Kubernetes types - than seven
From OpenAPI to JSON Schema ... Under-the-hood Kubernetes is all about types. Pods, ReplicationControllers, Deployments, etc. It's these ...
Read more >Why you need to use Kubernetes schema validation tools
Compare schema validation tools that help you avoid ... pre-generated JSON schemas created from the OpenAPI specifications (swagger.json) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@koxudaxi It works! Thank you
That might have something to do with Kubernetes only supporting Open API V2. There is an open PR for supporting V3 kubernetes/enhancements#1263.
That’s why I tried going the JSON Schema route with instrumenta/openapi2jsonschema.