Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read custom tags #95

Open
VedavyasBhatJupiter opened this issue Apr 6, 2023 · 1 comment
Open

Read custom tags #95

VedavyasBhatJupiter opened this issue Apr 6, 2023 · 1 comment

Comments

@VedavyasBhatJupiter
Copy link

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
@Dorthu
Copy link
Owner

Dorthu commented Apr 7, 2023

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants