mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-07 13:30:33 +03:00
parent
418b74848d
commit
633d71293f
|
@ -17,6 +17,21 @@
|
||||||
"schema": { "type": "array" },
|
"schema": { "type": "array" },
|
||||||
"style": "form",
|
"style": "form",
|
||||||
"explode": true
|
"explode": true
|
||||||
|
},
|
||||||
|
"queryParamWithNoStyle": {
|
||||||
|
"in": "query",
|
||||||
|
"name": "serialization_test_name",
|
||||||
|
"schema": { "type": "array" }
|
||||||
|
},
|
||||||
|
"pathParamWithNoStyle": {
|
||||||
|
"in": "path",
|
||||||
|
"name": "serialization_test_name",
|
||||||
|
"schema": { "type": "array" }
|
||||||
|
},
|
||||||
|
"cookieParamWithNoStyle": {
|
||||||
|
"in": "cookie",
|
||||||
|
"name": "serialization_test_name",
|
||||||
|
"schema": { "type": "array" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"headers": {
|
"headers": {
|
||||||
|
|
|
@ -43,6 +43,57 @@ describe('Models', () => {
|
||||||
expect(field.explode).toEqual(true);
|
expect(field.explode).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('field details relevant for default path param serialization', () => {
|
||||||
|
const field = new FieldModel(
|
||||||
|
parser,
|
||||||
|
{
|
||||||
|
$ref: '#/components/parameters/pathParamWithNoStyle',
|
||||||
|
},
|
||||||
|
'#/components/parameters/pathParamWithNoStyle',
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(field.name).toEqual('serialization_test_name');
|
||||||
|
expect(field.in).toEqual('path');
|
||||||
|
expect(field.schema.type).toEqual('array');
|
||||||
|
expect(field.style).toEqual('simple');
|
||||||
|
expect(field.explode).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('field details relevant for default query parameter serialization', () => {
|
||||||
|
const field = new FieldModel(
|
||||||
|
parser,
|
||||||
|
{
|
||||||
|
$ref: '#/components/parameters/queryParamWithNoStyle',
|
||||||
|
},
|
||||||
|
'#/components/parameters/queryParamWithNoStyle',
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(field.name).toEqual('serialization_test_name');
|
||||||
|
expect(field.in).toEqual('query');
|
||||||
|
expect(field.schema.type).toEqual('array');
|
||||||
|
expect(field.style).toEqual('form');
|
||||||
|
expect(field.explode).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('field details relevant for default cookie parameter serialization', () => {
|
||||||
|
const field = new FieldModel(
|
||||||
|
parser,
|
||||||
|
{
|
||||||
|
$ref: '#/components/parameters/queryParamWithNoStyle',
|
||||||
|
},
|
||||||
|
'#/components/parameters/queryParamWithNoStyle',
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(field.name).toEqual('serialization_test_name');
|
||||||
|
expect(field.in).toEqual('query');
|
||||||
|
expect(field.schema.type).toEqual('array');
|
||||||
|
expect(field.style).toEqual('form');
|
||||||
|
expect(field.explode).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
test('field name should populated from name even if $ref (headers)', () => {
|
test('field name should populated from name even if $ref (headers)', () => {
|
||||||
const field = new FieldModel(
|
const field = new FieldModel(
|
||||||
parser,
|
parser,
|
||||||
|
|
|
@ -12,18 +12,27 @@ import { extractExtensions } from '../../utils/openapi';
|
||||||
import { OpenAPIParser } from '../OpenAPIParser';
|
import { OpenAPIParser } from '../OpenAPIParser';
|
||||||
import { SchemaModel } from './Schema';
|
import { SchemaModel } from './Schema';
|
||||||
|
|
||||||
function getDefaultStyleValue(parameterLocation: OpenAPIParameterLocation): OpenAPIParameterStyle {
|
const DEFAULT_SERIALIZATION: Record<
|
||||||
switch (parameterLocation) {
|
OpenAPIParameterLocation,
|
||||||
case 'header':
|
{ explode: boolean; style: OpenAPIParameterStyle }
|
||||||
return 'simple';
|
> = {
|
||||||
case 'query':
|
path: {
|
||||||
return 'form';
|
style: 'simple',
|
||||||
case 'path':
|
explode: false,
|
||||||
return 'simple';
|
},
|
||||||
default:
|
query: {
|
||||||
return 'form';
|
style: 'form',
|
||||||
}
|
explode: true,
|
||||||
}
|
},
|
||||||
|
header: {
|
||||||
|
style: 'simple',
|
||||||
|
explode: false,
|
||||||
|
},
|
||||||
|
cookie: {
|
||||||
|
style: 'form',
|
||||||
|
explode: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Field or Parameter model ready to be used by components
|
* Field or Parameter model ready to be used by components
|
||||||
|
@ -75,10 +84,14 @@ export class FieldModel {
|
||||||
} else if (info.style) {
|
} else if (info.style) {
|
||||||
this.style = info.style;
|
this.style = info.style;
|
||||||
} else if (this.in) {
|
} else if (this.in) {
|
||||||
this.style = getDefaultStyleValue(this.in);
|
this.style = DEFAULT_SERIALIZATION[this.in].style;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.explode = !!info.explode;
|
if (info.explode === undefined && this.in) {
|
||||||
|
this.explode = DEFAULT_SERIALIZATION[this.in].explode;
|
||||||
|
} else {
|
||||||
|
this.explode = !!info.explode;
|
||||||
|
}
|
||||||
|
|
||||||
this.deprecated = info.deprecated === undefined ? !!this.schema.deprecated : info.deprecated;
|
this.deprecated = info.deprecated === undefined ? !!this.schema.deprecated : info.deprecated;
|
||||||
parser.exitRef(infoOrRef);
|
parser.exitRef(infoOrRef);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user