forked from redhat-developer/vscode-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RESTEasy can be excluded if using code.quarkus.io
Reads the data from code.quarkus.io or code.quarkus.redhat.com to see which quarkus extensions are required. This means if code.quarkus.io is used, then resteasy is not required. Reads the Open API of the code quarkus instance to determine if the option to prevent sample code being generated is present. If it is, then it adds another step to the project generation wizard to specify if sample code should be generated. Closes redhat-developer#322 Signed-off-by: David Thompson <davthomp@redhat.com>
- Loading branch information
Showing
12 changed files
with
1,862 additions
and
2,204 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { IncomingMessage } from "http"; | ||
import * as https from "https"; | ||
import * as yaml from "js-yaml"; | ||
import * as path from "path"; | ||
import { QuarkusConfig } from "../QuarkusConfig"; | ||
import { read } from "fs-extra"; | ||
import { URL } from "url"; | ||
|
||
const HTTP_MATCHER = new RegExp('^http://'); | ||
|
||
export namespace CodeQuarkusApiUtils { | ||
|
||
export interface Functionality { | ||
canExcludeSampleCode: boolean; | ||
} | ||
|
||
/** | ||
* Returns the capabilities of the Code Quarkus API instance that is defined in the user settings | ||
* | ||
* @returns the capabilities of the Code Quarkus API instance that is defined in the user settings | ||
* @throws if something goes wrong when getting the functionality from OpenAPI | ||
*/ | ||
export async function getCodeQuarkusApiFunctionality(): Promise<Functionality> { | ||
let oldOpenApiUrl: string = path.dirname(QuarkusConfig.getApiUrl()) + '/openapi'; | ||
let newOpenApiUrl: string = path.dirname(QuarkusConfig.getApiUrl()) + '/q/openapi'; | ||
oldOpenApiUrl = oldOpenApiUrl.replace(HTTP_MATCHER, "https://"); | ||
newOpenApiUrl = oldOpenApiUrl.replace(HTTP_MATCHER, "https://"); | ||
let openApiYaml: string; | ||
try { | ||
openApiYaml = await httpsGet(newOpenApiUrl); | ||
} catch { | ||
openApiYaml = await httpsGet(oldOpenApiUrl); | ||
} | ||
const openApiData: any = yaml.load(openApiYaml); | ||
|
||
return { | ||
canExcludeSampleCode: openApiData?.paths?.['/api/download']?.get?.parameters?.filter(p => p?.name === 'ne').length > 0 | ||
} as Functionality; | ||
} | ||
|
||
/** | ||
* Returns a set of capabilities that are implemented by all Code Quarkus APIs | ||
* | ||
* @returns a set of capabilities that are implemented by all Code Quarkus APIs | ||
*/ | ||
export function getDefaultFunctionality() { | ||
return { | ||
canExcludeSampleCode: false | ||
} as Functionality; | ||
} | ||
|
||
/** | ||
* Returns the GET response body if the code is 200 and rejects otherwise | ||
* | ||
* @param url URL to GET | ||
* @returns the response body if the code is 200 and rejects otherwise | ||
* @throws if anything goes wrong (not 200 response, any other errors during get) | ||
*/ | ||
async function httpsGet(url: string): Promise<string> { | ||
return new Promise<string>((resolve, reject) => { | ||
https.get(url, (res: IncomingMessage) => { | ||
if (res.statusCode === 301 || res.statusCode === 302) { | ||
httpsGet(new URL(url).origin + res.headers.location) // | ||
.then(resolve, reject); | ||
} else if (res.statusCode !== 200) { | ||
reject(`${res.statusCode}: ${res.statusMessage}`); | ||
} | ||
res.on('data', (d: Buffer) => { | ||
resolve(d.toString('utf8')); | ||
}); | ||
}) | ||
.on('error', reject); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,8 @@ | |
}, | ||
"linterOptions": { | ||
"exclude": [ | ||
"test-resources" | ||
"test-resources", | ||
"out/**/*" | ||
] | ||
} | ||
} |