Skip to content

[csharp][java] Generating api docs without model docs leads to broken doc links #5732

Description

@jimschubert
Description

DefaultGenerator allows for generating api docs without model docs, and model docs without api docs. Templates for csharp, java, and possibly others make the assumption these are always generated together. I discovered this while creating a new generator and looking at how doc templates are done in existing generators.

Swagger-codegen version

All versions supporting api/model docs.

Swagger declaration file content or url

N/A

Command line used for generation

N/A

Steps to reproduce
# NOTE: You have to delete existing docs, otherwise old model docs still "work"
\rm -rf samples/client/petstore/csharp/SwaggerClient/docs
JAVA_OPTS="$JAVA_OPTS -DmodelDocs=false" ./bin/csharp-petstore.sh
git status

You'll notice after running git status that all model documentation is marked for deletion.

In C#, the README will reference files that no longer exist:

menubar_and_readme_md_-_swaggerclient_and_defaultgenerator_java_-_swagger-codegen_-____projects_swagger-codegen_

In addition to README, api docs point back to the model documentation section from the above screenshot:

[[Back to Model list]](../README.md#documentation-for-models)

As well as linking to missing parameter models:

### Parameters

Name | Type | Description  | Notes
------------- | ------------- | ------------- | -------------
 **body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | 

and return types:

### Return type

[**ApiResponse**](ApiResponse.md)
Related issues

N/A

Suggest a Fix

As part of #5731, I've added the global additionalProperties: generateApiDocs and generateModelDocs. In that PR, I've used these to conditionally modify parameters, return types, and README sections to avoid generating broken links.

For example (from linked Kotlin client PR):


  ### Return type
  
  {{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}{{#generateModelDocs}}[**{{returnType}}**]({{returnBaseType}}.md){{/generateModelDocs}}{{^generateModelDocs}}**{{returnType}}**{{/generateModelDocs}}{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}null (empty response body){{/returnType}}
  

This should be an easy modification after PR #5731 is merged and the template properties are available. We'll probably want to list affected generator documentation templates as a TODO in this description.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions