Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

v2 improves endpoint doc paths #143

Merged
merged 5 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -463,32 +463,20 @@ private void generatePathItem(List<File> files, CodegenKey pathKey, CodegenPathI
generateXs(files, operationJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.OPERATION, CodegenConstants.APIS, endpointMap, true);

// operation docs
Map<String, String> templateToSuffix = config.jsonPathDocTemplateFiles().get(CodegenConstants.JSON_PATH_LOCATION_TYPE.OPERATION);
if (templateToSuffix != null) {
for (Map.Entry<String, String> templateToSuffixEntry: templateToSuffix.entrySet()) {
String templateFile = templateToSuffixEntry.getKey();
String suffix = templateToSuffixEntry.getValue();
for (Map.Entry<String, CodegenTag> tagEntry: operation.tags.entrySet()) {
CodegenTag tag = tagEntry.getValue();
Map<String, Object> endpointInfo = new HashMap<>();
endpointInfo.put("operation", operation);
endpointInfo.put("httpMethod", httpMethod);
endpointInfo.put("path", pathKey);
endpointInfo.put("pathItem", pathItem);
endpointInfo.put("servers", servers);
endpointInfo.put("security", security);
endpointInfo.put("packageName", config.packageName());
endpointInfo.put("apiPackage", config.apiPackage());
endpointInfo.put("tag", tag);
endpointInfo.put("headerSize", "#");
endpointInfo.put("complexTypePrefix", "../../../components/schema/");
endpointInfo.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
endpointInfo.put("identifierToHeadingQty", new HashMap<>());
String outputFilename = filenameFromRoot(Arrays.asList("docs", config.apiPackage(), "tags", tag.moduleName, operation.operationId.snakeCase + suffix));
generateFile(endpointInfo, templateFile, outputFilename, files, true, CodegenConstants.APIS);
}
}
}
Map<String, Object> endpointInfo = new HashMap<>();
endpointInfo.put("operation", operation);
endpointInfo.put("httpMethod", httpMethod);
endpointInfo.put("path", pathKey);
endpointInfo.put("pathItem", pathItem);
endpointInfo.put("servers", servers);
endpointInfo.put("security", security);
endpointInfo.put("packageName", config.packageName());
endpointInfo.put("apiPackage", config.apiPackage());
endpointInfo.put("headerSize", "#");
endpointInfo.put("complexTypePrefix", "../../components/schema/");
endpointInfo.put("identifierPieces", Collections.unmodifiableList(new ArrayList<>()));
endpointInfo.put("identifierToHeadingQty", new HashMap<>());
generateXDocs(files, operationJsonPath, CodegenConstants.JSON_PATH_LOCATION_TYPE.OPERATION, CodegenConstants.APIS, endpointInfo, true);

// paths.some_path.security.security_requirement_0.py
if (operation.security != null) {
Expand Down Expand Up @@ -1056,7 +1044,7 @@ void generateApis(List<File> files, TreeMap<CodegenKey, CodegenPathItem> paths)
}

HashMap<CodegenTag, HashMap<CodegenKey, ArrayList<CodegenOperation>>> tagToPathToOperations = new HashMap<>();
HashMap<CodegenTag, TreeMap<CodegenKey, CodegenOperation>> tagToOperationIdToOperation = new HashMap<>();
HashMap<CodegenTag, TreeMap<CodegenKey, HashMap<CodegenKey, CodegenOperation>>> tagToOperationIdToPathToOperation = new HashMap<>();
Map<String, String> apiPathTemplates = config.jsonPathTemplateFiles().get(CodegenConstants.JSON_PATH_LOCATION_TYPE.API_PATH);
for(Map.Entry<CodegenKey, CodegenPathItem> entry: paths.entrySet()) {
CodegenKey path = entry.getKey();
Expand Down Expand Up @@ -1085,16 +1073,18 @@ void generateApis(List<File> files, TreeMap<CodegenKey, CodegenPathItem> paths)
}
if (!tagToPathToOperations.containsKey(tag)) {
tagToPathToOperations.put(tag, new HashMap<>());
tagToOperationIdToOperation.put(tag, new TreeMap<>());
tagToOperationIdToPathToOperation.put(tag, new TreeMap<>());
}
HashMap<CodegenKey, ArrayList<CodegenOperation>> pathToOperations = tagToPathToOperations.get(tag);
if (!pathToOperations.containsKey(path)) {
pathToOperations.put(path, new ArrayList<>());
}
pathToOperations.get(path).add(op);
TreeMap<CodegenKey, CodegenOperation> operationIdToOperation = tagToOperationIdToOperation.get(tag);
if (!operationIdToOperation.containsKey(op.operationId)) {
operationIdToOperation.put(op.operationId, op);
TreeMap<CodegenKey, HashMap<CodegenKey, CodegenOperation>> operationIdToPathToOperation = tagToOperationIdToPathToOperation.get(tag);
if (!operationIdToPathToOperation.containsKey(op.operationId)) {
HashMap<CodegenKey, CodegenOperation> pathToOperation = new HashMap<>();
pathToOperation.put(path, op);
operationIdToPathToOperation.put(op.operationId, pathToOperation);
}
}
}
Expand Down Expand Up @@ -1152,9 +1142,9 @@ public int compare(CodegenKey e1, CodegenKey e2) {
}
}

