Skip to content

Commit 84df56b

Browse files
committed
fix: add schema generator
1 parent ed5b8e0 commit 84df56b

File tree

105 files changed

+17528
-1196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+17528
-1196
lines changed

.gitignore

+27-4
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,42 @@
77
*.dll
88
*.so
99
*.dylib
10+
**/obj
11+
12+
**/.autogened
13+
.vs
14+
.vscode
15+
**/*.zip
1016

1117
# Test binary, built with `go test -c`
1218
*.test
1319

20+
# dotnet
21+
TestResults
22+
1423
# Output of the go coverage tool, specifically when used with LiteIDE
1524
*.out
1625

1726
# Dependency directories (remove the comment below to include it)
1827
vendor/
28+
dist/
29+
bin/
1930

20-
# Go workspace file
21-
go.work
22-
**/.ignore*
23-
.coverage
31+
local/
32+
**/.coverage
2433

2534
.DS_Store
35+
36+
# Node_modules
37+
**/node_modules
38+
39+
# Terraform
40+
**/terraform.tfvars
41+
**/.terraform
42+
**/terraform.tfstate.backup
43+
**/terraform.tfstate
44+
45+
# results
46+
.combined-raw.json
47+
.gendoc
48+
.ignore

Makefile

-52
This file was deleted.

README.md

+59-25
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,85 @@
11
# async-api-generator
22

