Skip to content

Commit

Permalink
[typescript-fetch] Allow multiline documentation (OpenAPITools#6088)
Browse files Browse the repository at this point in the history
Add a lambda that formats the documentation correctly even if it
contains newlines. The generated docs with typedoc looks a lot better
and also renders Markdown correctly.

Also remove the "no description" fallback for APIs because we don't have
it anywhere else, other generators don't generate a default fallback and
I'd rather have no documentation than a "no description" string.
  • Loading branch information
haraldF authored and MikailBag committed May 31, 2020
1 parent 6ee55a3 commit 9489ee7
Show file tree
Hide file tree
Showing 26 changed files with 43 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

package org.openapitools.codegen.languages;

import com.google.common.collect.ImmutableMap;
import com.samskivert.mustache.Mustache;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.features.DocumentationFeature;
import org.openapitools.codegen.templating.mustache.IndentedLambda;
import org.openapitools.codegen.utils.ModelUtils;

import java.io.File;
Expand Down Expand Up @@ -134,6 +137,14 @@ public void processOpts() {
}
}

@Override
protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {
ImmutableMap.Builder<String, Mustache.Lambda> lambdas = super.addMustacheLambdas();
lambdas.put("indented_star_1", new IndentedLambda(1, " ", "* "));
lambdas.put("indented_star_4", new IndentedLambda(5, " ", "* "));
return lambdas;
}

@Override
public String getTypeDeclaration(Schema p) {
if (ModelUtils.isFileSchema(p)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterIn
{{#withInterfaces}}
{{#operations}}
/**
* {{classname}} - interface{{#description}}
* {{&description}}{{/description}}
* {{classname}} - interface
* {{#lambda.indented_1}}{{{unescapedDescription}}}{{/lambda.indented_1}}
* @export
* @interface {{classname}}Interface
*/
Expand Down Expand Up @@ -71,7 +71,7 @@ export interface {{classname}}Interface {
{{/withInterfaces}}
{{#operations}}
/**
* {{#description}}{{{description}}}{{/description}}{{^description}}no description{{/description}}
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
*/
{{#withInterfaces}}
export class {{classname}} extends runtime.BaseAPI implements {{classname}}Interface {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* {{{description}}}
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
* @export
* @enum {string}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {

{{/discriminator}}
/**
* {{{description}}}
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
* @export
* @interface {{classname}}
*/
Expand All @@ -29,7 +29,7 @@ export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
{{/additionalPropertiesType}}
{{#vars}}
/**
* {{{description}}}
* {{#lambda.indented_star_4}}{{{unescapedDescription}}}{{/lambda.indented_star_4}}
* @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%>
* @memberof {{classname}}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {

{{/hasImports}}
/**
* @type {{classname}}{{#description}}
* {{{description}}}{{/description}}
* @type {{classname}}
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
* @export
*/
export type {{classname}} = {{#discriminator}}{{#mappedModels}}{ {{discriminator.propertyName}}: '{{mappingName}}' } & {{modelName}}{{^-last}} | {{/-last}}{{/mappedModels}}{{/discriminator}}{{^discriminator}}{{#oneOf}}{{{.}}}{{^-last}} | {{/-last}}{{/oneOf}}{{/discriminator}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface UploadFileRequest {
}

/**
* no description
*
*/
export class PetApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface PlaceOrderRequest {
}

/**
* no description
*
*/
export class StoreApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface UpdateUserRequest {
}

/**
* no description
*
*/
export class UserApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface UploadFileRequest {
}

/**
* no description
*
*/
export class PetApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface PlaceOrderRequest {
}

/**
* no description
*
*/
export class StoreApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface UpdateUserRequest {
}

/**
* no description
*
*/
export class UserApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface UploadFileRequest {
}

/**
* no description
*
*/
export class PetApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface PlaceOrderRequest {
}

/**
* no description
*
*/
export class StoreApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface UpdateUserRequest {
}

/**
* no description
*
*/
export class UserApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface PetApiUploadFileRequest {
}

/**
* no description
*
*/
export class PetApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface StoreApiPlaceOrderRequest {
}

/**
* no description
*
*/
export class StoreApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface UserApiUpdateUserRequest {
}

/**
* no description
*
*/
export class UserApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface UploadFileRequest {
}

/**
* no description
*
*/
export class PetApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface PlaceOrderRequest {
}

/**
* no description
*
*/
export class StoreApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface UpdateUserRequest {
}

/**
* no description
*
*/
export class UserApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface UploadFileRequest {

/**
* PetApi - interface
*
* @export
* @interface PetApiInterface
*/
Expand Down Expand Up @@ -197,7 +198,7 @@ export interface PetApiInterface {
}

/**
* no description
*
*/
export class PetApi extends runtime.BaseAPI implements PetApiInterface {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface PlaceOrderRequest {

/**
* StoreApi - interface
*
* @export
* @interface StoreApiInterface
*/
Expand Down Expand Up @@ -103,7 +104,7 @@ export interface StoreApiInterface {
}

/**
* no description
*
*/
export class StoreApi extends runtime.BaseAPI implements StoreApiInterface {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface UpdateUserRequest {

/**
* UserApi - interface
*
* @export
* @interface UserApiInterface
*/
Expand Down Expand Up @@ -183,7 +184,7 @@ export interface UserApiInterface {
}

/**
* no description
*
*/
export class UserApi extends runtime.BaseAPI implements UserApiInterface {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface UploadFileRequest {
}

/**
* no description
*
*/
export class PetApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface PlaceOrderRequest {
}

/**
* no description
*
*/
export class StoreApi extends runtime.BaseAPI {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface UpdateUserRequest {
}

/**
* no description
*
*/
export class UserApi extends runtime.BaseAPI {

Expand Down

0 comments on commit 9489ee7

Please sign in to comment.