openapi3
openapi3 copied to clipboard
Read custom tags
I have custom tags on some Schema
objects. I can't find it in the object, though. Is it possible?
components:
schemas:
User
properties:
userId:
type: string
x-custom-tag-1: someValue
x-custom-tag-2: someOtherValue
It absolutely is; those are called "extensions" and you can read the above ones like so:
dorthu@travel-dev:~/source/openapi3$ cat example.yaml
openapi: "3.1.0"
info:
paths:
components:
schemas:
User:
properties:
userId:
type: string
x-custom-tag-1: someValue
x-custom-tag-2: someOtherValue
dorthu@travel-dev:~/source/openapi3$ ipython
Python 3.10.7 (main, Mar 10 2023, 10:47:39) [GCC 12.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from openapi3 import OpenAPI
In [2]: from yaml import safe_load
In [3]: with open("example.yaml") as f:
...: spec = OpenAPI(safe_load(f.read()))
...:
In [4]: spec.components.schemas['User'].properties['userId'].extensions['custom-tag-1']
Out[4]: 'someValue'
In [5]: spec.components.schemas['User'].properties['userId'].extensions['custom-tag-2']
Out[5]: 'someOtherValue'