forked from loafle/openapi-generator-original
test(OpenAPINormalizer): nullability normalization for 3.1 specs (#19714)
* test(OpenAPINormalizer): nullability normalization for 3.1 specs * chore: samples
This commit is contained in:
parent
2d57255817
commit
d68a186c5e
@ -624,6 +624,24 @@ public class OpenAPINormalizerTest {
|
|||||||
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getType(), "array");
|
assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getType(), "array");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOpenAPINormalizerProcessingArraySchema31NullabilitySpec() {
|
||||||
|
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_1/null-types-simple.yaml");
|
||||||
|
Schema schema = openAPI.getComponents().getSchemas().get("WithNullableType");
|
||||||
|
|
||||||
|
assertNull(((Schema) schema.getProperties().get("arrayDataOrNull")).getNullable());
|
||||||
|
assertNull(((Schema) schema.getProperties().get("stringDataOrNull")).getNullable());
|
||||||
|
assertNull(((Schema) schema.getProperties().get("oneofOrNull")).getNullable());
|
||||||
|
|
||||||
|
Map<String, String> inputRules = Map.of("NORMALIZE_31SPEC", "true");
|
||||||
|
OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, inputRules);
|
||||||
|
openAPINormalizer.normalize();
|
||||||
|
|
||||||
|
assertTrue(((Schema) schema.getProperties().get("arrayDataOrNull")).getNullable());
|
||||||
|
assertTrue(((Schema) schema.getProperties().get("stringDataOrNull")).getNullable());
|
||||||
|
assertTrue(((Schema) schema.getProperties().get("oneofOrNull")).getNullable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOpenAPINormalizerSimplifyOneOfAnyOf31Spec() {
|
public void testOpenAPINormalizerSimplifyOneOfAnyOf31Spec() {
|
||||||
// to test the rule SIMPLIFY_ONEOF_ANYOF with 3.1 spec
|
// to test the rule SIMPLIFY_ONEOF_ANYOF with 3.1 spec
|
||||||
|
8
samples/client/others/typescript/builds/null-types-simple/.gitattributes
generated
vendored
Normal file
8
samples/client/others/typescript/builds/null-types-simple/.gitattributes
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
**/* linguist-generated
|
||||||
|
*.md linguist-documentation
|
||||||
|
|
||||||
|
.gitattributes text
|
||||||
|
.gitattributes export-ignore
|
||||||
|
|
||||||
|
.gitignore text
|
||||||
|
.gitignore export-ignore
|
@ -1,3 +1,4 @@
|
|||||||
|
.gitattributes
|
||||||
.gitignore
|
.gitignore
|
||||||
README.md
|
README.md
|
||||||
apis/baseapi.ts
|
apis/baseapi.ts
|
||||||
|
@ -33,6 +33,8 @@ export class HttpException extends Error {
|
|||||||
*/
|
*/
|
||||||
export type RequestBody = undefined | string | FormData | URLSearchParams;
|
export type RequestBody = undefined | string | FormData | URLSearchParams;
|
||||||
|
|
||||||
|
type Headers = Record<string, string>;
|
||||||
|
|
||||||
function ensureAbsoluteUrl(url: string) {
|
function ensureAbsoluteUrl(url: string) {
|
||||||
if (url.startsWith("http://") || url.startsWith("https://")) {
|
if (url.startsWith("http://") || url.startsWith("https://")) {
|
||||||
return url;
|
return url;
|
||||||
@ -44,7 +46,7 @@ function ensureAbsoluteUrl(url: string) {
|
|||||||
* Represents an HTTP request context
|
* Represents an HTTP request context
|
||||||
*/
|
*/
|
||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: Headers = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URL;
|
private url: URL;
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ export class RequestContext {
|
|||||||
return this.httpMethod;
|
return this.httpMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHeaders(): { [key: string]: string } {
|
public getHeaders(): Headers {
|
||||||
return this.headers;
|
return this.headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +162,7 @@ export class SelfDecodingBody implements ResponseBody {
|
|||||||
export class ResponseContext {
|
export class ResponseContext {
|
||||||
public constructor(
|
public constructor(
|
||||||
public httpStatusCode: number,
|
public httpStatusCode: number,
|
||||||
public headers: { [key: string]: string },
|
public headers: Headers,
|
||||||
public body: ResponseBody
|
public body: ResponseBody
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@ -171,8 +173,8 @@ export class ResponseContext {
|
|||||||
* Parameter names are converted to lower case
|
* Parameter names are converted to lower case
|
||||||
* The first parameter is returned with the key `""`
|
* The first parameter is returned with the key `""`
|
||||||
*/
|
*/
|
||||||
public getParsedHeader(headerName: string): { [parameter: string]: string } {
|
public getParsedHeader(headerName: string): Headers {
|
||||||
const result: { [parameter: string]: string } = {};
|
const result: Headers = {};
|
||||||
if (!this.headers[headerName]) {
|
if (!this.headers[headerName]) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -245,7 +247,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
|
|||||||
export class HttpInfo<T> extends ResponseContext {
|
export class HttpInfo<T> extends ResponseContext {
|
||||||
public constructor(
|
public constructor(
|
||||||
public httpStatusCode: number,
|
public httpStatusCode: number,
|
||||||
public headers: { [key: string]: string },
|
public headers: Headers,
|
||||||
public body: ResponseBody,
|
public body: ResponseBody,
|
||||||
public data: T,
|
public data: T,
|
||||||
) {
|
) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user