@@ -19,7 +19,6 @@ import {
1919 SchemaMethods ,
2020 SchemaResources ,
2121 SchemaItem ,
22- SchemaItems ,
2322} from 'googleapis-common' ;
2423import * as nunjucks from 'nunjucks' ;
2524import * as filters from './filters' ;
@@ -87,14 +86,14 @@ export async function generateSamples(apiPath: string, schema: Schema) {
8786
8887function getSample ( schema : Schema , method : SchemaMethod ) {
8988 let responseExample : undefined | { } ;
90- if ( method . response ) {
91- const item = schema . schemas [ method . response . $ref ! ] ;
92- responseExample = flattenSchema ( item , schema . schemas ) ;
89+ if ( method ? .response ?. $ref ) {
90+ const item = schema ? .schemas ?. [ method . response . $ref ] ;
91+ responseExample = flattenSchema ( item ) ;
9392 }
9493 let requestExample : { } | undefined ;
95- if ( method . request ) {
96- const item = schema . schemas [ method . request . $ref ! ] ;
97- requestExample = flattenSchema ( item , schema . schemas ) ;
94+ if ( method ? .request ?. $ref ) {
95+ const item = schema ? .schemas ?. [ method . request . $ref ] ;
96+ requestExample = flattenSchema ( item ) ;
9897 }
9998 const sampleData : SampleData = {
10099 api : schema ,
@@ -137,24 +136,19 @@ export function getAllMethods(bag: MethodBag, methods?: SchemaMethod[]) {
137136 * Provide a flattened representation of what the structure for a
138137 * given request or response could look like.
139138 */
140- function flattenSchema ( item : SchemaItem , schemas : SchemaItems ) {
139+ function flattenSchema ( item ? : SchemaItem ) {
141140 // tslint:disable-next-line no-any
142141 // eslint-disable-next-line @typescript-eslint/no-explicit-any
143142 const result : any = { } ;
144- if ( item . properties ) {
143+ if ( item ? .properties ) {
145144 for ( const [ name , details ] of Object . entries ( item . properties ) ) {
146- result [ name ] = getExamplePropertyValue ( name , details , schemas ) ;
145+ result [ name ] = getExamplePropertyValue ( name , details ) ;
147146 }
148147 }
149148 return result ;
150149}
151150
152- function getExamplePropertyValue (
153- name : string ,
154- details : SchemaItem ,
155- // eslint-disable-next-line @typescript-eslint/no-unused-vars
156- schemas : SchemaItems ,
157- ) : { } {
151+ function getExamplePropertyValue ( name : string , details : SchemaItem ) : { } {
158152 switch ( details . type ) {
159153 case 'string' :
160154 return `my_${ name } ` ;
0 commit comments