-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement OpenApi TypeScript Client for Project Overview (#3703)
- Loading branch information
1 parent
20749ba
commit 72972ab
Showing
20 changed files
with
208 additions
and
55 deletions.
There are no files selected for viewing
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,5 @@ | ||
{ | ||
// HOST represents the URL of the API client. In this case, it's the URL of the SPA because we proxy API requests to the backend to sidestep any CORS issues. | ||
"HOST": "https://localhost", | ||
"LOCAL_DEV": false | ||
} |
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,10 @@ | ||
# This .env file contains the default environment variables | ||
# For local development, create an .env.local file with the desired variable values | ||
# Note: .env.local will be ignored by git | ||
# Local development variables must start with VITE_API | ||
VITE_API_HOST=http://localhost:3000 | ||
|
||
# Optional variables needed for testing with SecHub Server Basic Auth | ||
VITE_API_LOCAL_DEV=false | ||
VITE_API_USER='example-test-user' | ||
VITE_API_PASSWORD='example-api-token' |
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 |
---|---|---|
@@ -1,4 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
export const CONFIG = { | ||
HOST: String(import.meta.env.SECHUB_HOST) || '', | ||
|
||
import { ref } from 'vue' | ||
|
||
const config = ref({ | ||
// New ENV must be defined in global.d.ts | ||
HOST: String(import.meta.env.VITE_API_HOST) || '', | ||
USERNAME: String(import.meta.env.VITE_API_USER) || '', | ||
PASSWORD: String(import.meta.env.VITE_API_PASSWORD) || '', | ||
LOCAL_DEV: String(import.meta.env.VITE_API_LOCAL_DEV) || '', | ||
}) | ||
|
||
// Overrides local environment variables after project compilation | ||
// Utilizes variables from config.json if available | ||
export async function loadConfig () { | ||
try { | ||
const response = await fetch('/config.json') | ||
const runtimeConfig = await response.json() | ||
config.value = { ...config.value, ...runtimeConfig } | ||
} catch (error) { | ||
console.error('Failed to load configuration, using fallback in .env:', error) | ||
} | ||
} | ||
|
||
export function useConfig () { | ||
return config | ||
} |
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 |
---|---|---|
@@ -1,10 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
import { CONFIG } from 'src/config' | ||
import { useConfig } from '@/config' | ||
import { Configuration } from '@/generated-sources/openapi' | ||
|
||
const apiConfig = new Configuration({ | ||
basePath: CONFIG.HOST, | ||
// todo: check if cookie set by server is sent back (for auth reasons) | ||
}) | ||
let apiConfig: Configuration | ||
const config = useConfig() | ||
|
||
if (config.value.LOCAL_DEV) { | ||
// api configuration for local development with basic auth | ||
apiConfig = new Configuration({ | ||
basePath: config.value.HOST, | ||
username: config.value.USERNAME, | ||
password: config.value.PASSWORD, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
} else { | ||
apiConfig = new Configuration({ | ||
basePath: config.value.HOST, | ||
headers: { | ||
// todo: check if cookie set by server is sent back (for auth reasons) | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
} | ||
|
||
export default apiConfig |
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,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
import { ConfigurationApi } from '@/generated-sources/openapi' | ||
import apiConfig from './configuration' | ||
|
||
const configurationApi = new ConfigurationApi(apiConfig) | ||
|
||
export default configurationApi |
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,13 @@ | ||
// SPDX-License-Identifier: MIT | ||
import configurationApi from './configurationService' | ||
import projectApi from './productAdministrationService' | ||
import systemApi from './systemApiService' | ||
|
||
const defaultClient = { | ||
withProjectApi: projectApi, | ||
withSystemApi: systemApi, | ||
withConfigurationApi: configurationApi, | ||
|
||
} | ||
|
||
export default defaultClient |
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,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
import { ProjectAdministrationApi } from '@/generated-sources/openapi' | ||
import apiConfig from './configuration' | ||
|
||
const projectApi = new ProjectAdministrationApi(apiConfig) | ||
|
||
export default projectApi |
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,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
import { SystemApi } from '@/generated-sources/openapi' | ||
import apiConfig from './configuration' | ||
|
||
const systemApi = new SystemApi(apiConfig) | ||
|
||
export default systemApi |
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
Oops, something went wrong.