Skip to content

Commit

Permalink
simplify resolved schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Dec 23, 2019
1 parent 8062123 commit c33dfaa
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/middlewares/schemas/body.parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { ContentType, validationError } from '../util';

import { OpenAPIV3 } from '../../framework/types';

export type BodySchema = OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject | {};
export type BodySchema =
| OpenAPIV3.ReferenceObject
| OpenAPIV3.SchemaObject
| {};

export class BodySchemaParser {
private _apiDoc: OpenAPIV3.Document;
Expand Down Expand Up @@ -68,13 +71,9 @@ export class BodySchemaParser {

let bodyContentRefSchema = null;
if (bodyContentSchema && '$ref' in bodyContentSchema) {
const objectSchema = this.ajv.getSchema(bodyContentSchema.$ref);
bodyContentRefSchema =
objectSchema &&
objectSchema.schema &&
(<any>objectSchema.schema).properties
? { ...(<any>objectSchema).schema }
: null;
const resolved = this.ajv.getSchema(bodyContentSchema.$ref);
const schema = <OpenAPIV3.SchemaObject>resolved?.schema;
bodyContentRefSchema = schema?.properties ? { ...schema } : null;
}
// handle readonly / required request body refs
// don't need to copy schema if validator gets its own copy of the api spec
Expand Down

0 comments on commit c33dfaa

Please sign in to comment.