MCPcopy
hub / github.com/FoalTS/foal / main

Function main

packages/swagger/src/swagger-controller.ts:110–138  ·  view source on GitHub ↗
(ctx: Context)

Source from the content-addressed store, hash-verified

108
109 @Get('/main.js')
110 async main(ctx: Context) {
111 const template = await readFile(join(__dirname, 'main.tpl.js'), 'utf8');
112 let body = '';
113
114 if (!Array.isArray(this.options)) {
115 const url = isUrlOption(this.options) ? this.options.url : 'openapi.json';
116 body = template
117 .replace('{{ urls }}', `url: "${url}"`)
118 .replace('{{ primaryName }}', '');
119 } else {
120 let primaryName: string = '';
121 const options = this.options
122 .map(option => {
123 if (option.primary) {
124 primaryName = `\n \'urls.primaryName\': "${option.name}",`;
125 }
126 return {
127 name: option.name,
128 url: isUrlOption(option) ? option.url : `openapi.json?name=${option.name}`
129 };
130 });
131 body = template
132 .replace('{{ urls }}', `urls: ${JSON.stringify(options)}`)
133 .replace('{{ primaryName }}', primaryName);
134 }
135 body = body.replace('{{ uiOptions }}', JSON.stringify(this.uiOptions));
136 return new HttpResponseOK(body)
137 .setHeader('Content-Type', 'application/javascript');
138 }
139
140 @Get('/swagger-ui.css')
141 swaggerUi() {

Callers

nothing calls this directly

Calls 3

joinFunction · 0.85
isUrlOptionFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected