mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
[typescript-angular] fix: update basePath initialization to use template variable (#20816)
fixes #20760
This commit is contained in:
parent
ba2e50519d
commit
ce0c0dcab0
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { {{configurationClassName}} } from './configuration';
|
import { {{configurationClassName}} } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = '{{{basePath}}}';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: {{configurationClassName}};
|
public configuration: {{configurationClassName}};
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -415,4 +415,28 @@ public class TypeScriptAngularClientCodegenTest {
|
|||||||
final String fileContents = Files.readString(Paths.get(output + "/api/default.service.ts"));
|
final String fileContents = Files.readString(Paths.get(output + "/api/default.service.ts"));
|
||||||
assertThat(fileContents).containsOnlyOnce("localVarHeaders = this.configuration.addCredentialToHeaders('OAuth2', 'Authorization', localVarHeaders, 'Bearer ');");
|
assertThat(fileContents).containsOnlyOnce("localVarHeaders = this.configuration.addCredentialToHeaders('OAuth2', 'Authorization', localVarHeaders, 'Bearer ');");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBasePath() throws IOException {
|
||||||
|
// GIVEN
|
||||||
|
final String specPath = "src/test/resources/3_0/typescript-angular/issue_20760.yaml";
|
||||||
|
|
||||||
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
|
.setGeneratorName("typescript-angular")
|
||||||
|
.setInputSpec(specPath)
|
||||||
|
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||||
|
|
||||||
|
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||||
|
|
||||||
|
Generator generator = new DefaultGenerator();
|
||||||
|
generator.opts(clientOptInput).generate();
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
final String fileContents = Files.readString(Paths.get(output + "/api.base.service.ts"));
|
||||||
|
assertThat(fileContents).containsOnlyOnce("basePath = '/relative/url'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
title: OpenAPI Petstore
|
||||||
|
description: "sample spec"
|
||||||
|
license:
|
||||||
|
name: Apache-2.0
|
||||||
|
url: https://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
version: 1.0.0
|
||||||
|
servers:
|
||||||
|
- url: /relative/url
|
||||||
|
tags: []
|
||||||
|
paths: {}
|
||||||
|
components:
|
||||||
|
schemas: {}
|
||||||
|
securitySchemes: {}
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://api.example.xyz/v1';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://api.example.xyz/v1';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://localhost';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://localhost';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
@ -3,7 +3,7 @@ import { CustomHttpParameterCodec } from './encoder';
|
|||||||
import { Configuration } from './configuration';
|
import { Configuration } from './configuration';
|
||||||
|
|
||||||
export class BaseService {
|
export class BaseService {
|
||||||
protected basePath = '';
|
protected basePath = 'http://petstore.swagger.io/v2';
|
||||||
public defaultHeaders = new HttpHeaders();
|
public defaultHeaders = new HttpHeaders();
|
||||||
public configuration: Configuration;
|
public configuration: Configuration;
|
||||||
public encoder: HttpParameterCodec;
|
public encoder: HttpParameterCodec;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user