How to use the openapi3-ts.isReferenceObject function in openapi3-ts

To help you get started, we’ve selected a few openapi3-ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eropple / nestjs-openapi3 / src / utils / schema.ts View on Github external
export function parseSchemaLike(c: SchemaLike, modelsToParse: Array): O3TS.SchemaObject | O3TS.ReferenceObject {
  // It's important to note that this method DOES have a side effect: it
  // adds any found models to `modelsToParse`.

  if (typeof(c) === 'function') {
    return inferSchema(c, modelsToParse);
  } else if (Array.isArray(c)) {
    return { type: 'array', items: parseSchemaLike(c[0], modelsToParse) };
  } else if (isReferenceObject(c)) {
    return c;
  } else { // O3TS.SchemaObjects, but potentially with deeper schemaLikes.
    const ret: O3TS.SchemaObject = {
      ...c,
    };

    if (c.allOf) {
      ret.allOf = c.allOf.map(sub => parseSchemaLike(sub, modelsToParse));
    }

    if (c.anyOf) {
      ret.anyOf = c.anyOf.map(sub => parseSchemaLike(sub, modelsToParse));
    }

    if (c.oneOf) {
      ret.oneOf = c.oneOf.map(sub => parseSchemaLike(sub, modelsToParse));

openapi3-ts

TS Model & utils for OpenAPI 3.x specification.

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis