mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-14 04:46:34 +03:00
fix: referenced header name is empty
This commit is contained in:
parent
e1b2065b2e
commit
13165fb8fc
24
src/services/__tests__/fixtures/fields.json
Normal file
24
src/services/__tests__/fixtures/fields.json
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"openapi": "3.0.0",
|
||||||
|
"info": {
|
||||||
|
"version": "1.0",
|
||||||
|
"title": "Foo"
|
||||||
|
},
|
||||||
|
"components": {
|
||||||
|
"parameters": {
|
||||||
|
"testParam": {
|
||||||
|
"in": "path",
|
||||||
|
"name": "test_name",
|
||||||
|
"schema": { "type": "string" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"testHeader": {
|
||||||
|
"description": "The response content language",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
src/services/__tests__/models/FieldModel.test.ts
Normal file
43
src/services/__tests__/models/FieldModel.test.ts
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import { FieldModel } from '../../models/Field';
|
||||||
|
import { OpenAPIParser } from '../../OpenAPIParser';
|
||||||
|
import { RedocNormalizedOptions } from '../../RedocNormalizedOptions';
|
||||||
|
|
||||||
|
const opts = new RedocNormalizedOptions({});
|
||||||
|
|
||||||
|
describe('Models', () => {
|
||||||
|
describe('FieldModel', () => {
|
||||||
|
let parser;
|
||||||
|
const spec = require('../fixtures/fields.json');
|
||||||
|
parser = new OpenAPIParser(spec, undefined, opts);
|
||||||
|
|
||||||
|
test('basic field details', () => {
|
||||||
|
const field = new FieldModel(
|
||||||
|
parser,
|
||||||
|
{
|
||||||
|
$ref: '#/components/parameters/testParam',
|
||||||
|
},
|
||||||
|
'#/components/parameters/testParam',
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(field.name).toEqual('test_name');
|
||||||
|
expect(field.in).toEqual('path');
|
||||||
|
expect(field.required).toEqual(false);
|
||||||
|
expect(field.schema.type).toEqual('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('field name should populated from name even if $ref (headers)', () => {
|
||||||
|
const field = new FieldModel(
|
||||||
|
parser,
|
||||||
|
{
|
||||||
|
$ref: '#/components/headers/testHeader',
|
||||||
|
name: 'Test-Header',
|
||||||
|
},
|
||||||
|
'#/components/headers/testHeader',
|
||||||
|
opts,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(field.name).toEqual('Test-Header');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -22,13 +22,12 @@ export class FieldModel {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
parser: OpenAPIParser,
|
parser: OpenAPIParser,
|
||||||
infoOrRef: Referenced<OpenAPIParameter>,
|
infoOrRef: Referenced<OpenAPIParameter> & { name?: string },
|
||||||
pointer: string,
|
pointer: string,
|
||||||
options: RedocNormalizedOptions,
|
options: RedocNormalizedOptions,
|
||||||
) {
|
) {
|
||||||
const info = parser.deref(infoOrRef);
|
const info = parser.deref<OpenAPIParameter>(infoOrRef);
|
||||||
|
this.name = infoOrRef.name || info.name;
|
||||||
this.name = info.name;
|
|
||||||
this.in = info.in;
|
this.in = info.in;
|
||||||
this.required = !!info.required;
|
this.required = !!info.required;
|
||||||
const schemaPointer = (parser.isRef(infoOrRef) ? infoOrRef.$ref : pointer) + '/schema';
|
const schemaPointer = (parser.isRef(infoOrRef) ? infoOrRef.$ref : pointer) + '/schema';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user