-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(type-safe-api): improve performance of markdown, plantuml and ht…
…ml-redoc docs generation (#836) Remove openapi generator for markdown and plantuml in favour of our own templates with the new codegen. Generate html redoc docs by calling `@redocly/cli` directly with `npx` rather than using the wrapper script.
- Loading branch information
Showing
20 changed files
with
332 additions
and
293 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
packages/type-safe-api/scripts/type-safe-api/custom/docs/html-redoc
This file was deleted.
Oops, something went wrong.
Empty file removed
0
packages/type-safe-api/scripts/type-safe-api/generators/docs/templates/.gitkeep
Empty file.
25 changes: 25 additions & 0 deletions
25
packages/type-safe-api/scripts/type-safe-api/generators/docs/templates/markdown/README.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
###TSAPI_WRITE_FILE### | ||
{ | ||
"id": "readme", | ||
"dir": ".", | ||
"name": "README", | ||
"ext": ".md", | ||
"overwrite": true | ||
} | ||
###/TSAPI_WRITE_FILE#### Documentation for <%- info.title %> | ||
|
||
<a name="documentation-for-api-endpoints"></a> | ||
## Documentation for API Endpoints | ||
|
||
| Class | Method | HTTP request | Description | | ||
|------------ | ------------- | ------------- | -------------| | ||
<%_ allOperations.forEach(operation => { _%> | ||
| *<%- operation.service %>Api* | [**<%- operation.name %>**](Apis/<%- operation.service %>Api.md#<%- operation.name %>) | **<%- operation.method %>** <%- operation.path %> | <%- operation.description || '' %> | | ||
<%_ }); _%> | ||
|
||
<a name="documentation-for-models"></a> | ||
## Documentation for Models | ||
|
||
<%_ models.forEach(model => { _%> | ||
- [<%- model.name %>](./Models/<%- model.name %>.md) | ||
<%_ }); _%> |
54 changes: 54 additions & 0 deletions
54
packages/type-safe-api/scripts/type-safe-api/generators/docs/templates/markdown/api.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<%_ services.forEach(service => { _%> | ||
###TSAPI_WRITE_FILE### | ||
{ | ||
"id": "service-<%- service.name %>", | ||
"dir": "Apis", | ||
"name": "<%- service.className %>", | ||
"ext": ".md", | ||
"overwrite": true | ||
} | ||
###/TSAPI_WRITE_FILE#### <%- service.className %> | ||
<%- service.description || '' %> | ||
| Method | HTTP request | Description | | ||
|------------- | ------------- | -------------| | ||
<%_ service.operations.forEach(operation => { _%> | ||
| [**<%- operation.name %>**](<%- operation.service %>Api.md#<%- operation.name %>) | **<%- operation.method %>** <%- operation.path %> | <%- operation.description || '' %> | | ||
<%_ }); _%> | ||
<%_ service.operations.forEach(operation => { _%> | ||
<a name="<%- operation.name %>"></a> | ||
# **<%- operation.name %>** | ||
<%_ const result = operation.results[0] _%> | ||
> <% if (result && result.type !== 'void') { %><%- result.javaType %> <% } %><%- operation.name %>(<% operation.parameters.forEach((param, i) => { %><%- param.prop %><% if (i < operation.parameters.length - 1) { %>, <% } %><% }); %>) | ||
<%_ if (operation.description) { _%> | ||
<%- operation.description %> | ||
<%_ } _%> | ||
### Parameters | ||
<%_ if (operation.parameters.length === 0) { _%> | ||
This endpoint does not need any parameters. | ||
<%_ } else { _%> | ||
|Name | Type | Description | Notes | | ||
|------------- | ------------- | ------------- | -------------| | ||
<%_ operation.parameters.forEach((param) => { _%> | ||
| **<%- param.prop %>** | <% if (param.isPrimitive || param.export === "array" || param.export === "dictionary") { %>**<%- param.javaType %>**<% } else { %>[**<%- param.type %>**](../Models/<%- param.type %>.md)<% } %>| <%- param.description || '' %> |<% if (!param.isRequired) { %> [optional]<% } %><% if (param.defaultValue) { %> [default to <%- param.defaultValue %>]<% } %><% if (param.enum.length > 0) { %> [enum: <% param.enum.forEach((e, i) => { %><%- e.value %><% if (i < param.enum.length - 1) { %>, <% } %><% }); %><% } %> | | ||
<%_ }); _%> | ||
<%_ } _%> | ||
### Return type | ||
<%_ if (result && result.type !== 'void') { _%> | ||
<% if (result.isPrimitive || result.export === "array" || result.export === "dictionary") { %>**<%- result.javaType %>**<% } else { %>[**<%- result.type %>**](../Models/<%- result.type %>.md)<% } %> | ||
<%_ } else { _%> | ||
null (empty response body) | ||
<%_ } _%> | ||
### HTTP request headers | ||
- **Content-Type**: <% if (operation.parametersBody && operation.parametersBody.mediaTypes && operation.parametersBody.mediaTypes.length > 0) { %><%- operation.parametersBody.mediaTypes.join(', ') %><% } else { %>Not defined<% } %> | ||
- **Accept**: <% if (result && result.mediaTypes && result.mediaTypes.length > 0) { %><%- result.mediaTypes.join(', ') %><% } else { %>Not defined<% } %> | ||
<%_ }); _%> | ||
<%_ }); _%> |
21 changes: 21 additions & 0 deletions
21
packages/type-safe-api/scripts/type-safe-api/generators/docs/templates/markdown/model.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<%_ models.forEach(model => { _%> | ||
###TSAPI_WRITE_FILE### | ||
{ | ||
"id": "model-<%- model.name %>", | ||
"dir": "Models", | ||
"name": "<%- model.name %>", | ||
"ext": ".md", | ||
"overwrite": true | ||
} | ||
###/TSAPI_WRITE_FILE#### <%- model.name %> | ||
## Properties | ||
| Name | Type | Description | Notes | | ||
|------------ | ------------- | ------------- | -------------| | ||
<%_ model.resolvedProperties.forEach(property => { _%> | ||
| **<%- property.name %>** | <% if (property.isPrimitive || property.export === "array" || property.export === "dictionary") { %>**<%- property.javaType %>**<% } else { %>[**<%- property.type %>**](<%- property.type %>.md)<% } %> | <%- property.description || '' %> | <% if (!property.isRequired) { %>[optional] <% } %><% if (property.isReadOnly) { %>[readonly] <% } %><% if (property.defaultValue) { %>[default to <%- property.defaultValue %>]<% } %> | | ||
<%_ }); _%> | ||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) | ||
<%_ }); _%> |
30 changes: 30 additions & 0 deletions
30
packages/type-safe-api/scripts/type-safe-api/generators/docs/templates/plantuml/schemas.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
###TSAPI_WRITE_FILE### | ||
{ | ||
"id": "schemas", | ||
"dir": ".", | ||
"name": "schemas", | ||
"ext": ".plantuml", | ||
"overwrite": true | ||
} | ||
###/TSAPI_WRITE_FILE###@startuml | ||
|
||
title <%- info.title %> Schemas Diagram | ||
|
||
<%_ models.forEach((model) => { _%> | ||
entity <%- model.name %> { | ||
<%_ model.resolvedProperties.forEach(property => { _%> | ||
<% if (property.isRequired) { %>* <% } %><%- property.name %>: <%- property.javaType %> | ||
<%_ }); _%> | ||
} | ||
<%_ }); _%> | ||
|
||
<%_ models.forEach((model) => { _%> | ||
<%_ model.resolvedProperties.forEach((property) => { _%> | ||
<%_ if (!property.isPrimitive) { _%> | ||
<%- model.name %> -- <% if (["array", "dictionary"].includes(property.export)) { %>"0..*" <% } %><%- property.type %> : <%- property.name %> | ||
<%_ } _%> | ||
<%_ }); _%> | ||
<%_ }); _%> | ||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,6 @@ import { Project, ProjectOptions, Task } from "projen"; | |
import { GeneratedHtmlRedocDocumentationOptions } from "../../types"; | ||
import { OpenApiToolsJsonFile } from "../components/open-api-tools-json-file"; | ||
import { TypeSafeApiCommandEnvironment } from "../components/type-safe-api-command-environment"; | ||
import { | ||
buildTypeSafeApiExecCommand, | ||
TypeSafeApiScript, | ||
} from "../components/utils"; | ||
|
||
export interface GeneratedHtmlRedocDocumentationProjectOptions | ||
extends ProjectOptions, | ||
|
@@ -32,10 +28,7 @@ export class GeneratedHtmlRedocDocumentationProject extends Project { | |
|
||
this.generateTask = this.addTask("generate"); | ||
this.generateTask.exec( | ||
buildTypeSafeApiExecCommand( | ||
TypeSafeApiScript.GENERATE_HTML_REDOC_DOCS, | ||
`--spec-path ${options.specPath} --output-path .` | ||
) | ||
`npx --yes @redocly/[email protected] build-docs "${options.specPath}" --output ./index.html` | ||
); | ||
this.compileTask.spawn(this.generateTask); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.