Skip to content

Commit 3cbb8e5

Browse files
authored
Adapt to the new ___ ref separator from the spec (#902)
* Updated ref name separator to * Added date to AUTOCUT title and branch to easier tell these PRs apart. * # Signed-off-by: Theo Truong <[email protected]> * # Signed-off-by: Theo Truong <[email protected]> * # * Corrected OpenSearchApi file name caused by MacOS filesystem being case-insensitive Signed-off-by: Theo Truong <[email protected]> --------- Signed-off-by: Theo Truong <[email protected]>
1 parent dcf53f2 commit 3cbb8e5

File tree

8 files changed

+14
-1827
lines changed

8 files changed

+14
-1827
lines changed

Diff for: .github/workflows/generate_api.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ jobs:
5151
with:
5252
token: ${{ steps.github_app_token.outputs.token }}
5353
commit-message: "Updated opensearch-js to reflect the latest OpenSearch API spec (${{ env.date }})"
54-
title: "[AUTOCUT] Update opensearch-js to reflect the latest OpenSearch API spec"
54+
title: "[AUTOCUT] Update opensearch-js to reflect the latest OpenSearch API spec (${{ env.date }})"
5555
body: |
5656
Update `opensearch-js` to reflect the latest [OpenSearch API spec](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml).
5757
Date: ${{ env.date }}
58-
branch: update-api-from-spec
58+
branch: update-api-from-spec-${{ env.date }}
5959
base: main
6060
signoff: true
6161
labels: |

Diff for: api/OpenSearchAPI.d.ts

-1,627
This file was deleted.

Diff for: api/OpenSearchAPI.js

-187
This file was deleted.

Diff for: api_generator/src/renderers/render_types/ComponentTypesContainer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*/
1010

11-
import TypesContainer, { TYPE_COMPONENTS_FOLDER } from './TypesContainer'
11+
import TypesContainer, { SEPARATOR, TYPE_COMPONENTS_FOLDER } from './TypesContainer'
1212
import type { JSONSchema7 as Schema } from 'json-schema'
1313
import type { RawOpenSearchSpec, RawParameter } from '../../spec_parser/types'
1414
import _ from 'lodash'
@@ -25,7 +25,7 @@ export default class ComponentTypesContainer extends TypesContainer {
2525

2626
private static build_components (spec: RawOpenSearchSpec): void {
2727
const referenced_schemas = _.entries(spec.components.schemas).map(([key, schema]) => {
28-
const [file_name, schema_name] = key.split(':')
28+
const [file_name, schema_name] = key.split(SEPARATOR)
2929
return { file_name, schema_name, schema }
3030
})
3131
const ref_schemas_map = _.groupBy(referenced_schemas, 'file_name')
@@ -38,7 +38,7 @@ export default class ComponentTypesContainer extends TypesContainer {
3838

3939
private static build_global_params (spec: RawOpenSearchSpec): void {
4040
const params: RawParameter[] = _.entries(spec.components.parameters)
41-
.filter(([key]) => key.startsWith('_global::'))
41+
.filter(([key]) => key.startsWith(`_global${SEPARATOR}`))
4242
.map(([, param]) => param)
4343
const required = params.filter(param => param.required).map(param => param.name)
4444
const properties = _.fromPairs(params.map(param => [param.name, param.schema]))

Diff for: api_generator/src/renderers/render_types/FunctionTypesContainer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*/
1010

11-
import TypesContainer from './TypesContainer'
11+
import TypesContainer, { SEPARATOR } from './TypesContainer'
1212
import _ from 'lodash'
1313
import { type ApiFunctionTyping } from '../../spec_parser/ApiFunction'
1414
import type ApiFunction from '../../spec_parser/ApiFunction'
@@ -38,7 +38,7 @@ export default class FunctionTypesContainer extends TypesContainer {
3838
}
3939

4040
create_ref (key: keyof ApiFunctionTyping): string {
41-
return `${this._func.ns_prototype}/${this._func.prototype_name}:${this._func.types[key]}`
41+
return `${this._func.ns_prototype}/${this._func.prototype_name}${SEPARATOR}${this._func.types[key]}`
4242
}
4343

4444
#build_request (): Schema {
@@ -49,7 +49,7 @@ export default class FunctionTypesContainer extends TypesContainer {
4949
const required_params = Object.entries(params).filter(([, param]) => param.required).map(([name]) => name)
5050
const required = body?.required ? [...required_params, 'body'] : required_params
5151
const schema: Schema = { properties, required }
52-
return { allOf: [schema, { $ref: '#/components/schemas/_global:Params' }] }
52+
return { allOf: [schema, { $ref: `#/components/schemas/_global${SEPARATOR}Params` }] }
5353
}
5454

5555
#build_response (): Schema {

Diff for: api_generator/src/renderers/render_types/TypesContainer.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { to_pascal_case } from '../../helpers'
1515

1616
type FilePath = string
1717
export const TYPE_COMPONENTS_FOLDER = '_types'
18+
export const SEPARATOR = '___' // separating fileName___schemaName in $ref
1819

1920
export default class TypesContainer {
2021
static readonly REPO = new Map<FilePath, TypesContainer>()
@@ -47,7 +48,7 @@ export default class TypesContainer {
4748

4849
ref_to_obj (ref: string): string {
4950
if (ref === 'ApiResponse') return ref
50-
const schema_name = ref.split(':')[1]
51+
const schema_name = ref.split(SEPARATOR)[1]
5152
const container = this.ref_to_container(ref)
5253
if (container === this) return schema_name
5354
return `${container.import_name}.${schema_name}`
@@ -56,10 +57,10 @@ export default class TypesContainer {
5657
ref_to_container (ref: string): TypesContainer {
5758
let file_path: string = 'UNSET'
5859
if (ref.startsWith('#/components')) {
59-
const file_name = ref.split(':')[0].split('/').reverse()[0]
60+
const file_name = ref.split(SEPARATOR)[0].split('/').reverse()[0]
6061
file_path = `${TYPE_COMPONENTS_FOLDER}/${file_name}.d.ts`
6162
} else {
62-
const [folder_name, file_name] = ref.split(':')[0].split('/')
63+
const [folder_name, file_name] = ref.split(SEPARATOR)[0].split('/')
6364
file_path = `${folder_name}/${file_name}.d.ts`
6465
}
6566
const container = TypesContainer.REPO.get(file_path)

Diff for: lib/Client.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import { ConnectionOptions as TlsConnectionOptions } from 'tls';
1212
import { URL } from 'url';
13-
import OpenSearchAPI from '../api/OpenSearchAPI';
13+
import OpenSearchAPI from '../api/OpenSearchApi';
1414
import Serializer from './Serializer';
1515
import Helpers from './Helpers';
1616
import Connection, { AgentOptions, agentFn } from './Connection';

Diff for: lib/Client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const kChild = Symbol('opensearchjs-child');
4646
const kExtensions = Symbol('opensearchjs-extensions');
4747
const kEventEmitter = Symbol('opensearchjs-event-emitter');
4848

49-
const OpenSearchAPI = require('../api/OpenSearchAPI');
49+
const OpenSearchAPI = require('../api/OpenSearchApi');
5050

5151
class Client extends OpenSearchAPI {
5252
constructor(opts = {}) {

0 commit comments

Comments
 (0)