3-
This tool parses source code - of any type and looks for tags / annotations to extract.
3+
This tool parses source code - of any type and looks for tags / annotations to extract expressions and assign them to GenDoc statements.
4+
5+
The goal of this utility is twofold:
6+
7+
- produce an interim state from a single service/application and convert to [AsyncAPI](https://www.asyncapi.com) spec
8+
9+
- produce a holistic view across all application/service emitted AsyncAPI documents to provide a wider view
10+
11+
The driver is to remove manual creation/maintanence of AsyncAPI Specs and have them be generated from code - which would also ~force~ encourage documentation of code to live with code and hence making it easier to modify relevant code and accompanying documentation.
412

513
_Limitations by design:_
614

7-
- requires a closing tag as the source can be of any type and formatting is not guaranteed. Essentially using things like `{` or cursor column indicator, wouldn't be reliable enough
15+
- requires a closing tag as the source can be of any type and formatting is not guaranteed. Essentially using things like `{` or cursor column indicator, wouldn't be reliable enough as not everyone may have uniform formatting.
16+
17+
_High level flow_
18+
![hl-flow diagram](./docs/hl-flow.png)
19+
20+
Living documentation [link](https://lucid.app/lucidspark/4d09749b-ad86-456b-a5ad-2f9e70a2b546/edit?viewport_loc=-1181%2C-734%2C4250%2C2266%2C0_0&invitationId=inv_bc6af9c8-3b41-4b00-b535-255d109f0afb)
821

922
## Flow Overview
1023

11-
walk the directory and create a list of all source files - excluding specified such as bin, dist, vendor, node_modules, etc...
24+
Walk the directory and create a list of all source files - excluding specified such as bin, dist, vendor, node_modules, etc...
1225

1326
running each file as a source through a lexer i.e. performing a lexical analysis, where we identify tokens and build an AST (Abstract Syntax Tree)
1427

15-
> each file can be done in a separate go routine as there is no intrinsic relationship between them at this stage
28+
> each file can be done in a separate go routine as there is no intrinsic relationship between them at this stage.
1629
17-
### Lexer
30+
Here is a more [detailed internal overview](./docs/internals.md)
1831

19-
TOKENs are kept to the following types - `token.TokenType` - not listed as the list is likely to change/grow.
32+
### Usage
2033

21-
Special consideration will need to be given to files that are not able to contain comments or anything outside of their existing syntax - e.g. .json most commonly containing schemas.
34+
See [usage](./docs/usage.md) for more details.
2235

23-
> these cases a convention will need to be followed where by the name of the message that it is describing must be in the name of the file.
36+
## AsyncAPI standard
2437

25-
### Parser
38+
[AsyncAPI at Next](./docs/asyncapi.md)
2639

27-
Not using an existing parser generator like CGF, BNF, or EBNF is on purposes as the input source will only ever really be composed of parts we care about i.e. `gendoc` markers their beginning and end and what they enclose within them as text.
40+
## Local development
2841

29-
We'll use the overly simplified Pratt Parser (top down method) as we'll have no need to for expression parsing onyl statement node creation with the associated/helper attributes.
42+
To run the full flow locally you can use the local:// storage protocol.
3043

31-
## AsyncAPI standard
44+
See usage [local example](./docs/usage.md#LocalExample) for an example of how to work with and experiment locally with the outputs.
3245

33-
The current [AsyncAPI standard spec](https://www.asyncapi.com/docs/reference/specification/v2.6.0) is at version `2.6.0`.
46+
## Components
3447

35-
The tool will deal with all the relevant sections to be able to build an AsyncAPI spec file from within a single repo.
48+
For a full view of required components including publishing to the existing event catalog, the AsyncAPI document generator consists of the following auxilary components.
3649

37-
The asyncAPI is built from the `Application` - i.e. service down, each service will have a toplevel description - `info` key, which will in turn include
50+
### Schema Generation from DotNet
3851

39-
### Important Properties
40-
41-
- `id` name of the service. Will default to parent folder name - unless overridden
42-
- format: `urn:$business_domain:$bounded_context_domain:$service_name` => `urn:whds:packing:whds.packing.app`
43-
- `application`
44-
this is info about the service/application including descriptions and titles
45-
- `channels` outlines the topics/subscriptions or queues the application produces or is subscribed to.
46-
- `topic/queue/subscription`
47-
will each contain a message summary description, schema, any traits - i.e. re-useable components - such as the envelop for common parameters
52+
Download SchemaGenerator for relevant architecture and run binary with required flags, see [here](./src/dotnet/Schema.Generator/README.md) for details.
4853

4954
### EventCatalog binding
5055

51-
The translation of AsyncAPI into an EventCatalog set up. Whilst there are fairly standard mappings between the 2 processes - there are some nuances and requirements.
56+
The translation of AsyncAPI into an EventCatalog set up. Whilst there are fairly standard mappings between the 2 processes - there are some nuances and requirements, but this [plugin](./src/ts/eventcatalog-plugin-doc-generator-azblob/README.md) will be used to generate the eventcatalog compliant output.
57+
58+
See on [NPM](TODO) and how to use it insid the existing eventcatalog app.
59+
60+
### Infrastructure
61+
62+
For remote publishing of generated interim and processed AsyncAPI documents a centralised bucket is required. The [definition](./terraform/examples/full/full.tf) and description of the flow can be found [here](./terraform/README.md).
63+
64+
## Evolution
65+
66+
Once satisfactory outcomes are achieved, the next step could be to generate clients directly. There are various options out there:
67+
68+
- [Official AsyncAPI Generators](https://github.com/asyncapi/generator)
69+
- Write own?
70+
- There will be use cases when a single repo contains an entire definition needed for the doc generation to work, i.e. it will contain all the infrastructure/notes/models/schemas examples. IN this case a wrap around command can be exposed to combine the interim output generation with reading it and generating the full AsyncAPI.
71+
- E.g. the backstage.io required CRD can embed an entire AsyncAPI doc inside its spec payload.
72+
73+
### Still needing attention
74+
75+
- the merging of content within the same level could use a bit of work, namely not overwriting content defined in multiple places and perform a non-destructive merge where possible.
76+
- `servers` section inside the main `service` definition
77+
- `wip`: naming of operations and category types to allow for a more generic labelling types. e.g. categoryType of pubOperation is actually an eventcatalog subscriber.
78+
79+
#### schemagenerator
80+
81+
Dotnet CLI to inspect and generate schemas and JSON payload samples.
82+
83+
TODO:
84+
- Generated Samples when includes datetime
85+
- ENUMs in the generated SCHEMAs can sometimes come up as empty `""`

go.mod

-3
This file was deleted.

go.work

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// added go.work ensure existing repo structure can be followed
2+
// this is essentially the equivalent of a .sln file in the root
3+
go 1.22
4+
5+
use ./src/go/async-api-gen-doc

go.work.sum

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 h1:rtAn27wIbmOGUs7RIbVgPEjb31ehTVniDwPGXyMxm5U=
2+
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
4+
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
5+
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
6+
github.com/dnitsch/simplelog v1.7.1 h1:5RVORNECiXQDLLEvmOnUMoPSwNWyZAGOs6p8xrRBlto=
7+
github.com/dnitsch/simplelog v1.7.1/go.mod h1:+6a7bFEUXelqYb9kxJ1rv+bpmlO6nKh2aKkOVv59wlo=
8+
github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
9+
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
10+
github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ=
11+
github.com/montanaflynn/stats v0.7.0 h1:r3y12KyNxj/Sb/iOE46ws+3mS1+MZca1wlHQFPsY/JU=
12+
github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
13+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
14+
github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
15+
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
16+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
17+
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
18+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19+
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
20+
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
21+
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
22+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
23+
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
24+
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
25+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
26+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
27+
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
28+
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
29+
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
30+
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
31+
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
32+
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
33+
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
34+
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
35+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=

internal/cmdutil/cmdutil.go

-33
This file was deleted.

internal/cmdutil/cmdutil_test.go

-47
This file was deleted.

license-report-config.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"output": "markdown",
3+
"fields": [
4+
"name",
5+
"licensePeriod",
6+
"material",
7+
"licenseType",
8+
"link",
9+
"comment",
10+
"installedVersion",
11+
"author"
12+
],
13+
"tablemarkOptions": {
14+
"columns": [
15+
{ "name": "name", "align": "center" },
16+
{ "name": "licensePeriod", "align": "center" },
17+
{ "name": "material", "align": "center" },
18+
{ "name": "licenseType", "align": "center" },
19+
{ "name": "link", "align": "center" },
20+
{ "name": "comment", "align": "center" },
21+
{ "name": "installedVersion", "align": "center" },
22+
{ "name": "author", "align": "center" }
23+
]
24+
}
25+
}

output-report.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const libReport = require('istanbul-lib-report')
2+
const { createCoverageMap, createFileCoverage } = require('istanbul-lib-coverage')
3+
const reports = require('istanbul-reports')
4+
const mergedRaw = require('./.combined-raw.json')
5+
6+
let map = createCoverageMap()
7+
8+
for (const fk of Object.keys(mergedRaw)) {
9+
const reportKey = fk // .includes("/libs/") ? fk.split("/libs/")[1] : fk.split("/tasks/")[1]
10+
const jsonCoverageMap = createCoverageMap({[reportKey]: createFileCoverage(mergedRaw[fk])});
11+
map.merge(jsonCoverageMap);
12+
}
13+
14+
// create a context for report generation
15+
const context = libReport.createContext({
16+
dir: './.coverage',
17+
defaultSummarizer: "nested",
18+
coverageMap: map, //.files().forEach((f) => )
19+
// this is the map which we generated in above snippet
20+
})
21+
22+
// create an instance of the relevant report class, passing the
23+
// report name e.g. json/html/html-spa/text
24+
const reportHtml = reports.create('html')
25+
26+
const reportJunit = reports.create('cobertura')
27+
// call execute to synchronously create and write the report to disk
28+
reportHtml.execute(context)
29+
30+
reportJunit.execute(context)

0 commit comments

Comments
 (0)