TreeMap<CodegenKey, CodegenOperation> operationIdToOperation = new TreeMap<>(new OperationIdComparator());
operationIdToOperation.putAll(tagToOperationIdToOperation.get(tag));
apiData.put("operationIdToOperation", operationIdToOperation);
TreeMap<CodegenKey, HashMap<CodegenKey, CodegenOperation>> operationIdToPathToOperation = new TreeMap<>(new OperationIdComparator());
operationIdToPathToOperation.putAll(tagToOperationIdToPathToOperation.get(tag));
apiData.put("operationIdToPathToOperation", operationIdToPathToOperation);

if (apiTagTemplates != null) {
for (Map.Entry<String, String> apiPathEntry: apiTagTemplates.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ HTTP request | Method | Description
------------ | ------ | -------------
{{#each paths}}
{{#each operations}}
{{../@key.original}} **{{@key.original}}** | {{#each tags}}[{{className}}]({{apiDocPath}}{{moduleName}}.md).[{{operationId.snakeCase}}]({{apiDocPath}}{{moduleName}}/{{operationId.snakeCase}}.md) {{/each}} | {{#if summary}}{{summary}}{{/if}}
{{../@key.original}} **{{@key.original}}** | {{#each tags}}[{{className}}]({{apiDocPath}}{{moduleName}}.md).[{{operationId.snakeCase}}](docs/paths/{{../../@key.snakeCase}}/{{../@key.original}}.md) {{/each}} | {{#if summary}}{{summary}}{{/if}}
{{/each}}
{{/each}}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ All URIs are relative to the selected server

Method | Description
------ | -------------
{{#each operationIdToOperation}}
[**{{@key.snakeCase}}**]({{tag.moduleName}}/{{operationId.snakeCase}}.md) | {{#if summary}}{{summary}}{{/if}}
{{#each operationIdToPathToOperation}}
{{#each this}}
[**{{../@key.snakeCase}}**](../../paths/{{@key.snakeCase}}/{{jsonPathPiece.original}}.md) | {{#if summary}}{{summary}}{{/if}}
{{/each}}
{{/each}}

[[Back to top]](#top) {{> _helper_footer_links readmePath="../../../" endpointsLink=true }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{{#with operation}}
<a name="{{operationId.anchorPiece}}"></a>
{{headerSize}} **{{{operationId.snakeCase}}}**
{{packageName}}.paths.{{path.snakeCase}}.operation
{{headerSize}} Operation Method Name

| Method Name | Api Class | Notes |
| ----------- | --------- | ----- |
{{#each tags}}
| {{../operationId.snakeCase}} | [{{className}}](../../apis/tags/{{moduleName}}.md) | This api is only for tag={{{name}}} |
{{/each}}
| {{httpMethod.original}} | ApiFor{{httpMethod.camelCase}} | This api is only for this endpoint |
| {{httpMethod.original}} | {{path.camelCase}} | This api is only for path={{{path.original}}} |

{{headerSize}}# Table of Contents
- [General Info](#general-info)
Expand Down Expand Up @@ -40,9 +48,9 @@ Name | Type | Description | Notes
{{#if refInfo}}
{{#with getDeepestRef}}
{{#if required}}
[**body**](../../../components/request_bodies/{{../refInfo.refModule}}.md) | typing.Union[{{#each content}}{{#with this.schema}}[{{../../../refInfo.refClass}}.content.{{../@key.snakeCase}}.{{jsonPathPiece.snakeCase}}](../../../components/request_bodies/{{../../../refInfo.refModule}}.md#{{> components/_helper_anchor_id identifierPieces=(append identifierPieces "content" ../@key jsonPathPiece) }}){{/with}}, {{/each}}{{#each getContentSchemas}}{{> _helper_schema_python_types }}{{#unless @last}}, {{/unless}}{{/each}}] | required |
[**body**](../../components/request_bodies/{{../refInfo.refModule}}.md) | typing.Union[{{#each content}}{{#with this.schema}}[{{../../../refInfo.refClass}}.content.{{../@key.snakeCase}}.{{jsonPathPiece.snakeCase}}](../../components/request_bodies/{{../../../refInfo.refModule}}.md#{{> components/_helper_anchor_id identifierPieces=(append identifierPieces "content" ../@key jsonPathPiece) }}){{/with}}, {{/each}}{{#each getContentSchemas}}{{> _helper_schema_python_types }}{{#unless @last}}, {{/unless}}{{/each}}] | required |
{{else}}
[**body**](../../../components/request_bodies/{{../refInfo.refModule}}.md) | typing.Union[{{#each content}}{{#with this.schema}}[{{../../../refInfo.refClass}}.content.{{../@key.snakeCase}}.{{jsonPathPiece.snakeCase}}](../../../components/request_bodies/{{../../../refInfo.refModule}}.md#{{> components/_helper_anchor_id identifierPieces=(append identifierPieces "content" ../@key jsonPathPiece) }}){{/with}}, {{/each}}Unset, {{#each getContentSchemas}}{{> _helper_schema_python_types }}{{#unless @last}}, {{/unless}}{{/each}}] | optional, default is unset |
[**body**](../../components/request_bodies/{{../refInfo.refModule}}.md) | typing.Union[{{#each content}}{{#with this.schema}}[{{../../../refInfo.refClass}}.content.{{../@key.snakeCase}}.{{jsonPathPiece.snakeCase}}](../../components/request_bodies/{{../../../refInfo.refModule}}.md#{{> components/_helper_anchor_id identifierPieces=(append identifierPieces "content" ../@key jsonPathPiece) }}){{/with}}, {{/each}}Unset, {{#each getContentSchemas}}{{> _helper_schema_python_types }}{{#unless @last}}, {{/unless}}{{/each}}] | optional, default is unset |
{{/if}}
{{/with}}
{{else}}
Expand Down Expand Up @@ -114,15 +122,15 @@ n/a | api_client.ApiResponseWithoutDeserialization | When skip_deserialization i
{{#if defaultResponse}}
{{#with defaultResponse}}
{{#if refInfo}}
default | [{{refInfo.refClass}}.response_cls](../../../components/responses/{{refInfo.refModule}}.md#{{refInfo.refModule}}response_cls) | {{#with getDeepestRef}}{{description}}{{/with}}
default | [{{refInfo.refClass}}.response_cls](../../components/responses/{{refInfo.refModule}}.md#{{refInfo.refModule}}response_cls) | {{#with getDeepestRef}}{{description}}{{/with}}
{{else}}
default | [{{jsonPathPiece.camelCase}}.response_cls](#{{jsonPathPiece.anchorPiece}}-response_cls) | {{description}}
{{/if}}
{{/with}}
{{/if}}
{{#each nonDefaultResponses}}
{{#if refInfo}}
{{@key}} | [{{refInfo.refClass}}.response_cls](../../../components/responses/{{refInfo.refModule}}.md#{{refInfo.refModule}}response_cls) | {{#with getDeepestRef}}{{description}}{{/with}}
{{@key}} | [{{refInfo.refClass}}.response_cls](../../components/responses/{{refInfo.refModule}}.md#{{refInfo.refModule}}response_cls) | {{#with getDeepestRef}}{{description}}{{/with}}
{{else}}
{{@key}} | [{{jsonPathPiece.camelCase}}.response_cls](#{{jsonPathPiece.anchorPiece}}-response_cls) | {{description}}
{{/if}}
Expand All @@ -149,7 +157,7 @@ See how to do this in the code sample.
| Security Index | Security Scheme to Scope Names |
| -------------- | ------------------------------ |
{{#each security}}
| {{@key}} | {{#eq this.size 0}}no security{{else}}{{#each this}}["{{{@key}}}"](../../../components/security_schemes/{{this.refInfo.refModule}}.md) {{this.scopeNames}}<br>{{/each}}{{/eq}} |
| {{@key}} | {{#eq this.size 0}}no security{{else}}{{#each this}}["{{{@key}}}"](../../components/security_schemes/{{this.refInfo.refModule}}.md) {{this.scopeNames}}<br>{{/each}}{{/eq}} |
{{/each}}
{{/gt}}
{{else}}
Expand All @@ -169,7 +177,7 @@ See how to do this in the code sample.
| Security Index | Security Scheme to Scope Names |
| -------------- | ------------------------------ |
{{#each ../security}}
| {{@key}} | {{#eq this.size 0}}no security{{else}}{{#each this}}["{{{@key}}}"](../../../components/security_schemes/{{this.refInfo.refModule}}.md) {{this.scopeNames}}<br>{{/each}}{{/eq}} |
| {{@key}} | {{#eq this.size 0}}no security{{else}}{{#each this}}["{{{@key}}}"](../../components/security_schemes/{{this.refInfo.refModule}}.md) {{this.scopeNames}}<br>{{/each}}{{/eq}} |
{{/each}}
{{/gt}}
{{/neq}}
Expand Down Expand Up @@ -236,5 +244,9 @@ server_index | Class | Description

{{> paths/path/verb/_helper_operation_doc_example rootSecurity=../security }}

[[Back to top]](#top) [[Back to API]](../{{tag.moduleName}}.md) {{> _helper_footer_links readmePath="../../../../" endpointsLink=true}}
[[Back to top]](#top)
{{#each tags}}
[[Back to {{className}} API]](../../apis/tags/{{moduleName}}.md)
{{/each}}
{{> _helper_footer_links readmePath="../../../" endpointsLink=true}}
{{/with}}
Loading