diff --git a/20200713191259-slaa.org b/20200713191259-slaa.org index 4b9327c..1b85ae6 100644 --- a/20200713191259-slaa.org +++ b/20200713191259-slaa.org @@ -136,3 +136,4 @@ could comprehend what it means to have dignity of self. * Resources - [[https://slaafws.org/][Fellowship-Wide Services]] +- [[https://slaadvi.org/][S.L.A.A. Greater Delaware Valley Intergroup]] diff --git a/20210225144943-openapi_core_exceptions.org b/20210225144943-openapi_core_exceptions.org new file mode 100644 index 0000000..75a9477 --- /dev/null +++ b/20210225144943-openapi_core_exceptions.org @@ -0,0 +1,24 @@ +#+title: OpenAPI Core Exceptions + +Diagram of the exceptions in the [[file:20210226114112-openapi_core.org][OpenAPI Core]] library. + +#+begin_src dot :file openapi-core-exceptions.svg + digraph { + # openapi-core/openapi_core/casting/schemas/exceptions.py + OpenAPIError -> CastError + # openapi-core/openapi_core/deserializing/exceptions.py + OpenAPIError -> DeserializeError + # openapi-core/openapi_core/deserializing/parameters/exceptions.py + DeserializeError -> EmptyParameterValue + # openapi-core/openapi_core/unmarshalling/schemas/exceptions.py + OpenAPIError -> UnmarshalError + UnmarshalError -> ValidateError + UnmarshalError -> UnmarshallerError + ValidateError -> InvalidSchemaValue + UnmarshallerError -> InvalidSchemaFormatValue + UnmarshallerError -> FormatterNotFoundError + } +#+end_src + +#+RESULTS: +[[file:openapi-core-exceptions.svg]] diff --git a/20210226111129-validating_data_against_a_schema_object.org b/20210226111129-validating_data_against_a_schema_object.org new file mode 100644 index 0000000..35c905b --- /dev/null +++ b/20210226111129-validating_data_against_a_schema_object.org @@ -0,0 +1,74 @@ +#+title: Validating data against a schema object +#+roam_tags: openapi-core + +How to use [[file:20210226114112-openapi_core.org][OpenAPI Core]] + +#+begin_src python :results code :exports both + from openapi_core import create_spec + from openapi_core.unmarshalling.schemas.factories import SchemaUnmarshallersFactory + + spec = create_spec({ + "openapi": "3.0.0", + "info": { + "title": "Test API", + "version": "1.0.0", + }, + "components": { + "schemas": { + "resource": { + "type": "object", + "properties": {"name": {"type": "string"}}, + "required": ["name"], + }, + }, + "securitySchemes": { + "basicAuth": { + "type": "http", + "scheme": "bearer", + } + }, + }, + "security": [{"basicAuth": []}], + "paths": { + "/resource": { + "post": { + "requestBody": { + "required": True, + "content": { + "application/vnd.example.resource+json": { + "schema": {"$ref": "#/components/schemas/resource"}, + } + }, + }, + "responses": { + "200": { + "description": "Success", + "content": { + "application/vnd.example.resource+json": { + "schema": {"$ref": "#/components/schemas/resource"}, + } + }, + } + }, + } + } + }, + }) + + data = { + "badname": "Name", + } + + factory = SchemaUnmarshallersFactory() + unmarshaller = factory.create(spec.components.schemas.get("resource")) + + try: + return unmarshaller(data) + except Exception as e: + return str(e) +#+end_src + +#+RESULTS: +#+begin_src python +Value {'badname': 'Name'} not valid for schema of type SchemaType.OBJECT: (,) +#+end_src diff --git a/20210226114112-openapi_core.org b/20210226114112-openapi_core.org new file mode 100644 index 0000000..674232b --- /dev/null +++ b/20210226114112-openapi_core.org @@ -0,0 +1,4 @@ +#+title: OpenAPI Core + +A Python library for validating requests and responses against OpenAPI 3 +specifications. diff --git a/index.org b/index.org index 32e5eb6..0b17ddb 100644 --- a/index.org +++ b/index.org @@ -8,3 +8,4 @@ A collection of entry points to various interests and ideas. - [[file:20210219114633-digital_audio_processing.org][Digital Audio Processing]] - [[file:20200716214603-taking_better_notes.org][Taking better notes]] - [[file:20200721011317-the_phoenix_inquisitor.org][The Phoenix Inquisitor]] +- [[file:20210226114112-openapi_core.org][OpenAPI Core]]