tom_core_openapi 0.1.0
tom_core_openapi: ^0.1.0 copied to clipboard
OpenAPI 3.1 for Tom servers — generates the document from the endpoint annotations and reflected DTOs, validates it, and generates a typed Dart client from it. A tom_build_base command-line tool.
Changelog #
Unreleased #
Added #
apiKeyAuth(TomOpenApiDocumentGenerator.apiKeyScheme): a security scheme oftype: apiKeyin theX-API-Keyheader — a service account's key — defined besidebearerAuth. Every authenticated operation'ssecuritynames both as alternative requirements,[{bearerAuth: []}, {apiKeyAuth: []}].- A
429response on every operation, with the framework error envelope and aRetry-Afterheader (integer,minimum: 1), because rate limits are deployment configuration any operation may be under. apiKeyon the generated Dart client: a constructor parameter and a mutable field, sent asX-API-Keyto secured operations when nobearerTokenis set; public operations send neither.
0.1.0 #
Added #
TomOpenApiDocumentGeneratorandTomOpenApiInfo: an OpenAPI 3.1.0 document of every endpoint a server mounts, read off the endpoint annotations through the router's own scan (registerFrameworkApis,scanClasses,getClassMethodMetadata), framework endpoints included and WebSocket endpoints left out.excludePathPrefixesdrops part of the surface; paths, tags, methods and schemas are sorted, andgenerateJsonwrites the stable on-disk form. Operation ids, parameters, request bodies, responses (404and the framework error envelope on every operation) and security (bearerAuth,security: []for public endpoints,x-tom-accessfor role rules) follow the rules indoc/openapi_generation.md.TomOpenApiSchemaBuilderandTomOpenApiDartType: schemas that follow the kernel serializer — plain DTO fields,TomClassobservables, the@!@wire form of an observableTomDateTime(TomOpenApiSchemaBuilder.tomDateTime),x-tom-opaquefor self-rendering types, JSON Schema 2020-12 nullability. Declaration types are read from the reflectedType.TomOpenApiException, keyedopenapi.document.duplicate_route,openapi.document.inconsistent,openapi.schema.type_not_reflectedandopenapi.schema.ambiguous_type.TomOpenApiDocumentCheck.problems: uniqueoperationIds, resolvable$refs, path variables matched to path parameters, no duplicate parameter.TomOpenApiValidatorandTomOpenApiValidation: the OpenAPI 3.1 meta-schema (2022-10-07 schema-base variant, vendored from spec.openapis.org under Apache-2.0) through Python'sjsonschema(lib/src/validation/validate_openapi.py), plus the cross-reference check. An unmeasured validation is never valid.TOM_PYTHONoverrides the interpreter; Windows usespy -3.TomOpenApiDartClientGenerator: a typed Dart client depending onpackage:httponly — a class per object schema, a method per operation named by itsoperationId,<Client>ExceptionwithstatusCode,bodyanderrorKey, the bearer token sent to secured operations only, and the@!@TomDateTimeconvention decoded and encoded.- The
openapitool ontom_build_base(runTomOpenApiTool,createTomOpenApiExecutors,tomOpenApiTool)::documentfrom a server'stool/openapi.dart,:dart-clientand:validatefromdart run tom_core_openapi:openapi;--checkon both writers.formatDartSourceformats generated code withdart format. example/tom_core_openapi_example.dart,doc/index.md,doc/openapi_generation.mdanddoc/api/api_summary_tom_core_openapi.md.