generateObject(schema) {
    const {
      Object: ObjectElement,
    } = this.minim.elements;

    const element = new ObjectElement();
    let properties = schema.properties || {};
    let required = schema.required || [];

    if (schema.allOf && Array.isArray(schema.allOf)) {
      // Merge all of the object allOf into properties and required
      const allOf = schema.allOf.filter(subschema => subschema.type === 'object');

      const allProperties = allOf
        .filter(subschema => subschema.properties)
        .map(subschema => subschema.properties);
      properties = Object.assign(properties, ...allProperties);

      required = allOf
        .filter(subschema => subschema.required)
        .map(subschema => subschema.required)
        .reduce((accumulator, property) => accumulator.concat(property), required);

      const refs = schema.allOf
        .filter(subschema => subschema.$ref)
        .map(subschema => idForDataStructure(subschema.$ref));

      if (refs.length === 1) {
        // allOf contains ref, let's treat it as our base
        [element.element] = refs;
      } else if (refs.length > 1) {
        const { Ref: RefElement } = this.minim.elements;
        const refElements = refs.map(ref => new RefElement(ref));
        element.content.push(...refElements);
      }
    }

    element.content.push(..._.map(properties, (subschema, property) => {
      const member = this.generateMember(property, subschema);

      const isRequired = required.includes(property);
      member.attributes.set('typeAttributes', [
        isRequired ? 'required' : 'optional',
      ]);

      return member;
    }));

    // Create member elements for required keys which are not defined in properties
    const missingRequiredProperties = required.filter(name => properties[name] === undefined);
    const requiredMembers = missingRequiredProperties.map((name) => {
      let member;

      if (schema.additionalProperties !== undefined && typeof schema.additionalProperties !== 'boolean') {
        member = this.generateMember(name, schema.additionalProperties);
      } else {
        member = new this.minim.elements.Member(name);
      }

      member.attributes.set('typeAttributes', ['required']);
      return member;
    });
    element.content.push(...requiredMembers);

    if (schema.additionalProperties !== undefined && schema.additionalProperties !== true) {
      const typeAttributes = element.attributes.get('typeAttributes') || new this.minim.elements.Array([]);
      typeAttributes.push('fixedType');
      element.attributes.set('typeAttributes', typeAttributes);

      if (schema.additionalProperties !== false) {
        const member = this.generateMember('', schema.additionalProperties);
        member.attributes.set('variable', true);
        element.content.push(member);
      }
    }

    return element;
  }
// Generates an object element from the given object schema
Generates an object element from the given object schema
Generates an object element from the given object schema
generateObject(schema) {
    const {
      Object: ObjectElement,
    } = this.minim.elements;
    const element = new ObjectElement();
    let properties = schema.properties || {};
    let required = schema.required || [];
    if (schema.allOf && Array.isArray(schema.allOf)) {
      const allOf = schema.allOf.filter(subschema => subschema.type === 'object');
      const allProperties = allOf
        .filter(subschema => subschema.properties)
        .map(subschema => subschema.properties);
      properties = Object.assign(properties, ...allProperties);
      required = allOf
        .filter(subschema => subschema.required)
        .map(subschema => subschema.required)
        .reduce((accumulator, property) => accumulator.concat(property), required);
      const refs = schema.allOf
        .filter(subschema => subschema.$ref)
        .map(subschema => idForDataStructure(subschema.$ref));
      if (refs.length === 1) {
        [element.element] = refs;
      } else if (refs.length > 1) {
        const { Ref: RefElement } = this.minim.elements;
        const refElements = refs.map(ref => new RefElement(ref));
        element.content.push(...refElements);
      }
    }
    element.content.push(..._.map(properties, (subschema, property) => {
      const member = this.generateMember(property, subschema);
      const isRequired = required.includes(property);
      member.attributes.set('typeAttributes', [
        isRequired ? 'required' : 'optional',
      ]);
      return member;
    }));
    const missingRequiredProperties = required.filter(name => properties[name] === undefined);
    const requiredMembers = missingRequiredProperties.map((name) => {
      let member;
      if (schema.additionalProperties !== undefined && typeof schema.additionalProperties !== 'boolean') {
        member = this.generateMember(name, schema.additionalProperties);
      } else {
        member = new this.minim.elements.Member(name);
      }
      member.attributes.set('typeAttributes', ['required']);
      return member;
    });
    element.content.push(...requiredMembers);
    if (schema.additionalProperties !== undefined && schema.additionalProperties !== true) {
      const typeAttributes = element.attributes.get('typeAttributes') || new this.minim.elements.Array([]);
      typeAttributes.push('fixedType');
      element.attributes.set('typeAttributes', typeAttributes);
      if (schema.additionalProperties !== false) {
        const member = this.generateMember('', schema.additionalProperties);
        member.attributes.set('variable', true);
        element.content.push(member);
      }
    }
    return element;
  }
generateObject ( schema ) { const { Object : ObjectElement , } = this . minim . elements ; const element = new ObjectElement ( ) ; let properties = schema . properties || { } ; let required = schema . required || [ ] ; if ( schema . allOf && Array . isArray ( schema . allOf ) ) { const allOf = schema . allOf . filter ( subschema => subschema . type === 'object' ) ; const allProperties = allOf . filter ( subschema => subschema . properties ) . map ( subschema => subschema . properties ) ; properties = Object . assign ( properties , ... allProperties ) ; required = allOf . filter ( subschema => subschema . required ) . map ( subschema => subschema . required ) . reduce ( ( accumulator , property ) => accumulator . concat ( property ) , required ) ; const refs = schema . allOf . filter ( subschema => subschema . $ref ) . map ( subschema => idForDataStructure ( subschema . $ref ) ) ; if ( refs . length === 1 ) { [ element . element ] = refs ; } else if ( refs . length > 1 ) { const { Ref : RefElement } = this . minim . elements ; const refElements = refs . map ( ref => new RefElement ( ref ) ) ; element . content . push ( ... refElements ) ; } } element . content . push ( ... _ . map ( properties , ( subschema , property ) => { const member = this . generateMember ( property , subschema ) ; const isRequired = required . includes ( property ) ; member . attributes . set ( 'typeAttributes' , [ isRequired ? 'required' : 'optional' , ] ) ; return member ; } ) ) ; const missingRequiredProperties = required . filter ( name => properties [ name ] === undefined ) ; const requiredMembers = missingRequiredProperties . map ( ( name ) => { let member ; if ( schema . additionalProperties !== undefined && typeof schema . additionalProperties !== 'boolean' ) { member = this . generateMember ( name , schema . additionalProperties ) ; } else { member = new this . minim . elements . Member ( name ) ; } member . attributes . set ( 'typeAttributes' , [ 'required' ] ) ; return member ; } ) ; element . content . push ( ... requiredMembers ) ; if ( schema . additionalProperties !== undefined && schema . additionalProperties !== true ) { const typeAttributes = element . attributes . get ( 'typeAttributes' ) || new this . minim . elements . Array ( [ ] ) ; typeAttributes . push ( 'fixedType' ) ; element . attributes . set ( 'typeAttributes' , typeAttributes ) ; if ( schema . additionalProperties !== false ) { const member = this . generateMember ( '' , schema . additionalProperties ) ; member . attributes . set ( 'variable' , true ) ; element . content . push ( member ) ; } } return element ; }
Generates an object element from the given object schema
Generates an object element from the given object schema
// Merge all of the object allOf into properties and required // allOf contains ref, let's treat it as our base // Create member elements for required keys which are not defined in properties