Skip to content

Commit

Permalink
Remove $ref resolving code
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlende committed Jul 15, 2024
1 parent 36ff2ba commit f10e7c3
Showing 1 changed file with 2 additions and 46 deletions.
48 changes: 2 additions & 46 deletions bin/api-docs/gen-theme-reference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,42 +79,6 @@ const keys = ( maybeObject ) => {
return Object.keys( maybeObject );
};

/**
* Get definition from ref.
*
* @param {string} ref
* @return {Object} definition
* @throws {Error} If the referenced definition is not found in 'themejson.definitions'.
*
* @example
* getDefinition( '#/definitions/typographyProperties/properties/fontFamily' )
* // returns themejson.definitions.typographyProperties.properties.fontFamily
*/
const resolveDefinitionRef = ( ref ) => {
const refParts = ref.split( '/' );
const definition = refParts[ refParts.length - 1 ];
if ( ! themejson.definitions[ definition ] ) {
throw new Error( `Can't resolve '${ ref }'. Definition not found` );
}
return themejson.definitions[ definition ];
};

/**
* Get properties from an array.
*
* @param {Object} items
* @return {Object} properties
*/
const getPropertiesFromArray = ( items ) => {
// if its a $ref resolve it
if ( items.$ref ) {
return resolveDefinitionRef( items.$ref ).properties;
}

// otherwise just return the properties
return items.properties;
};

/**
* Convert settings properties to markup.
*
Expand All @@ -138,9 +102,7 @@ const getSettingsPropertiesMarkup = ( struct ) => {
let type = props[ key ].type || '';
let ps =
props[ key ].type === 'array'
? keys( getPropertiesFromArray( props[ key ].items ) )
.sort()
.join( ', ' )
? keys( props[ key ].items.properties ).sort().join( ', ' )
: '';

/*
Expand All @@ -159,9 +121,7 @@ const getSettingsPropertiesMarkup = ( struct ) => {
.map( ( item ) =>
item?.type === 'object' && item?.properties
? '_{' +
keys( getPropertiesFromArray( item ) )
.sort()
.join( ', ' ) +
keys( item.properties ).sort().join( ', ' ) +
'}_'
: ''
)
Expand Down Expand Up @@ -249,10 +209,6 @@ const formatType = ( prop ) => {
if ( item.type ) {
types.push( item.type );
}
// refComplete is always an object
if ( item.$ref && item.$ref === '#/definitions/refComplete' ) {
types.push( 'object' );
}
} );

type = [ ...new Set( types ) ].join( ', ' );
Expand Down

0 comments on commit f10e7c3

Please sign in to comment.