Overview
Neuro.Content.OpenApi is the typed OpenAPI document model used by Neuron packages. It gives services a C# representation of an OpenAPI 3.0.x document, factory methods for reading a parsed JSON dictionary, and ToDictionary() methods for serializing the model back to JSON.
It also includes OpenApiJsonCodec, a Waher content codec that lets Neuron services return an OpenApiDocument as normal application/json.
The repository and project URL are named
Neuron.Content.OpenApi, while the NuGet package, assembly, and namespace are Neuro.Content.OpenApi.Install the package
netstandard2.1 and depends on Waher.IoTGateway and Waher.Runtime.Inventory.
What it owns
Use this package when you need to:- Build an OpenAPI document in code
- Parse an existing OpenAPI JSON document into a typed model
- Mutate paths, operations, schemas, components, responses, or security definitions
- Return an OpenAPI document through Waher content handling
- Work with the document produced by
Neuro.Networking.HttpRouter.OpenApi
Neuro.Networking.HttpRouter.OpenApi.
Relationship to the HTTP router
The HTTP router generator walks aControllerEndpointRouter route tree and returns an OpenApiDocument from this package.
Neuro.Content.OpenApi.Model types before returning the document.
Response.Return(Document) can serialize the document because OpenApiJsonCodec implements Waher content encoding for OpenApiDocument.
Document model
The root type isOpenApiDocument.
OpenApiDocument.OpenApiVersion defaults to 3.0.3. The codec requires Info when encoding a document.
Add paths and operations
Paths are represented byOpenApiPathItem. Each path item can hold HTTP method operations such as Get, Post, Put, Patch, and Delete.
Document.AddPath(...) when adding paths manually. It validates that the path starts with /.
Parse an OpenAPI document
FromDictionary(...) builds the typed model from a dictionary such as the object returned by Waher.Content.JSON.Parse(...).
openapi field when decoded through OpenApiJsonCodec.
Serialize a document
Every model type exposesToDictionary() for JSON-compatible output.
OpenApiJsonCodec performs this conversion for OpenApiDocument and emits application/json.
Schema model
Schemas are polymorphic.OpenApiSchema.FromDictionary(...) chooses a concrete schema type based on $ref, oneOf, allOf, type, or object properties.
Reusable schemas live under
OpenApiComponents.Schemas.
Core types
Codec behavior
OpenApiJsonCodec implements both IContentEncoder and IContentDecoder from Waher.Content.
- Encodes
OpenApiDocumenttoapplication/json - Decodes
application/jsonintoOpenApiDocumentwhen the root object containsopenapi - Uses
OpenApiDocument.ToDictionary()when writing JSON - Uses
OpenApiDocument.FromDictionary(...)when reading JSON - Is discoverable through
Waher.Runtime.Inventory
Practical rules
- Set
Info.TitleandInfo.Versionbefore returning a document. - Keep shared schemas, parameters, responses, and security schemes in
OpenApiComponents. - Prefer
OpenApiRefSchemawhen reusing component schemas across multiple operations. - Treat
FromDictionary(...)andToDictionary()as the boundary between JSON and typed C# code. - Use
Neuro.Networking.HttpRouter.OpenApiwhen you want controller routes to generate the document for you.