Skip to content

exploration of other way to define cdevents (and to generate doc, sdk,...)

Notifications You must be signed in to change notification settings

davidB/sandbox_cdevents_spec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sandbox_cdevents_spec

Experiments with the cdevents spec to use an other format for specification of the events. And to generate documentation and SDK's models from the spec.

To have a relevent example, the experiment provide the 3 events ({subject}.{predicate}) (2 on the same subject):

  • artifact.published
  • artifact.deleted (to have 2 on the same subject)
  • taskrun.started
  • (optional) testcaserun.started (to have 2 on the same predicate)

Links

Features to Explore, to try

  • specification store on several files
  • code generation:
    • polymorphism for subject/predicate
    • typed scalars (aka "string" with format)
      • date-time
      • non-empty string
      • purl
      • uri-reference
    • test, validation (runtime)
    • description => api documentation
    • example(s) => api documentation
    • example(s) => tests (unit test or doctest)
  • doc: markdown
    • description
    • example(s)
  • possible customization of templates/generation
  • generate only models
  • generation of cli/server for conformance/contract test ?

Exploration's remarks

Json Schema

  • every spec ends with a schema.json
  • root as cdevent.schema.json
  • one file per type
  • use oneOf for polymorphism (but no discriminator as not supported by json schema)
  • use const for constant values (like enum with a single value)
  • try to use:
    • https://quicktype.io/
      • doesn't support json schema 2020-12 (try to switch to draft 07 & 06)
    • schematools
      • see also the OpenAPI section
      • TODO try with "discriminator" (no in the spec, but could be managed by the tool)

OpenAPI

  • use Taskfile to run actions (validate, codegen, docgen,...)
  • try to OpenAPI 3.1 (support in alpha/beta by most of the tools)
    • In 3.0,
      • models are extended on json schema draft-07
    • In 3.1,
      • models are extended on json schema 2020-12
      • allow siblings info to $ref (like override of description)
      • allow const? (part of json schema 2020-12)
  • use yaml format (less verbose than json, simpler for multi-line strings)
  • create a root api.yaml file without path, we focus on the components part (the models)
  • use of discriminator for subject/predicate
  • 2 approaches for the models:
  • OpenAPI ecosystem provide lot of codegenerator (see OpenAPI.Tools - an Open Source list of great tools for OpenAPI.), we will focus on few that allow to use our own templates (and maybe extensions)

AsyncAPI

AsyncAPI is a specification for building asynchronous APIs.

  • Difficult to debug generator (generic error message with no context eg: X is not defined)

Smithy

Smithy is designed to create API for Resources oriented API (ala REST): resources definition and associated operations / lifecycles.

Conclusion & feelings (temporary)

Caution

A breaking change with current spec, messages, SDK and existing ecosystem (could be a problem)

  • no ready to use generator (yet) with zero configuration for markdown, java, python, rust, go,...
  • generated code is only a part of the SDK or spec'documentation
  • generating samples from the spec will require a dedicated tool and template (like Schemathesis or Specmatic) based on examples or random data (like in property-based testing) based on one 1 SDK
  • having a single entrypoint in spec (json schema maybe extractred from the spec) will make validation of examples, or message simpler for non-SDK users
  • generator MUST support templates, extensions, and scalar (string) specialisation:
    • predifined templates are minimal (enough to do the job)
    • to keep the quality of current SDK
    • to keep compatibility with existing "primitive" type (eg. no "string" for id, uri, etc.)
    • to allow annotation of generated structures
  • support of multiple spec versions could become a problem (if SDK want it)
  • TODO? custom (homemade) generator with minimal logic in the "generator" and more logic in the "template" (ala schematools)
  • TODO? invest more time (contribution?) in some of the tools (openapi-generator, schematools, codegen, modelina)
  • TODO? change the spec to be more like in programming languages
  • TODO? review all events => normalize, remove duplication, add missing fields, etc.
  • TODO? complementary linter to validate rules over the spec (naming convention, use of $ref, etc.): pkl, cuelang, opa... ?
  • should SDK includes integration with CloudEvents, http frameworks, etc.?

Dev & Build

❯ mise install
❯ cd openapi
❯ task --list
task: Available tasks for this project:
* codegen:                     Generate code from the spec (all languages)
* openapi-generator-cli:       allow to call openapi-generator-cli directly by passing arguments after `--` (eg. `task openapi-generator-cli -- help`)
* schematools-cli:             allow to call schematools directly by passing arguments after `--` (eg. `task schematools-cli -- --help`)
* validate:                    Validate the spec
* codegen:go:                  Generate code from the spec (go)
* codegen:java:                Generate code from the spec (java)
* codegen:markdown:            Generate code from the spec (markdown) <-- documentation
* codegen:python:              Generate code from the spec (python)
* codegen:rust:                Generate code from the spec (rust)

About

exploration of other way to define cdevents (and to generate doc, sdk,...)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published