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

[WIP] Add OpenAPI v3.0/v3.1 parser #826

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions chaotic-openapi/chaotic_openapi/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Any, Union, Dict
from openapi_python_client.parser.openapi import GeneratorData
from openapi_python_client.config import Config, ConfigFile, MetaType
from pathlib import Path

def parse(data_dict: Dict[str, Any], config: Config):
return GeneratorData.from_dict(data_dict, config=config)

def config():
return Config.from_sources(ConfigFile(), MetaType.NONE, Path("example.yaml"), 'utf-8', False, None)

from openapi_python_client import _get_document

conf = config()

# print(_get_document(source=conf.document_source, timeout=10))
print(parse(_get_document(source=conf.document_source, timeout=10), conf))
176 changes: 176 additions & 0 deletions chaotic-openapi/chaotic_openapi/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
openapi: 3.0.3
info:
title: Key-Value Storage API
description: An API to manage a key-value store with CRUD operations and basic authentication.
version: 1.0.0
servers:
- url: https://api.kvstore.example.com/v1
description: Production server
- url: http://localhost:3000/v1
description: Development server
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
schemas:
KeyValuePair:
type: object
properties:
key:
type: string
description: Unique key for the item
value:
type: string
description: Value associated with the key
required:
- key
- value
ErrorResponse:
type: object
properties:
error:
type: string
description: Error message
paths:
/kv:
get:
summary: Get all key-value pairs
description: Retrieve all key-value pairs in the store.
security:
- BasicAuth: []
responses:
'200':
description: A list of key-value pairs
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/KeyValuePair'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
post:
summary: Create a new key-value pair
description: Add a new key-value pair to the store.
security:
- BasicAuth: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/KeyValuePair'
responses:
'201':
description: Key-value pair created successfully
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/kv/{key}:
get:
summary: Get a key-value pair
description: Retrieve a value by its key.
security:
- BasicAuth: []
parameters:
- name: key
in: path
required: true
schema:
type: string
description: The key to retrieve
responses:
'200':
description: Key-value pair retrieved successfully
content:
application/json:
schema:
$ref: '#/components/schemas/KeyValuePair'
'404':
description: Key not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
put:
summary: Update a key-value pair
description: Update the value associated with a specific key.
security:
- BasicAuth: []
parameters:
- name: key
in: path
required: true
schema:
type: string
description: The key to update
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/KeyValuePair'
responses:
'200':
description: Key-value pair updated successfully
'404':
description: Key not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
delete:
summary: Delete a key-value pair
description: Remove a key-value pair from the store.
security:
- BasicAuth: []
parameters:
- name: key
in: path
required: true
schema:
type: string
description: The key to delete
responses:
'204':
description: Key-value pair deleted successfully
'404':
description: Key not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
security:
- BasicAuth: []
2 changes: 1 addition & 1 deletion scripts/chaotic/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Jinja2 >= 2.10
PyYAML >= 6.0.1

openapi-python-client==0.21.7