[TypescriptAngular] gets package npm version from API specification (#2019)

This commit is contained in:
Pablo Lázaro 2019-02-07 08:53:01 +01:00 committed by William Cheng
parent aa15882e2b
commit aa24f07433
2 changed files with 69 additions and 0 deletions

View File

@ -206,6 +206,8 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
if (additionalProperties.containsKey(NPM_VERSION)) {
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
} else if (this.getVersionFromApi() != null) {
this.setNpmVersion(this.getVersionFromApi());
}
if (additionalProperties.containsKey(SNAPSHOT)
@ -650,4 +652,17 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
}
return name;
}
/**
* Returns version from OpenAPI info.
*
* @return
*/
private String getVersionFromApi() {
if (this.openAPI != null && this.openAPI.getInfo() != null) {
return this.openAPI.getInfo().getVersion();
} else {
return null;
}
}
}

View File

@ -0,0 +1,54 @@
package org.openapitools.codegen.typescript.typescriptangular;
import io.swagger.v3.oas.models.OpenAPI;
import org.junit.Assert;
import org.junit.Test;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
public class TypescriptAngularApiVersionTest {
@Test
public void testWithApiVersion() {
final TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
codegen.additionalProperties().put("npmName", "just-a-test");
OpenAPI api = TestUtils.createOpenAPI();
codegen.setOpenAPI(api);
codegen.processOpts();
Assert.assertEquals(codegen.getNpmVersion(), "1.0.7");
}
@Test
public void testWithoutNpmName() {
final TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
OpenAPI api = TestUtils.createOpenAPI();
codegen.setOpenAPI(api);
codegen.processOpts();
Assert.assertEquals(codegen.getNpmVersion(), "1.0.0");
}
@Test
public void testWithNpmVersion() {
final TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();
codegen.additionalProperties().put("npmName", "just-a-test");
codegen.additionalProperties().put("npmVersion", "2.0.0");
OpenAPI api = TestUtils.createOpenAPI();
codegen.setOpenAPI(api);
codegen.processOpts();
Assert.assertEquals(codegen.getNpmVersion(), "2.0.0");
}
}