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
11 changed files
with
1,515 additions
and
1,870 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,86 @@ | ||
/** | ||
* Copyright 2021 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { IncomingMessage } from "http"; | ||
import * as https from "https"; | ||
import * as yaml from "js-yaml"; | ||
import * as path from "path"; | ||
import { URL } from "url"; | ||
import { QuarkusConfig } from "../QuarkusConfig"; | ||
|
||
const HTTP_MATCHER = new RegExp('^http://'); | ||
|
||
export interface CodeQuarkusFunctionality { | ||
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<CodeQuarkusFunctionality> { | ||
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 CodeQuarkusFunctionality; | ||
} | ||
|
||
/** | ||
* 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 CodeQuarkusFunctionality; | ||
} | ||
|
||
/** | ||
* 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,8 @@ | |
}, | ||
"linterOptions": { | ||
"exclude": [ | ||
"test-resources" | ||
"test-resources", | ||
"out/**/*" | ||
] | ||
} | ||
} |