Skip to content

Commit

Permalink
Merge branch 'main' into list-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
yujin-emma authored May 16, 2024
2 parents 6c0a495 + bd62a5d commit b06c88d
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @ananzh @kavilla @AMoo-Miki @ashwin-pc @joshuarrrr @abbyhu2000 @zengyan-amazon @zhongnansu @manasvinibs @ZilongX @Flyingliuhub @BSFishy @curq @bandinib-amzn @SuZhou-Joe @ruanyl @BionIT @xinruiba @zhyuanqi
* @ananzh @kavilla @AMoo-Miki @ashwin-pc @joshuarrrr @abbyhu2000 @zengyan-amazon @zhongnansu @manasvinibs @ZilongX @Flyingliuhub @curq @bandinib-amzn @SuZhou-Joe @ruanyl @BionIT @xinruiba @zhyuanqi @mengweieric
3 changes: 2 additions & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
| Manasvini B Suryanarayana | [manasvinibs](https://github.com/manasvinibs) | Amazon |
| Tao Liu | [Flyingliuhub](https://github.com/Flyingliuhub) | Amazon |
| Zilong Xia | [ZilongX](https://github.com/ZilongX) | Amazon |
| Matt Provost | [BSFishy](https://github.com/BSFishy) | Amazon |
| Sirazh Gabdullin | [curq](https://github.com/curq) | External contributor |
| Bandini Bhopi | [bandinib-amzn](https://github.com/bandinib-amzn) | Amazon |
| Su Zhou | [SuZhou-Joe](https://github.com/SuZhou-Joe) | Amazon |
| Yulong Ruan | [ruanyl](https://github.com/ruanyl) | Amazon |
| Lu Yu | [BionIT](https://github.com/BionIT) | Amazon |
| Xinrui Bai | [xinruiba](https://github.com/xinruiba) | Amazon |
| Ella Zhu | [zhyuanqi](https://github.com/zhyuanqi) | Amazon |
| Eric Wei | [mengweieric](https://github.com/mengweieric) | Amazon |

## Emeritus

Expand All @@ -35,3 +35,4 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
| Bishoy Boktor | [boktorbb](https://github.com/boktorbb) | Amazon |
| Sean Neumann | [seanneumann](https://github.com/seanneumann) | Contributor |
| Kristen Tian | [kristenTian](https://github.com/kristenTian) | Amazon |
| Matt Provost | [BSFishy](https://github.com/BSFishy) | Amazon |
2 changes: 2 additions & 0 deletions changelogs/fragments/6585.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
chore:
- Adds a git pre commit hook to ensure that developer docs are always updated ([#6585](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6585))
2 changes: 2 additions & 0 deletions changelogs/fragments/6790.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doc:
- Move @BSFishy to emeritus maintainer ([#6790](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6790))
2 changes: 2 additions & 0 deletions changelogs/fragments/6798.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doc:
- Add mengweieric as maintainer ([#6798](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6798))
2 changes: 2 additions & 0 deletions changelogs/fragments/6799.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
doc:
- Add OpenAPI specification for GET and CREATE saved object API ([#6799](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6799))
9 changes: 9 additions & 0 deletions docs/openapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## OpenAPI Specification For OpenSearch Dashboards API

### OpenAPI
The OpenAPI (https://swagger.io/specification/) Specification defines a standard, language-agnostic interface to the HTTP RESTful APIs which allows both humans and computers to discover and understand the functionalities provided by the service without having to read through the source code or lengthy documentation. When properly defined, a consumer of the API can understand and interact with the service with a minimal amount of efforts. The OpenAPI definition file can be in the YAML or JSON format.

When generated, OpenAPI definition can then be used by documentation generation tools to display the API such as swagger UI, code generation tools to generate servers and clients in various programming languages, testing tools, and many other use cases.

### Starting Up the Swagger UI Locally
To start up the swagger UI locally for development or validation purposes, you can simply start a server in the directory where the index.html file is located. `npx serve` is a simple way to start a server.
29 changes: 29 additions & 0 deletions docs/openapi/saved_objects/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="//unpkg.com/swagger-ui-dist@3/swagger-ui.css">

<title>Saved Object API</title>

<body>

<div id="api-docs" />

<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
<script>

window.onload = function() {
const ui = SwaggerUIBundle({
url: "saved_objects.yml",
dom_id: "#api-docs",
deepLinking: true,
})

}

</script>

</body>
</html>
130 changes: 130 additions & 0 deletions docs/openapi/saved_objects/saved_objects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
openapi: 3.0.3
info:
version: v1
title: OpenSearch Dashboards Saved Objects API
contact:
name: OpenSearch Dashboards Team
description: |-
OpenAPI schema for OpenSearch Dashboards Saved Objects API
tags:
- name: saved objects
description: Manage Dashboards saved objects, including dashboards, visualizations, saved search, and more.
paths:
/api/saved_objects/{type}/{id}:
get:
tags:
- saved objects
summary: Retrieve a single saved object by type and id.
parameters:
- $ref: '#/components/parameters/id'
- $ref: '#/components/parameters/type'
responses:
'200':
description: The saved object is successfully retrieved.
content:
application/json:
schema:
type: object
'404':
description: The saved object does not exist.
content:
application/json:
schema:
type: object
post:
tags:
- saved objects
summary: Create a new saved object with type and id.
parameters:
- $ref: '#components/parameters/type'
- $ref: '#components/parameters/id'
- in: query
name: overwrite
description: If set to true, will overwrite the existing saved object with same type and id.
schema:
type: boolean
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- attributes
properties:
attributes:
type: object
description: The metadata of the saved object to be created, and the object is not validated.
migrationVersion:
type: object
description: The information about the migrations that have been applied to this saved object to be created.
references:
description: List of objects that describe other saved objects the created object references.
type: array
items:
type: object
properties:
id:
type: string
name:
type: string
type:
type: string
initialNamespaces:
description: Namespaces that this saved object exists in. This attribute is only used for multi-namespace saved object types.
type: array
items:
type: string
workspaces:
type: array
items:
type: string
description: Workspaces that this saved object exists in.
responses:
'200':
description: The creation request is successful
content:
application/json:
schema:
type: object
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/400_bad_request'
components:
parameters:
type:
name: type
in: path
description: The type of SavedObject to retrieve
required: true
schema:
type: string
id:
name: id
in: path
description: Unique id of the saved object.
required: true
schema:
type: string
schemas:
400_bad_request:
title: Bad request
type: object
required:
- error
- message
- statusCode
properties:
error:
type: string
enum:
- Bad Request
message:
type: string
statusCode:
type: integer
enum:
- 400
1 change: 1 addition & 0 deletions scripts/precommit_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
*/

require('@osd/optimizer').registerNodeAutoTranspilation();
require('./generate_docs_sidebar');
require('../src/dev/run_precommit_hook');
18 changes: 18 additions & 0 deletions src/dev/precommit_hook/check_dev_docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

const SIDEBAR_PATH = 'docs/_sidebar.md';

export async function checkDevDocs(log, files) {
files.map((file) => {
const path = file.getRelativePath();

if (path === SIDEBAR_PATH) {
throw Error(
`The ${SIDEBAR_PATH} file of the developer docs has been modified but is not ready to be committed. This can be done by performing "git add ${SIDEBAR_PATH}" and committing the changes.`
);
}
});
}
42 changes: 29 additions & 13 deletions src/dev/precommit_hook/get_files_for_commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,9 @@ import { fromNode as fcb } from 'bluebird';
import { REPO_ROOT } from '@osd/utils';
import { File } from '../file';

/**
* Get the files that are staged for commit (excluding deleted files)
* as `File` objects that are aware of their commit status.
*
* @param {String} repoPath
* @return {Promise<Array<File>>}
*/
export async function getFilesForCommit() {
const simpleGit = new SimpleGit(REPO_ROOT);

const output = await fcb((cb) => simpleGit.diff(['--name-status', '--cached'], cb));

function getFileList(diffText) {
return (
output
diffText
.split('\n')
// Ignore blank lines
.filter((line) => line.trim().length > 0)
Expand All @@ -69,3 +58,30 @@ export async function getFilesForCommit() {
.filter(Boolean)
);
}

/**
* Get the files that are staged for commit (excluding deleted files)
* as `File` objects that are aware of their commit status.
*
* @return {Promise<Array<File>>}
*/
export async function getFilesForCommit() {
const simpleGit = new SimpleGit(REPO_ROOT);

const staged = await fcb((cb) => simpleGit.diff(['--name-status', '--cached'], cb)); // staged

return getFileList(staged);
}

/**
* Get the unstaged files as `File` objects that are aware of their commit status.
*
* @return {Promise<Array<File>>}
*/
export async function getUnstagedFiles() {
const simpleGit = new SimpleGit(REPO_ROOT);

const unstaged = await fcb((cb) => simpleGit.diff(['--name-status'], cb));

return getFileList(unstaged);
}
3 changes: 2 additions & 1 deletion src/dev/precommit_hook/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
*/

export { checkFileCasing } from './check_file_casing';
export { getFilesForCommit } from './get_files_for_commit';
export { getFilesForCommit, getUnstagedFiles } from './get_files_for_commit';
export { checkDevDocs } from './check_dev_docs';
15 changes: 14 additions & 1 deletion src/dev/run_precommit_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,26 @@
import { run, combineErrors } from '@osd/dev-utils';
import * as Eslint from './eslint';
import * as Stylelint from './stylelint';
import { getFilesForCommit, checkFileCasing } from './precommit_hook';
import {
getFilesForCommit,
getUnstagedFiles,
checkFileCasing,
checkDevDocs,
} from './precommit_hook';

run(
async ({ log, flags }) => {
const files = await getFilesForCommit();
const unstagedFiles = await getUnstagedFiles();
const errors = [];

try {
// Check if the dev docs sidebar has been updated but not staged
await checkDevDocs(log, unstagedFiles);
} catch (error) {
errors.push(error);
}

try {
await checkFileCasing(log, files);
} catch (error) {
Expand Down

0 comments on commit b06c88d

Please sign in to comment.